NDArray.__setitem__ raises AttributeError for list index keys

未關閉 適合新手
#764 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
82/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
data

研究方向

從 src/blosc2/ndarray.py 中 NDArray.setitem 的進階索引分支開始,特別檢查第 5106–5108 行附近對純量布林鍵的檢查。將使用列表鍵和元組鍵的指定與正常運作的 NumPy 陣列案例進行比較。完成條件是這些指定不再引發 AttributeError,且既有的陣列鍵行為仍正常運作。

由索引模型根據 Issue 內容生成。

描述

Assigning with a fancy index that is a Python list, or a tuple that contains an index array or list, raises AttributeError (main d3bca9e5 and 4.14.1). Reading with the same keys works, and an index array as the whole key works too.

import blosc2, numpy as np
a = blosc2.zeros((20, 30, 40), dtype=np.float32)
idx = np.array([1, 3, 5])

a[idx] = np.ones((3, 30, 40), np.float32)              # ok
a[[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.

主要語言
Python
星號
214
分支
72
平均合併
3 天 9 小時
30 天內合併 PR
24

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Blosc/python-blosc2 的其他 Issue

查看 Blosc/python-blosc2 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。