Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/zarr-metadata/changes/422.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Zarr format 2 time dtypes accept the generic time unit in brackets — `<M8[generic]`, or `<m8[2generic]` with a scale — the spellings zarr-python writes for a NumPy generic-unit time dtype. A unit is still required: the unitless `<M8` stays refused, as the v2 spec demands.
3 changes: 2 additions & 1 deletion packages/zarr-metadata/src/zarr_metadata/_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
"ps",
"fs",
"as",
"generic",
)
"""The units NumPy accepts for a datetime64 or timedelta64 (https://numpy.org/doc/stable/reference/arrays.datetime.html#datetime-units). The v3 types also accept `"generic"`."""
"""The units NumPy accepts for a datetime64 or timedelta64 (https://numpy.org/doc/stable/reference/arrays.datetime.html#datetime-units), and `"generic"`, NumPy's unit-less unit, which NumPy parses in brackets (`<M8[generic]`) though its own `dtype.str` omits it. The v2 spec's unit table does not list `generic`, but zarr-python writes it (zarr-developers/zarr-python#4580)."""

NUMPY_TIME_MAX_SCALE_FACTOR: Final = 2**31 - 1
"""The largest `scale_factor` that numpy stores, because the field is a signed int32."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]
"""The time unit codes of the numpy time types, `numpy.datetime64` and `numpy.timedelta64`."""

NUMPY_TIME_UNIT: Final = (*NUMPY_TIME_UNITS, "generic")
NUMPY_TIME_UNIT: Final = NUMPY_TIME_UNITS
"""Runtime tuple of the permitted `numpy.timedelta64`/`numpy.datetime64` unit strings."""

numpy_time_storage: Final = multi_byte
Expand Down
2 changes: 2 additions & 0 deletions packages/zarr-metadata/tests/v2/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def _read(value: object) -> tuple[type, list[tuple[Loc, str]]]:
("<M8[ns]", "datetime64", "<M8[ns]"),
(">M8[10s]", "datetime64", ">M8[10s]"),
("<M8[μs]", "datetime64", "<M8[us]"),
("<M8[generic]", "datetime64", "<M8[generic]"),
("<m8[D]", "timedelta64", "<m8[D]"),
(">m8[2generic]", "timedelta64", ">m8[2generic]"),
([["x", "<f4"], ["y", "<i4", [2]]], "struct", (("x", "<f4"), ("y", "<i4", (2,)))),
([["r", "|u1"], ["s", [["t", "<f4"]]]], "struct", (("r", "|u1"), ("s", (("t", "<f4"),)))),
# NumPy names the padding fields of an aligned struct "", and zarr 2.x writes them.
Expand Down
Loading