Skip to content

Slicing Datasets is inclusive of upper bound, rather than exclusive #1585

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

Closed
sjperkins opened this issue Sep 22, 2017 · 1 comment
Closed

Comments

@sjperkins
Copy link

Slicing a Dataset with a slice object includes the upper bound, which is different from python, numpy etc.

python 2.7.12, xarray 0.9.6. #1492 (comment) may be relevant, a quick search didn't reveal other issues:

The following illustrates the issue:

import numpy as np
import xarray as xr

time = xr.DataArray(np.arange(50), dims=['time'], coords={'time' : np.arange(50)})
data = xr.DataArray(np.arange(1000), dims=['row'], coords={'row' : np.arange(1000)})

ds = xr.Dataset({"time" : time, "data" : data})

print ds.sel(time=slice(0,10), row=slice(0,100))
print ds.sel(time=slice(0,10-1), row=slice(0,100-1))

produces

<xarray.Dataset>
Dimensions:  (row: 101, time: 11)
Coordinates:
  * row      (row) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
  * time     (time) int64 0 1 2 3 4 5 6 7 8 9 10
Data variables:
    data     (row) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...


<xarray.Dataset>
Dimensions:  (row: 100, time: 10)
Coordinates:
  * row      (row) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
  * time     (time) int64 0 1 2 3 4 5 6 7 8 9
Data variables:
    data     (row) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
@sjperkins
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant