Skip to content

Unable to rechunk a view of a 2-d sliced AnnData with a dask array #2330

@joshua-gould

Description

@joshua-gould

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of anndata.
  • (optional) I have confirmed this bug exists on the main branch of anndata.

Report

Code:

import anndata
import dask.array as da
import numpy as np

x = da.random.random((10, 10))
d = anndata.AnnData(x)
x2 = x[[0, 1, 4]][..., [0, 1, 4]]
x2 = x2.rechunk('auto')

d2 = d[[0, 1, 4], [0, 1, 4]]
np.testing.assert_equal(d2.X.compute(), x2.compute())
d2.X = d2.X.rechunk(
    'auto')  # Incorrect shape ((3, 1)) of integer indices for dimension with size 10


Traceback:

```pytb
  File "lib/python3.12/site-packages/anndata/_core/anndata.py", line 678, in X
    self._adata_ref._X[oidx, vidx] = value
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "lib/python3.12/site-packages/dask/array/core.py", line 1968, in __setitem__
    dsk = setitem_array(out, self, key, value)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/dask/array/slicing.py", line 1712, in setitem_array
    indices, implied_shape, reverse, implied_shape_positions = parse_assignment_indices(
                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/dask/array/slicing.py", line 1395, in parse_assignment_indices
    raise IndexError(
IndexError: Incorrect shape ((3, 1)) of integer indices for dimension with size 10

Versions

| Dependency                    | Version     |
| ----------------------------- | ----------- |
| setuptools                    | 80.9.0      |
| sphinxcontrib-jquery          | 4.1         |
| sphinxcontrib-htmlhelp        | 2.1.0       |
| cloudpickle                   | 3.1.2       |
| cycler                        | 0.12.1      |
| python-dateutil               | 2.9.0.post0 |
| pillow                        | 11.3.0      |
| Pygments                      | 2.19.2      |
| omegaconf                     | 2.3.0       |
| pyparsing                     | 3.3.1       |
| argcomplete                   | 3.6.3       |
| sphinxcontrib-qthelp          | 2.0.0       |
| sphinxcontrib-jsmath          | 1.0.1       |
| pure_eval                     | 0.2.3       |
| six                           | 1.17.0      |
| session-info2                 | 0.3         |
| executing                     | 2.2.1       |
| pytz                          | 2025.2      |
| packaging                     | 25.0        |
| ipython                       | 9.9.0       |
| parso                         | 0.8.5       |
| asttokens                     | 3.0.1       |
| matplotlib                    | 3.10.8      |
| prompt_toolkit                | 3.0.52      |
| decorator                     | 5.2.1       |
| defusedxml                    | 0.7.1       |
| pandas                        | 2.3.3       |
| pyarrow                       | 23.0.0      |
| wcwidth                       | 0.2.14      |
| sphinxcontrib-devhelp         | 2.0.0       |
| sphinxcontrib-applehelp       | 2.0.0       |
| numpy                         | 1.26.4      |
| traitlets                     | 5.14.3      |
| jedi                          | 0.19.2      |
| kiwisolver                    | 1.4.9       |
| stack-data                    | 0.6.3       |
| sphinxcontrib-serializinghtml | 2.0.0       |
| Component | Info                                                                              |
| --------- | --------------------------------------------------------------------------------- |
| Python    | 3.12.12 | packaged by conda-forge | (main, Oct 22 2025, 23:34:53) [Clang 19.1.7 ] |
| OS        | macOS-26.2-arm64-arm-64bit                                                        |
| Updated   | 2026-02-05 15:17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions