Skip to content
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

slicing non-monotonously increasing dimension returns empty slice silently #2966

Closed
poplarShift opened this issue May 15, 2019 · 2 comments
Closed

Comments

@poplarShift
Copy link

poplarShift commented May 15, 2019

When slicing over a dimension that is not ordered monotonously increasing, .sel returns an empty slice (which is ok) but it also doesn't complain (which is not very helpful).

import xarray as xr
print(xr.__version__)

ds = xr.tutorial.open_dataset('rasm')

print('right order selects correctly:')
print(ds.sel(x=slice(10,15)))

ds['x'] = ds.x[::-1]

print('wrong order returns empty slice, silently:')
print(ds.sel(x=slice(10,15)))

Returns:

0.12.1

right order selects correctly:
<xarray.Dataset>
Dimensions:  (time: 36, x: 5, y: 205)
Coordinates:
  * time     (time) object 1980-09-16 12:00:00 ... 1983-08-17 00:00:00
    xc       (y, x) float64 ...
    yc       (y, x) float64 ...
Dimensions without coordinates: x, y
Data variables:
    Tair     (time, y, x) float64 ...
Attributes:
    title:                     /workspace/jhamman/processed/R1002RBRxaaa01a/l...
    institution:               U.W.
    source:                    RACM R1002RBRxaaa01a
    output_frequency:          daily
    output_mode:               averaged
    convention:                CF-1.4
    references:                Based on the initial model of Liang et al., 19...
    comment:                   Output from the Variable Infiltration Capacity...
    nco_openmp_thread_number:  1
    NCO:                       "4.6.0"
    history:                   Tue Dec 27 14:15:22 2016: ncatted -a dimension...
wrong order returns empty slice, silently:
<xarray.Dataset>
Dimensions:  (time: 36, x: 0, y: 205)
Coordinates:
  * time     (time) object 1980-09-16 12:00:00 ... 1983-08-17 00:00:00
    xc       (y, x) float64 ...
    yc       (y, x) float64 ...
  * x        (x) int64 
Dimensions without coordinates: y
Data variables:
    Tair     (time, y, x) float64 ...
Attributes:
    title:                     /workspace/jhamman/processed/R1002RBRxaaa01a/l...
    institution:               U.W.
    source:                    RACM R1002RBRxaaa01a
    output_frequency:          daily
    output_mode:               averaged
    convention:                CF-1.4
    references:                Based on the initial model of Liang et al., 19...
    comment:                   Output from the Variable Infiltration Capacity...
    nco_openmp_thread_number:  1
    NCO:                       "4.6.0"
    history:                   Tue Dec 27 14:15:22 2016: ncatted -a dimension...
@dcherian
Copy link
Contributor

Thanks for opening an issue @poplarShift.

There's been quite some discussion in #1613, so I'll close this in favour of that. Please chime in there.

@poplarShift
Copy link
Author

Thanks! Thought I looked everywhere if the issue already existed but must have missed that.

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

2 participants