Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean index assignment fails for values of ndim>1 #11398

Open
lucascolley opened this issue Sep 18, 2024 · 0 comments
Open

Boolean index assignment fails for values of ndim>1 #11398

lucascolley opened this issue Sep 18, 2024 · 0 comments
Labels

Comments

@lucascolley
Copy link
Contributor

This works in NumPy, but fails in Dask.

In [1]: import numpy as np

In [2]: import dask.array as da

In [3]: x = np.asarray([[1, 2]])

In [4]: y = np.asarray([[3, 4]])

In [5]: i = np.asarray([True])

In [6]: xd = da.asarray(x)

In [7]: yd = da.asarray(y)

In [8]: id = da.asarray(i)

In [9]: x[i] = y[i]

In [10]: x
Out[10]: array([[3, 4]])

In [11]: xd[id] = yd[id]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[11], line 1
----> 1 xd[id] = yd[id]

File ~/programming/pixi-dev-scipystack/scipy/.pixi/envs/array-api/lib/python3.12/site-packages/dask/array/core.py:1903, in Array.__setitem__(self, key, value)
   1900 from dask.array.routines import where
   1902 if isinstance(value, Array) and value.ndim > 1:
-> 1903     raise ValueError("boolean index array should have 1 dimension")
   1904 try:
   1905     y = where(key, value, self)

ValueError: boolean index array should have 1 dimension

In [12]: yd[id].ndim
Out[12]: 2

Anything else we need to know?:
I think the error message is unclear too. I initially thought that the "boolean index array" referred to id here (the index array), as opposed to yd[id], the value array being assigned.

@github-actions github-actions bot added the needs triage Needs a response from a contributor label Sep 18, 2024
@phofl phofl added array and removed needs triage Needs a response from a contributor labels Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants