pydata / pydata/xarray

Inconsistency between sel and isel when working with slice

Open
#4,526 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic-documentation
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What happened:

Slice do not have the same effect when working with sel and isel.
The stop bound is not selected with isel while it is with sel.

What you expected to happen:
Either to select or not select the "stop" bound of the slice in both case.

Minimal Complete Verifiable Example:

import xarray as xr 
da = xr.Dataset()
da.coords["lat"] = [0, 1, 2, 3]
da["value"] = (('lat'),da["lat"].values+10)

print("Isel result is \n %s \n\n"%da.isel(lat=slice(1,2)))
print("Sel result is \n %s"%da.sel(lat=slice(1,2)))

Gives the following results

Isel result is 
 <xarray.Dataset>
Dimensions: (lat: 1)
Coordinates:
  * lat      (lat) int64 1
Data variables:
    value    (lat) int64 11 


Sel result is 
 <xarray.Dataset>
Dimensions:  (lat: 2)
Coordinates:
  * lat      (lat) int64 1 2
Data variables:
    value    (lat) int64 11 12

Anything else we need to know?:

Environment:

Output of xr.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.8.2 | packaged by conda-forge | (default, Mar 5 2020, 17:11:00)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 4.15.0-118-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: fr_FR.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.7.3

xarray: 0.15.0
pandas: 1.0.1
numpy: 1.18.1
scipy: 1.4.1
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: 2.4.0
cftime: 1.0.4.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: 0.9.8.3
iris: None
bottleneck: None
dask: 2.12.0
distributed: 2.12.0
matplotlib: 3.2.0
cartopy: 0.17.0
seaborn: None
numbagg: None
setuptools: 46.0.0.post20200308
pip: 20.0.2
conda: None
pytest: 5.4.1
IPython: 7.13.0
sphinx: None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied Python example and tracing the sel and isel entry points. Determine the intended stop-bound behavior for each indexing mode, then make the behavior consistent and add regression coverage for the reproducer.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.