-
-
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
Automatically create xindex
?
#9703
Comments
Somehow I remember that this came up already a year ago or so. But I cannot seem to find the issue... I think that this would be a great addition. |
👍 for automatically creating indexes when needed. I would not modify the xarray object in place. Users can do this if they need the performance gains. |
One quick thought: should we add them when creating the object? |
Might be related: #8028 |
I agree that explicitly setting the index can be a bit annoying sometimes. I'm a little worried about automatically creating (even temporary) indexes, though. The created index would be a default What about dimensions with billions of elements? It's an edge case but it has been discussed a few times. It is now possible to create new datasets with no index at all... How can we also avoid the creation of temporary indexes in that case? (More theoretically, this contradicts a bit the goal of the index refactor that was to make indexes "explicitly" part of the Xarray data model)
I think I'd prefer this. However, we would first need to support selection and alignment with multiple indexes sharing common dimensions. |
Is your feature request related to a problem?
I'm trying to use
xindex
more. Currently, trying to select values using coordinates that haven't been explicitly indexed viaset_xindex()
raises:After explicitly setting the index, it works as expected:
It's a bit annoying — frequently I attempt to select something, realize it doesn't have an index, add the
.set_xindex
call, try and remember to add each one at object creation, feel like xarray isn't being as helpful as it could be.Describe the solution you'd like
Could we instead set the xindex automatically when calling
.sel
Possibly we want to force the user to create this once, rather than paying the cost of creating a new index on each call? But OTOH it seems relatively cheap?
(I guess it could be possible to update a cache in place, and then creating a new index from the cache would be very cheap. Though also possibly that's a source of quite confusing behavior if our implementation is in any way wrong / people are sharing objects across threads etc — i.e. the principle of "don't update in place" is useful)
Describe alternatives you've considered
A
set_xindex(...)
param (i.e. literally an ellipsis...
) that just creates all the indexes that it can, and folks could call after creating an object?Additional context
No response
The text was updated successfully, but these errors were encountered: