-
-
Notifications
You must be signed in to change notification settings - Fork 331
Change in indexing behaviour with numpy ints #967
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
Comments
I was just about to write the exact same issue... (stumbled upon it while trying to read an encoded dict) root = zarr.group()
root.create("asdf", shape=(10,), dtype=object, object_codec=numcodecs.JSON())
root.asdf[0] = dict(a=1, b=2)
# using a normal python int to get the data
root.asdf[0]
#>>> {'a': 1, 'b': 2}
# using a numpy int to get the data
ids = np.array([0, 1, 2])
root.asdf[ids[0]]
#>>> array([{'a': 1, 'b': 2}], dtype=object) |
benjeffery
added a commit
to benjeffery/zarr-python
that referenced
this issue
Feb 28, 2022
benjeffery
added a commit
to benjeffery/zarr-python
that referenced
this issue
Feb 28, 2022
6 tasks
joshmoore
added a commit
that referenced
this issue
Mar 7, 2022
* Fix indexing for scalar numpy values (#967) * Fix linting errors * Remove whitespace from GH editor * Fix `W391 blank line at end of file` Co-authored-by: Josh Moore <[email protected]> Co-authored-by: jmoore <[email protected]>
This issue has been fixed in patch release 2.11.1. 🎉 |
Woop! Thankyou for the quick release! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
After 7c31f04 there was a breaking change to indexing behavior when a numpy integer type is passed:
For the following array:
Before this commit:
a[np.int64(1)]
has the value1.0
After:
a[np.int64(1)]
has the value[1.]
For both cases
a[1]
stays as1.0
as expected. Was this change expected? This happens a lot when iterating over one numpy array and indexing with it as the iterable is of the numpy type. The fix in our application was to cast to a pythonint
before indexing.EDIT: Also note that numpy indexing returns the single value as was the case before this commit.
The text was updated successfully, but these errors were encountered: