-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added validation of attrs before saving to netCDF files #991
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
Conversation
This allows us to give nice errors if users try to save a Dataset with attr values that can't be written to a netCDF file. Fixes pydata#911
check_attr(k, v) | ||
|
||
# Check attrs on each variable within the dataset | ||
for var_name in dataset.data_vars: |
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.
Use dataset.variables
(a dict of xarray.Variable
objects) instead of separately checking data vars and coords
Thanks, I'll deal with these modifications. Also, I'm seeing errors from TravisCI saying |
Take a look at the other netcdf tests -- they all use a decorator like
|
I think I've dealt with all of these. Refactoring the tests has made them a bit cleaner and safer due to not using mutation - however I still have quite a few repeated lines of code. I've also combined them all into one test with lots of asserts - as otherwise I couldn't keep the helper functions within the test without repeating them loads of times. Does anything need adding to the docs for this? I'm assuming not as it's just making the code do more checking, it's not adding a feature as such? |
The Travis builds seem to have all passed except for |
check_attr(k, v) | ||
|
||
# Check attrs on each variable within the dataset | ||
for var_name in dataset.variables: |
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.
dataset.variables
is a dictionary. So you can write:
for variable in dataset.variables.values():
for k, v in variable.attrs.items():
check_attr(k, v)
This is almost there now. I agree that we don't need to update the docs, but please do make note of it in "What's New". |
thanks! |
This allows us to give nice errors if users try to save a Dataset with
attr values that can't be written to a netCDF file.
Fixes #911.
I've added tests to
test_backends.py
as I can't see a better place to put them. I've also made the tests fairly extensive, but also used some helper functions to stop too much repetition. Please let me know if any of this doesn't fit within the xarray style.