home / github

Menu
  • GraphQL API
  • Search all tables

issues

Table actions
  • GraphQL API for issues

3 rows where repo = 13221727 and user = 404832 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: created_at (date), updated_at (date), closed_at (date)

type 2

  • issue 2
  • pull 1

state 2

  • closed 2
  • open 1

repo 1

  • xarray · 3 ✖
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
2180430069 I_kwDOAMm_X86B9rj1 8820 "ValueError: dimensions [...] must have the same length as the number of data dimensions" when slicing by zero-dimensional CuPy array dranjan 404832 open 0     0 2024-03-11T23:21:34Z 2024-03-11T23:21:34Z   CONTRIBUTOR      

What happened?

I'm slicing a DataArray by another zero-dimensional array. It works as I would expect when the DataArray and indexing array are backed by NumPy, but not when they're CuPy arrays:

python a = xr.DataArray(cp.arange(24).reshape(4, 6), dims=['x', 'y']) idx = xr.DataArray(cp.array(2)) print(a.isel(x=idx))

which results in:

Traceback (most recent call last): File "/home/darsh/work/dr-0338/example.py", line 8, in <module> print(a.isel(x=idx)) ^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/dataarray.py", line 1471, in isel ds = self._to_temp_dataset()._isel_fancy( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/dataset.py", line 2994, in _isel_fancy new_var = var.isel(indexers=var_indexers) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/variable.py", line 993, in isel return self[key] ~~~~^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/variable.py", line 767, in __getitem__ return self._finalize_indexing_result(dims, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/variable.py", line 771, in _finalize_indexing_result return self._replace(dims=dims, data=data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/variable.py", line 917, in _replace return type(self)(dims, data, attrs, encoding, fastpath=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/variable.py", line 365, in __init__ super().__init__( File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/namedarray/core.py", line 264, in __init__ self._dims = self._parse_dimensions(dims) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/namedarray/core.py", line 490, in _parse_dimensions raise ValueError( ValueError: dimensions ('x', 'y') must have the same length as the number of data dimensions, ndim=1

What did you expect to happen?

If the example is run with NumPy arrays instead of CuPy arrays, we get this, as expected: <xarray.DataArray (y: 6)> Size: 48B array([12, 13, 14, 15, 16, 17]) Dimensions without coordinates: y

Minimal Complete Verifiable Example

```Python

!/usr/bin/env python3

import cupy as cp import xarray as xr

a = xr.DataArray(cp.arange(24).reshape(4, 6), dims=['x', 'y']) idx = xr.DataArray(cp.array(2)) print(a.isel(x=idx)) ```

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.
  • [X] Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

Python Traceback (most recent call last): File "/home/darsh/work/dr-0338/example.py", line 8, in <module> print(a.isel(x=idx)) ^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/dataarray.py", line 1471, in isel ds = self._to_temp_dataset()._isel_fancy( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/dataset.py", line 2994, in _isel_fancy new_var = var.isel(indexers=var_indexers) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/variable.py", line 993, in isel return self[key] ~~~~^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/variable.py", line 767, in __getitem__ return self._finalize_indexing_result(dims, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/variable.py", line 771, in _finalize_indexing_result return self._replace(dims=dims, data=data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/variable.py", line 917, in _replace return type(self)(dims, data, attrs, encoding, fastpath=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/core/variable.py", line 365, in __init__ super().__init__( File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/namedarray/core.py", line 264, in __init__ self._dims = self._parse_dimensions(dims) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/darsh/virtualenvs/python3.11/lib/python3.11/site-packages/xarray/namedarray/core.py", line 490, in _parse_dimensions raise ValueError( ValueError: dimensions ('x', 'y') must have the same length as the number of data dimensions, ndim=1

Anything else we need to know?

I briefly looked into this but haven't discovered the cause yet. What I know: - It appears the buggy behavior was introduced in version 2023.3.0. With 2023.2.0, it gives the correct output. - I confirmed in the debugger that the indexing operation itself seems to work, and it's really just the dimensions ('x', 'y') that are computed incorrectly.

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.11.8 (main, Feb 25 2024, 16:41:26) [GCC 9.4.0] python-bits: 64 OS: Linux OS-release: 5.15.0-100-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: None libnetcdf: None xarray: 2024.2.0 pandas: 1.5.3 numpy: 1.26.4 scipy: None netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: None iris: None bottleneck: None dask: None distributed: None matplotlib: None cartopy: None seaborn: None numbagg: None fsspec: None cupy: 13.0.0 pint: None sparse: None flox: None numpy_groupies: None setuptools: None pip: None conda: None pytest: None mypy: None IPython: None sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/8820/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    xarray 13221727 issue
1848392846 PR_kwDOAMm_X85Xz2MY 8067 Fix assignment with .loc dranjan 404832 closed 0     6 2023-08-13T04:02:09Z 2023-09-12T18:17:12Z 2023-09-12T18:17:09Z CONTRIBUTOR   0 pydata/xarray/pulls/8067
  • [x] Closes #7030
  • [x] Tests added
  • [x] User visible changes (including notable bug fixes) are documented in whats-new.rst

Apparently DataArray instances on the right-hand side of Variable.__setitem__ were being stripped of their xarray metadata, leading to the incorrect broadcasting noted in #7030. My proposed fix is to add an explicit if-clause for this case.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/8067/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    xarray 13221727 pull
903055859 MDU6SXNzdWU5MDMwNTU4NTk= 5384 Regression: "ValueError: cannot unstack dimensions that do not have a MultiIndex" when unstacking a MultiIndex dranjan 404832 closed 0     5 2021-05-27T00:34:27Z 2021-05-28T08:28:11Z 2021-05-28T08:28:11Z CONTRIBUTOR      

I'm not sure if this is a bug or I'm not using xarray correctly, but I used to be able to do this without crashing. The new behavior seems to have been introduced some time between 0.16.2 and 0.18.2.

What happened:

python traceback Traceback (most recent call last): File "scripts/repro.py", line 12, in <module> ds = ds.unstack(['c']) File "/home/darsh/src/notebooks/build/venv/lib/python3.8/site-packages/xarray/core/dataset.py", line 4024, in unstack raise ValueError( ValueError: cannot unstack dimensions that do not have a MultiIndex: ['c']

What you expected to happen:

The code runs without the ValueError exception.

Minimal Complete Verifiable Example:

```python from xarray import DataArray, Dataset

a = DataArray([0], dims=['a']) b = a.stack(b=('a',)).reset_index('b') c = b.stack({'c': ['b']})

ds = Dataset({'d': DataArray(c.data, dims=['c'])}, coords=c.coords) print('\nBefore:') print(ds)

ds = ds.unstack(['c']) print('\nAfter:') print(ds) ```

Anything else we need to know?:

Here's the full output from the example on 0.18.2: ```

Before: <xarray.Dataset> Dimensions: (c: 1) Coordinates: * c (c) MultiIndex - b (c) int64 0 a (c) int64 0 Data variables: d (c) int64 0 Traceback (most recent call last): File "scripts/repro.py", line 12, in <module> ds = ds.unstack(['c']) File "/home/darsh/src/notebooks/build/venv/lib/python3.8/site-packages/xarray/core/dataset.py", line 4024, in unstack raise ValueError( ValueError: cannot unstack dimensions that do not have a MultiIndex: ['c'] `` What confuses me is that thecdimension is shown as aMultiIndex, but it still complains that it doesn't have aMultiIndex. Directly unstackingds.d` rather than the dataset itself also fails with the same exception.

Oddly, it seems to work if I assign the coordinates after constructing the dataset: ```diff diff --git a/scripts/repro.py b/scripts/repro.py index ed2ae7c..d5bd6a3 100644 --- a/scripts/repro.py +++ b/scripts/repro.py @@ -5,7 +5,7 @@ a = DataArray([0], dims=['a']) b = a.stack(b=('a',)).reset_index('b') c = b.stack({'c': ['b']})

-ds = Dataset({'d': DataArray(c.data, dims=['c'])}, coords=c.coords) +ds = Dataset({'d': DataArray(c.data, dims=['c'])}).assign_coords(c.coords) print('\nBefore:') print(ds)

```

With that workaround, or by downgrading to 0.16.2, the example doesn't crash:

```

Before: <xarray.Dataset> Dimensions: (c: 1) Coordinates: * c (c) MultiIndex - b (c) int64 0 a (c) int64 0 Data variables: d (c) int64 0

After: <xarray.Dataset> Dimensions: (b: 1) Coordinates: a (b) int64 0 * b (b) int64 0 Data variables: d (b) int64 0 ```

Environment:

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.8.0 (default, Feb 25 2021, 22:10:10) [GCC 8.4.0] python-bits: 64 OS: Linux OS-release: 5.4.0-73-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: None libnetcdf: None xarray: 0.18.2 pandas: 1.2.4 numpy: 1.20.3 scipy: 1.6.3 netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2021.05.0 distributed: None matplotlib: 3.4.2 cartopy: None seaborn: None numbagg: None pint: 0.17 setuptools: 39.0.1 pip: 21.1.1 conda: None pytest: 6.2.4 IPython: 7.23.1 sphinx: None None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5384/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed xarray 13221727 issue

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 72.812ms · About: xarray-datasette