You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NDArray.__setitem__ raises AttributeError for list index keys #764
Assigning with a fancy index that is a Python list, or a tuple that contains an index array or list, raises AttributeError (main d3bca9e and 4.14.1). Reading with the same keys works, and an index array as the whole key works too.
importblosc2, numpyasnpa=blosc2.zeros((20, 30, 40), dtype=np.float32)
idx=np.array([1, 3, 5])
a[idx] =np.ones((3, 30, 40), np.float32) # oka[[1, 3, 5]] =np.ones((3, 30, 40), np.float32) # AttributeError: 'list' object has no attribute 'shape'a[[1, 3, 5], 3:17] =np.ones((3, 14, 40), np.float32) # AttributeError: 'tuple' object has no attribute 'shape'a[idx, 3:17] =np.ones((3, 14, 40), np.float32) # AttributeError: 'tuple' object has no attribute 'shape'a[2, [1, 3, 5]] =np.ones((3, 40), np.float32) # AttributeError: 'tuple' object has no attribute 'shape'a[[1, 3, 5], 3:17] # reading works
Cause. The fancy-index branch of NDArray.__setitem__ checks for a scalar boolean key on the original key, key.shape == () and hasattr(key, "dtype") and ... (ndarray.py#L5106-L5108), which only works when key is a NumPy array. Testing isinstance(key, np.ndarray) (or getattr(key, "shape", None) == ()) first should be enough.
Found while testing write paths for #763; not fixed there to keep that PR to one change.
Activity