-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Get 0d slices of ndarrays directly from indexing #2625
Conversation
Hello @danielwe! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on December 22, 2018 at 11:56 Hours UTC |
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.
Thanks, @danielwe
One minor comment but it looks really nice :)
xarray/tests/test_variable.py
Outdated
assert ( | ||
variable[0]._data.__array_interface__["data"][0] | ||
== variable._data.__array_interface__["data"][0] | ||
) |
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.
Can you add more explicit tests that other developers easily find what we are testing?
e.g.
a = variable[0]
a = 3
assert a == variable[0]
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.
It might also be easier just to write a separate dedicated method for this, rather than squeezing it into the existing _assertIndexedLikeNDArray
.
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.
You're right, my thinking about tests was a little muddled. The new solution should be better.
# We're not interested in obtaining a scalar, but rather a 0d slice. | ||
# This is accomplished by appending an ellipsis (see | ||
# https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#detailed-notes). # noqa | ||
key = key.tuple + (Ellipsis,) |
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.
Two questions:
- does this also work in the other branches, i.e., the ones that do fancy indexing?
- (related) can you remove the
_ensure_ndarray
method above?
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.
-
It does not affect outer indexing but breaks vectorized indexing, where some arrays come back with dimensions in a different order. I haven't looked into exactly why. It would be nice to move the change into
__getitem__
, asreturn array[key + (Ellipsis,)]
, but I'm afraid that won't work. In any case, I think only basic indexing ever returns a 0d array, so the current change covers all relevant cases. -
In fact, yes. I was convinced there were edge cases with object arrays etc., so I let it stay, but all tests pass without. Removed now.
wonderful, thanks @danielwe ! |
* master: DEP: drop python 2 support and associated ci mods (pydata#2637) TST: silence warnings from bottleneck (pydata#2638) revert to dev version DOC: fix docstrings and doc build for 0.11.1 Source encoding always set when opening datasets (pydata#2626) Add flake check to travis (pydata#2632) Fix dayofweek and dayofyear attributes from dates generated by cftime_range (pydata#2633) silence import warning (pydata#2635) fill_value in shift (pydata#2470) Flake fixed (pydata#2629) Allow passing of positional arguments in `apply` for Groupby objects (pydata#2413) Fix failure in time encoding for pandas < 0.21.1 (pydata#2630) Fix multiindex selection (pydata#2621) Close files when CachingFileManager is garbage collected (pydata#2595) added some logic to deal with rasterio objects in addition to filepaths (pydata#2589) Get 0d slices of ndarrays directly from indexing (pydata#2625) FIX Don't raise a deprecation warning for xarray.ufuncs.{angle,iscomplex} (pydata#2615) CF: also decode time bounds when available (pydata#2571)
whats-new.rst
for all changes andapi.rst
for new API