home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 869786882

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
869786882 MDU6SXNzdWU4Njk3ODY4ODI= 5228 sel(dim=slice(a,b,c)) only accepts integers for c, uses c as isel does 4441338 closed 0     1 2021-04-28T10:22:40Z 2021-04-28T10:47:00Z 2021-04-28T10:46:59Z NONE      

Trying to slice with sel using label delta values as interval, i.e. da.sel(mydim=slice(None,None,c).

What happened: The label delta value is not accepted.

What you expected to happen: Selecting c-spaced samples from the DataArray da.

Minimal Complete Verifiable Example:

```python dim0_n = 100 d = xr.DataArray(np.arange(dim0_n),coords={'dim0':np.linspace(0,1,num=dim0_n)},dims=('dim0',)) d.sel(dim0=slice(None,None,0.1))

expected 0,10,20,...,90

instead get a TypeError: 'float' object cannot be interpreted as an integer

(full traceback below)

```

Full traceback

``` TypeError Traceback (most recent call last) <ipython-input-43-9eb3e3c8bbe4> in <module> 1 dim0_n = 100 2 d = xr.DataArray(np.arange(dim0_n),coords={'dim0':np.linspace(0,1,num=dim0_n)},dims=('dim0',)) ----> 3 d.sel(dim0=slice(None,None,0.1)) 4 # expected 0,10,20,...,90 5 # instead get a TypeError (traceback below) ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataarray.py in sel(self, indexers, method, tolerance, drop, **indexers_kwargs) 1252 Dimensions without coordinates: points 1253 """ -> 1254 ds = self._to_temp_dataset().sel( 1255 indexers=indexers, 1256 drop=drop, ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataset.py in sel(self, indexers, method, tolerance, drop, **indexers_kwargs) 2231 self, indexers=indexers, method=method, tolerance=tolerance 2232 ) -> 2233 result = self.isel(indexers=pos_indexers, drop=drop) 2234 return result._overwrite_indexes(new_indexes) 2235 ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataset.py in isel(self, indexers, drop, missing_dims, **indexers_kwargs) 2093 var_indexers = {k: v for k, v in indexers.items() if k in var_value.dims} 2094 if var_indexers: -> 2095 var_value = var_value.isel(var_indexers) 2096 if drop and var_value.ndim == 0 and var_name in coord_names: 2097 coord_names.remove(var_name) ~/miniconda3/lib/python3.9/site-packages/xarray/core/variable.py in isel(self, indexers, missing_dims, **indexers_kwargs) 1164 1165 key = tuple(indexers.get(dim, slice(None)) for dim in self.dims) -> 1166 return self[key] 1167 1168 def squeeze(self, dim=None): ~/miniconda3/lib/python3.9/site-packages/xarray/core/variable.py in __getitem__(self, key) 808 array `x.values` directly. 809 """ --> 810 dims, indexer, new_order = self._broadcast_indexes(key) 811 data = as_indexable(self._data)[indexer] 812 if new_order: ~/miniconda3/lib/python3.9/site-packages/xarray/core/variable.py in _broadcast_indexes(self, key) 647 648 if all(isinstance(k, BASIC_INDEXING_TYPES) for k in key): --> 649 return self._broadcast_indexes_basic(key) 650 651 self._validate_indexers(key) ~/miniconda3/lib/python3.9/site-packages/xarray/core/variable.py in _broadcast_indexes_basic(self, key) 675 dim for k, dim in zip(key, self.dims) if not isinstance(k, integer_types) 676 ) --> 677 return dims, BasicIndexer(key), None 678 679 def _validate_indexers(self, key): ~/miniconda3/lib/python3.9/site-packages/xarray/core/indexing.py in __init__(self, key) 382 k = int(k) 383 elif isinstance(k, slice): --> 384 k = as_integer_slice(k) 385 else: 386 raise TypeError( ~/miniconda3/lib/python3.9/site-packages/xarray/core/indexing.py in as_integer_slice(value) 359 start = as_integer_or_none(value.start) 360 stop = as_integer_or_none(value.stop) --> 361 step = as_integer_or_none(value.step) 362 return slice(start, stop, step) 363 ~/miniconda3/lib/python3.9/site-packages/xarray/core/indexing.py in as_integer_or_none(value) 353 354 def as_integer_or_none(value): --> 355 return None if value is None else operator.index(value) 356 357 TypeError: 'float' object cannot be interpreted as an integer ```

Anything else we need to know?:

I think a warning in the documentation would be nice. It happened that I was giving integer values to c and xarray was subsetting datasets in an entirely different way that the one intended. It took noticing a downstream effect to find this behavior.

Environment:

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:46) [GCC 9.3.0] python-bits: 64 OS: Linux OS-release: 3.10.0-1160.11.1.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: None LOCALE: en_US.UTF-8 libhdf5: 1.10.6 libnetcdf: 4.7.4 xarray: 0.17.0 pandas: 1.2.4 numpy: 1.20.2 scipy: 1.6.2 netCDF4: 1.5.6 pydap: None h5netcdf: 0.11.0 h5py: 3.1.0 Nio: None zarr: 2.8.1 cftime: 1.4.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2021.04.1 distributed: 2021.04.1 matplotlib: 3.3.4 cartopy: None seaborn: 0.11.1 numbagg: None pint: None setuptools: 51.0.0.post20201207 pip: 21.1 conda: 4.10.1 pytest: None IPython: 7.22.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5228/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 0.822ms · About: xarray-datasette