Skip to content

Work around numpy 1.14 structured array changes #239

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

Merged
merged 7 commits into from
Jan 31, 2018

Conversation

alimanfoo
Copy link
Member

@alimanfoo alimanfoo commented Jan 30, 2018

This PR adds testing with numpy 1.14 and deals with some compatibility issues around fill values for structured arrays. Resolves #222, resolves #238.

TODO:

  • Add unit tests and/or doctests in docstrings
  • Unit tests and doctests pass locally under Python 3.6 (e.g., run tox -e py36 or
    pytest -v --doctest-modules zarr)
  • Unit tests pass locally under Python 2.7 (e.g., run tox -e py27 or
    pytest -v zarr)
  • PEP8 checks pass (e.g., run tox -e py36 or flake8 --max-line-length=100 zarr)
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/tutorial.rst
  • Doctests in tutorial pass (e.g., run tox -e py36 or python -m doctest -o NORMALIZE_WHITESPACE -o ELLIPSIS docs/tutorial.rst)
  • Changes documented in docs/release.rst
  • Docs build locally (e.g., run tox -e docs)
  • AppVeyor and Travis CI passes
  • Test coverage to 100% (Coveralls passes)

@alimanfoo alimanfoo self-assigned this Jan 30, 2018
@alimanfoo alimanfoo requested a review from jakirkham January 30, 2018 23:43
@alimanfoo
Copy link
Member Author

Pushed a small change to tox config because coverage from py36-npy114 was overwriting py36-npy113 (where doctests are included).

@alimanfoo
Copy link
Member Author

Hm, looks like still coverage issues. Will try something different.

@alimanfoo
Copy link
Member Author

OK, coveralls looking happy.

return v
elif dtype.kind == 'V':
v = base64.standard_b64decode(v)
v = np.array(v, dtype=dtype.str).view(dtype)[()]
Copy link
Member

Choose a reason for hiding this comment

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

Clever! Are we doing any round trip tests of encoding/decoding and vice versa?

Copy link
Member Author

Choose a reason for hiding this comment

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

This test covers encoding/decoding of metadata for a structured array. Probably could add a specific test for encoding/decoding structured array fill value.

Copy link
Member

Choose a reason for hiding this comment

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

Looks good. Thanks for the pointer.

It couldn't hurt to have such a test if you want to add it. However it seems like this is already being tested by the array round trip. So don't think it is strictly necessary to test fill values specifically.

# this does not raise with numpy 1.14
# with pytest.raises(ValueError):
# # dodgy fill value
# self.create_array(shape=a.shape, chunks=2, dtype=a.dtype, fill_value=42)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add a version check with this test? Also do we know why this doesn't raise with NumPy 1.14?

Copy link
Member Author

Choose a reason for hiding this comment

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

Numpy 1.14 is happy with a fill value like 42 for a structured array, it actually fills every field with the value, whereas numpy 1.13 barfs. I thought about adding a version check but then thought maybe that was overcomplicating, happy to add one if you think it's worth it.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. No strong opinions from me.

That said, if we think this test is no longer worthwhile, we should delete it instead of commenting it. Commented code has a way of sticking around unaddressed. It's much easier to add a new PR marked WIP readding this code and it has a better chance of being addressed that way (if needed).

# https://github.com/alimanfoo/zarr/pull/172#issuecomment-343782713

if fill_value == 0:
fill_value = ''
Copy link
Member

Choose a reason for hiding this comment

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

Why is this no longer needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is now covered by this branch.

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry. Overlooked that it is handled above generally. Thanks for the pointer. Seems fine.

@jakirkham
Copy link
Member

Thanks for tackling this @alimanfoo! Looks pretty good to me. :)

Had a couple of questions above mainly to make sure we are testing the round trip of encoding/decoding fill values and about some code that seems to have been dropped.

@alimanfoo
Copy link
Member Author

Thanks @jakirkham for the review. I've deleted the commented code section, I don't think it's necessary. I'll merge and roll another release.

@alimanfoo alimanfoo merged commit 07fa81a into master Jan 31, 2018
@alimanfoo alimanfoo deleted the npy114-20180130-alimanfoo branch January 31, 2018 18:57
@alimanfoo alimanfoo added this to the v2.2 milestone Jan 31, 2018
@jakirkham
Copy link
Member

Thanks @alimanfoo.

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.

2.2.0rc2 test failures at conda-forge Handle NumPy 1.14 structured dtype changes
2 participants