-
-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: validate v3 dtypes when loading/creating v3 metadata #2209
Conversation
src/zarr/core/array_spec.py
Outdated
@@ -29,7 +29,7 @@ def __init__( | |||
prototype: BufferPrototype, | |||
) -> None: | |||
shape_parsed = parse_shapelike(shape) | |||
dtype_parsed = parse_dtype(dtype) | |||
dtype_parsed = dtype # parsing is likely not needed here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dtype_parsed = dtype # parsing is likely not needed here | |
dtype_parsed = dtype |
The input type is already np.dtype[Any]
so I don't think we need to parse this.
@@ -157,6 +157,11 @@ def update_attributes(self, attributes: dict[str, JSON]) -> Self: | |||
return replace(self, attributes=attributes) | |||
|
|||
|
|||
def parse_dtype(data: npt.DTypeLike) -> np.dtype[Any]: | |||
# todo: real validation | |||
return np.dtype(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we now parse v2 and v3 dtypes differently.
dtype=npst.scalar_dtypes().filter(lambda x: x.kind != "m"), | ||
dtype=npst.scalar_dtypes().filter( | ||
lambda x: (x.kind not in ["m", "M"]) and (x.byteorder not in [">"]) | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur. It's not being handled today
async def test_datetime_metadata(fill_value: int, precision: str) -> None: | ||
# @pytest.mark.parametrize("fill_value", [-1, 0, 1, 2932897]) | ||
# @pytest.mark.parametrize("precision", ["ns", "D"]) | ||
# async def test_datetime_metadata(fill_value: int, precision: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test was creating an invalid dtype (datetime). We can leave it in place and bring it back when there is support for this dtype in v3.
(0, "int16"), | ||
(1e10, "uint64"), | ||
(-999, "float32"), | ||
(1e32, "float64"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add a test for NaN fill values
Co-authored-by: Davis Bennett <[email protected]>
this looks great, thanks! |
* v3: chore: update pre-commit hooks (zarr-developers#2222) fix: validate v3 dtypes when loading/creating v3 metadata (zarr-developers#2209) fix typo in store integration test (zarr-developers#2223) Basic Zarr-python 2.x compatibility changes (zarr-developers#2098) Make Group.arrays, groups compatible with v2 (zarr-developers#2213) Typing fixes to test_indexing (zarr-developers#2193) Default to RemoteStore for fsspec URIs (zarr-developers#2198) Make MemoryStore serialiazable (zarr-developers#2204) [v3] Implement Group methods for empty, full, ones, and zeros (zarr-developers#2210) implement `store.list_prefix` and `store._set_many` (zarr-developers#2064) Fixed codec for v2 data with no fill value (zarr-developers#2207)
This PR validates data types in v3 metadata. The behavior implemented raises an error if a data type outside of the current v3 spec is discovered in either a
zarr.json
metadata document or in theArray
constructor.xref: #2200
TODO: