Possible to select by label with integer slices from an integer dimension coordinate? #9547
-
(EDIT: Here's a dataset and a notebook Gist with outputs illustrating the behavior. In summary, So it seems I have a If I then just save back every tenth frame (a small subset for testing/checking into version control), load it back in as I could sidestep this by passing a Ideally, for my case, the same slice index would always return
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
can you post an example dataset just so we can more easily follow what you're doing? For example, does this exhibit the behavior you're describing? ds = xr.Dataset(coords={"frame": np.arange(1000)})
ds.sel(frame=slice(None, None, 10)) |
Beta Was this translation helpful? Give feedback.
-
after investigating a bit further, I believe this is inherited behavior from ds = xr.Dataset(coords={"x": np.linspace(0, 1, 100)})
ds.sel(x=slice(None, None, 0.1)) and this fails with the same error: s = pd.Series(np.arange(100), index=np.linspace(0, 1, 100))
s.loc[slice(None, None, 0.1)] To fix this, we'd either have to write our own index, or convince the |
Beta Was this translation helpful? Give feedback.
-
Here's a dataset and a notebook Gist with outputs illustrating the behavior. Thanks for the detail. So it probably can't be helped if it's indexing behavior adopted from upstream. I'm not going to explore customization/extension avenues now, but am I correct in my understanding that I might be able to do it with a custom accessor or the (experimental) custom index? |
Beta Was this translation helpful? Give feedback.
-
Ah, great, thanks for the detail! Yes it seems my problem would be a specific use case for something like The Gist goes into more detail, but basically I'm using a
I'm looking forward to making use of the new indexing features as they emerge, but I'm in no rush, as I'm sure reaching a stable API will represent quite a lot of work. |
Beta Was this translation helpful? Give feedback.
I haven't looked at your notebook gist yet, but from what I can read here this
Range1DIndex
custom index example may be relevant: #9543 (comment).(Note: that example only works within the context the draft PR where it has been shown).
A coordinate associated with this index is lazy, so
da.frames[-1]
will only compute the last frame index.I think you could pretty easily customize it so it handles slice steps the way you want. If that behavior makes sense in the general case we might also consider supporting it in Xarray.