NDArray.__setitem__ raises AttributeError for list index keys

オープン 初心者向け
#764 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
24

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Blosc/python-blosc2 のほかの issue

Blosc/python-blosc2 の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。