-
-
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
unexpected positional indexing behavior with Dataset and DataArray "isel" #411
Comments
This is expected -- we do orthogonal indexing (treating each coordinate independently), not NumPy style fancy indexing. If you read on in the indexing docs, you'll find this under "Indexing details": http://xray.readthedocs.org/en/latest/indexing.html#indexing-details Perhaps we should note this more prominently! The style of indexing you're describing here is definitely useful, though (e.g., for selecting the locations of stations from a grid) -- it's something that I would really like to support. |
Okay. Glad to hear I was missing something. For large datasets, I was getting a The indexing details link you show does explain the behavior better but it is somewhat contradictory to the quote I listed above. I think it would be worth reconciling the docs on that point. The station selection use case you bring up is exactly what I was going for. It would be nice if we could stay in Lastly, is there an issue open for support of numpy fancy indexing? This is something that would be useful for my work and I could contribute to the effort beginning in July. |
I'll definitely add a note to qualify that description in the docs -- sorry you went to all the trouble of writing up the bug report!
The open issue for this is #214, which describes how I currently do "diagonal" style indexing to extract stations. It preserves all the metadata, but is a little slow if you have a very long list of stations:. Note that the example in that first comment will work even with arrays that don't fit into memory if you use dask (which will be in the next xray release, which will be out today or tomorrow).
Full NumPy style fancy indexing is out of scope for xray. You can simply do way too many complex things with it for which preserving the metadata is impossible (e.g., you can scramble the elements of a 2D array into any arbitrary desired positions). Moreover, the underlying array indexing operations are only possible to do efficiently if the underlying array is backed by NumPy -- there's no way we'll do that with |
Added a warning in #412. Here's what that doc page looks like now: |
I may be missing something here but I think the indexing behavior in
isel
is surprisingly different to that ofnumpy
and is incongruent with thexray
documentation. Either this is a bug or a feature that I don't understand.From the
xray
docs on positional indexing:My example below uses two 1d
numpy
arrays to select from a 3d numpy array. When using purenumpy
, I get a 2d array back. In my view, this is the expected behavior. When using thexray.Dataset
orxray.DataArray
, I get an oddly shaped 3d array back with a duplicate dimension.The text was updated successfully, but these errors were encountered: