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

Aperta
#7,374 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
numpy, python
Ambito
data

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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())

Lingua principale
Python
Stelle
730
Fork
323
Merge medio
3g 21h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SciTools/iris

Tutte le issue di SciTools/iris

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.