Open max-sixty opened 2 weeks ago
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: https://github.com/pydata/xarray/issues/8028
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