-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API: Render axes attributes as list of double quoted strings #155
Conversation
Previously, arrays of strings or byte arrays were truncated to only show the first element, but this is incompatible with the Nexus standard which expects axes to be provided as an array of strings. Closes prjemian#129
2e4efd4
to
81ea1ce
Compare
Actually, this is not quite what I had in mind. More like (with this file created): import h5py
with h5py.File("/tmp/demo.h5", "w") as h5:
nxentry = h5.create_group("Scan")
nxentry.attrs["NX_class"] = "NXentry"
nxdata = nxentry.create_group("data")
nxdata.attrs["NX_class"] = "NXdata"
nxdata.attrs["axes"] = "two_theta"
nxdata.attrs["signal"] = "counts"
nxdata.attrs["two_theta_indices"] = 0
nxdata.attrs["multi_str"] = "one two three".split()
ds = nxentry.create_dataset(
"counts",
data=[
1037, 1318, 1704, 2857, 4516
]
)
ds.attrs["units"] = "counts"
ds = nxentry.create_dataset(
"two_theta",
data=[
17.92608, 17.92591, 17.92575, 17.92558, 17.92541
]
)
ds.attrs["units"] = "degrees" Should give a report like this: (bluesky_2022_1) prjemian@zap:~/.../prjemian/punx$ punx tree /tmp/demo.h5
!!! WARNING: this program is not ready for distribution.
/tmp/demo.h5 : NeXus data file
Scan:NXentry
@NX_class = NXentry
counts:NX_INT64[5] = [1037, 1318, 1704, 2857, 4516]
@units = counts
two_theta:NX_FLOAT64[5] = [17.92608, 17.92591, 17.92575, 17.92558, 17.92541]
@units = degrees
data:nxdata
@NX_class = NXdata
@axes = two_theta
@multi_str = ["one", "two", "three"]
@signal = counts
@two_theta_indices = 0 Today, the code renders this one attribute: Thinking that all string attributes should be rendered with double quotes and lists of strings should be rendered with square brackets. |
more like this: (bluesky_2022_1) prjemian@zap:~/.../prjemian/punx$ punx tree /tmp/demo.h5
!!! WARNING: this program is not ready for distribution.
/tmp/demo.h5 : NeXus data file
Scan:NXentry
@NX_class = "NXentry"
counts:NX_INT64[5] = [1037, 1318, 1704, 2857, 4516]
@units = "counts"
two_theta:NX_FLOAT64[5] = [17.92608, 17.92591, 17.92575, 17.92558, 17.92541]
@units = "degrees"
data:nxdata
@NX_class = "NXdata"
@axes = "two_theta"
@multi_str = ["one", "two", "three"]
@signal = "counts"
@two_theta_indices = 0 |
I changed the behavior of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carterbox This looks good. Are there any other test cases to construct? If not, merge when ready.
I don't know why the CI passes. There are a few failing tests for me locally! |
Please copy the complete the console failure report here. |
Some attributes were being rendered not using the _renderAttributes function. Now this function has been refactored, so that all attribute rendering occurs in the same code segment.
This example file for the validation tests is now "wrong" because it uses a numpy array of a single string. What should I do about that? |
The validate tests are currently failing where they expect a string but get a list instead. For example:
Fails because |
I agree that the examples are incorrect. They can be used to test for invalid structures. Will the proper structure be caught by other tests? If so, then the test can be modified to check that invalid structure is detected. It is possible that other tests and data files may need such review. |
unitests aren't being run on this PR. It's because I'm using my own fork instead of using branches here. Should I add:
to the GitHub action? |
Sure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look fine to me.
The test says it is testing a list of axes but the only list attribute is a
different one. I'll modify and upload.
…On Sat, Nov 13, 2021, 4:31 PM Daniel Ching ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In punx/tests/test_issue129.py
<#155 (comment)>:
> +
+def test_render_multiple_axes_attribute(hfile):
+ """Ensure axes attributes are rendered as list of double quoted strings.
+
+ @axes should be saved as an array of byte strings or an array of object
+ strings because the NeXus standard says so. Single strings separated by
+ whitespace or other charachters will not be rendered correctly.
+ """
+ assert os.path.exists(hfile)
+ with h5py.File(hfile, "w") as h5:
+ nxentry = h5.create_group("Scan")
+ nxentry.attrs["NX_class"] = "NXentry"
+
+ nxdata = nxentry.create_group("data")
+ nxdata.attrs["NX_class"] = "NXdata"
+ nxdata.attrs["axes"] = "two_theta"
You want me to only compare that one line in the report to the reference
instead of all lines in the report?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#155 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARMUMF7ONPEKPN2DOKTDOLUL3RMBANCNFSM5HJ4WXZA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
The point is that |
In the NeXus documentation (in the Index), the The 2-D example shows the structure is
where the datasets The unit test should create a data file with the structure of the 2-D example and assert the structure and content of the |
Random numbers for the actual data (of the datasets) are sufficient. These values will not be tested. |
Removed the |
Number data types are OS-dependent as shown in this example when testing on Windows 10:
|
@carterbox This is ready for your comment. Should I recycle my review approval? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Previously, arrays of strings or byte arrays were truncated to only show the first element, but this is incompatible with the Nexus standard which expects axes to be provided as an array of strings.
This PR changes the behavior of utils.decode_byte_string() and h5tree.renderAttribute so that all types of strings are converted to strings and arrays of strings are converted to lists of strings. This allows rendering of strings and lists of strings with double quotes. However, it also causes some knock-on effects where unrelated functions which always expected a string, now need to deal with lists of strings. These cases which caused existing tests to fail were patched.
Closes #129