home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 666523009

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
666523009 MDU6SXNzdWU2NjY1MjMwMDk= 4276 isel with 0d dask array index fails 3958036 closed 0     0 2020-07-27T19:14:22Z 2023-03-15T02:48:01Z 2023-03-15T02:48:01Z CONTRIBUTOR      

What happened: If a 0d dask array is passed as an argument to isel(), an error occurs because dask arrays do not have a .item() method. I came across this when trying to use the result of da.argmax() from a dask-backed array to select from the DataArray.

What you expected to happen: isel() returns the value at the index contained in the 0d dask array.

Minimal Complete Verifiable Example:

```python import dask.array as daskarray import numpy as np import xarray as xr

a = daskarray.from_array(np.linspace(0., 1.)) da = xr.DataArray(a, dims="x")

x_selector = da.argmax(dim=...)

da_max = da.isel(x_selector) ```

Anything else we need to know?:

I think the problem is here https://github.com/pydata/xarray/blob/a198218ddabe557adbb04311b3234ec8d20419e7/xarray/core/variable.py#L546-L548 and k.values.item() or int(k.data) would fix my issue, but I don't know the reason for using .item() in the first place, so I'm not sure if either of these would have some undesirable side-effect.

May be related to #2511, but from the code snippet above, I think this is a specific issue of 0d dask arrays rather than a generic dask-indexing issue like #2511.

I'd like to fix this because it breaks the nice new features of argmin() and argmax() if the DataArray is dask-backed.

Environment:

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.7.6 | packaged by conda-forge | (default, Jun 1 2020, 18:57:50) [GCC 7.5.0] python-bits: 64 OS: Linux OS-release: 5.4.0-42-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.7.4 xarray: 0.16.0 pandas: 1.0.5 numpy: 1.18.5 scipy: 1.4.1 netCDF4: 1.5.3 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: None cftime: 1.2.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2.19.0 distributed: 2.21.0 matplotlib: 3.2.2 cartopy: None seaborn: None numbagg: None pint: 0.13 setuptools: 49.2.0.post20200712 pip: 20.1.1 conda: 4.8.3 pytest: 5.4.3 IPython: 7.15.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4276/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

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