Skip to content
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

Add '_FillValue' to set of valid_encodings for netCDF4 backend #1869

Merged
merged 6 commits into from Feb 13, 2018
Merged

Add '_FillValue' to set of valid_encodings for netCDF4 backend #1869

merged 6 commits into from Feb 13, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jan 30, 2018

  • Closes Dimension Co-ordinates incorectly saving _FillValue attribute #1865 (remove if there is no corresponding issue, which should only be the case for minor changes)
  • Tests added (for all bug fixes or enhancements)
  • Tests passed (for all non-documentation changes)
    • Relevant tests passed on my cloned version of the code. I had some skipped tests as I did not install rasterio, Nio, or Zarr. Four unrelated tests failed (2 in netcdf3 and 2 in h5netcdf)
  • Fully documented, including whats-new.rst for all changes and api.rst for new API (remove if this change should not be visible to users, e.g., if it is an internal clean-up, or if this is part of a larger project that will be documented later)

@shoyer
Copy link
Member

shoyer commented Jan 30, 2018

Oops! Yes, this is was definitely a bug.

Can you add a unit test for this, so we don't have a regression?

Take a look at the test test_explicitly_omit_fill_value added in #1659 and test_encoding_same_dtype below it for examples.

Add additional tests to prevent future regression of setting _FillValue
to None when using the encoding kwarg in to_netcdf.
@ghost
Copy link
Author

ghost commented Jan 30, 2018

Unit tests added in 9210dfa. The first and the third added tests use the encoding kwarg and fail without b8fd86d applied and pass with b8fd86d applied, so they should catch a regression.

The second added test passes both before and after b8fd86d and was added for completeness as it pairs with the original test_explicitly_omit_fill_value, but for a coordinate.

I still think nothing needs to change in the documentation as this now follows the intent of the design.

I will leave it to you @shoyer or your delegate to address whether anything needs to be stated in the changelog / what's new.

@ghost
Copy link
Author

ghost commented Jan 30, 2018

Wait to merge... I'm still getting failed tests using the scipy backend

Remove copy/paste line that shouldn't have been in a test.
Add additional asserts.
Fix indentation.
@ghost
Copy link
Author

ghost commented Jan 30, 2018

Now the tests pass (see comment beside the checkbox)

Honestly, I'm not happy with where I put the fix in order to get the tests to pass when using the scipy backend by adding an additional test, but I didn't know where else to put the test. The test to see if the variable would be checked in prepare_variables came before the encoding could be managed in encode_cf_variable in conventions.py

The alternative would be to remove the changes to scipy_.py and just have the test run only for the other engine backends and leave fixing the scipy backend for someone more familiar with it for another issue.

@ghost
Copy link
Author

ghost commented Jan 31, 2018

@shoyer, do you have an opinion on whether or not to include the scipy fix or leave it out of this PR?
Also what is your opinion on the documentation? I feel nothing is needed as with this PR the code will operate as the documentation states.

@shoyer
Copy link
Member

shoyer commented Jan 31, 2018

We don't need any additional documentation, but we should note this bug fix in "What's new"

@@ -188,8 +188,9 @@ def encode_variable(self, variable):
def prepare_variable(self, name, variable, check_encoding=False,
unlimited_dims=None):
if check_encoding and variable.encoding:
raise ValueError('unexpected encoding for scipy backend: %r'
% list(variable.encoding))
if variable.encoding != {'_FillValue': None}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a little awkward.

I think this is probably OK (backend classes already need to know about encodings), but it would be good to think about why we don't already have validation for encodings with scipy. We should probably be raising an error if somebody attempts an encoding like {'zlib': True} but right now it looks like we don't do that.

@ghost
Copy link
Author

ghost commented Feb 12, 2018

@shoyer, I think everything is in order to apply this bug fix.

@ghost ghost mentioned this pull request Feb 13, 2018
5 tasks
@jhamman
Copy link
Member

jhamman commented Feb 13, 2018

@shoyer - this looks good to me. At some point, we should formalize how backends validate their encodings but I don't think that needs to happen here.

@shoyer shoyer merged commit 33660b7 into pydata:master Feb 13, 2018
@shoyer
Copy link
Member

shoyer commented Feb 13, 2018

Yes, thanks @czr137 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dimension Co-ordinates incorectly saving _FillValue attribute
3 participants