issue_comments: 1248876262
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/issues/7031#issuecomment-1248876262 | https://api.github.com/repos/pydata/xarray/issues/7031 | 1248876262 | IC_kwDOAMm_X85KcFbm | 35968931 | 2022-09-16T03:24:59Z | 2022-09-16T03:31:50Z | MEMBER | I think this version does something sensible for all slice cases ```python from xarray.core.indexes import ( PandasIndex, IndexSelResult, _query_slice ) from xarray.core.indexing import _expand_slice class PeriodicBoundaryIndex(PandasIndex): """ An index representing any 1D periodic numberline.
``` ```python lon_coord = xr.DataArray(data=np.linspace(-180, 180, 19), dims="lon") da = xr.DataArray(data=np.sin(180*lon_coord), dims="lon", coords={"lon": lon_coord}) world = da.drop_indexes("lon").set_xindex("lon", index_cls=PeriodicBoundaryIndex, period=360) ``` ```python world.sel(lon=slice(60, 120), method="nearest") <xarray.DataArray (lon: 4)>array([-0.71424378, -0.87270922, -0.9701637 , -0.99979417])Coordinates:* lon (lon) float64 60.0 80.0 100.0 120.0``` ```python world.sel(lon=slice(160, 210), method="nearest") <xarray.DataArray (lon: 4)>array([-0.85218366, -0.68526211, 0.68526211, 0.85218366])Coordinates:* lon (lon) float64 160.0 180.0 -180.0 -160.0``` ```python world.sel(lon=slice(-210, -160), method="nearest") <xarray.DataArray (lon: 4)>array([-0.85218366, -0.68526211, 0.68526211, 0.85218366])Coordinates:* lon (lon) float64 160.0 180.0 -180.0 -160.0``` Unsure as to whether this next one counts as an "intuitive" result or not ```python world.sel(lon=slice(-210, 210), method="nearest") <xarray.DataArray (lon: 4)>array([-0.85218366, -0.68526211, 0.68526211, 0.85218366])Coordinates:* lon (lon) float64 160.0 180.0 -180.0 -160.0``` ```python world.sel(lon=slice(120, 60), method="nearest") <xarray.DataArray (lon: 0)>array([], dtype=float64)Coordinates:* lon (lon) float64``` |
{ "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
1372035441 |