Variable-width strings load from Zarr with an unexpected dtype of "numpy.dtypes.StringDType"

オープン
#7,374 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
numpy, python
領域
data

調査の方向性

Start by reading the Zarr loading path and the existing handling of object dtype strings, then compare it with the example using NumPy StringDType and Zarr format 3. Check the related context in issue #7092 to understand the stated support limitation. Done means loading the example no longer returns an unexpected dtype, with a focused regression test covering the result.

索引モデルが issue の本文から書いたものです。

説明

It appears that zarr will create this from numpy arrays of type 'np.dtypes.StringDType'.
To create this with Zarr we must supply the 'StringDType' dtype.
The result is that the zarr data has a simple '"dtype" = "string"' in the metadata.

The current Iris Zarr saver seems to understand to do this conversion with arrays of type 'object',
I.E. like`np.array('a', 'one'], dtype="O")``
( which is how netCDF4 reads back variable-length strings ).

For this type of data, however,
when loading, iris produces numpy arrays of dtype 'StringDType' instead of 'O'.
N.B. we don't expect to handle this correctly yet, cf #7092

For example:

# Create the original NetCDF variable-length string array.
string_values = np.array(["one", "a", "ninety-nine"], dtype=object)

root = zarr.open_group("string_data.zarr", mode="w")
vxs = root.create_array("vxs", data=string_values.astype(np.dtypes.StringDType))
print("Zarr strings written:", vxs[:].tolist())

print()
print("vxs metdata:")
os.system("cat string_data.zarr/vxs/zarr.json")

print()
cube = iris.load_cube("string_data.zarr")
print("Iris data read:", repr(cube.data))

giving


vxs metdata:
{
  "shape": [
    3
  ],
  "data_type": "string",
  "chunk_grid":  ...
...
  "attributes": {},
  "zarr_format": 3,
  "node_type": "array",
  "storage_transformers": []
}
Iris data read: array(['one', 'a', 'ninety-nine'], dtype=StringDType())

主要言語
Python
スター
730
フォーク
323
平均マージ
3日 21時間
マージ済み PR(30日)
16

環境構築

はじめの一歩

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

SciTools/iris のほかの issue

SciTools/iris の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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