Skip to content

improvements to parse_dtype #3264

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

Merged
merged 21 commits into from
Jul 22, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add test to check that parse_dtype is parse_data_type
  • Loading branch information
d-v-b committed Jul 17, 2025
commit d684ada2b95f9d0b9fe2bb8c26a49cda31c432d3
26 changes: 25 additions & 1 deletion tests/test_dtype_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ZDType,
data_type_registry,
get_data_type_from_json,
parse_data_type,
parse_dtype,
)

Expand Down Expand Up @@ -174,7 +175,7 @@ def test_entrypoint_dtype(zarr_format: ZarrFormat) -> None:
@pytest.mark.parametrize("data_type", zdtype_examples, ids=str)
def test_parse_data_type(data_type: ZDType[Any, Any], zarr_format: ZarrFormat) -> None:
"""
Test that parse_data_type accepts alternative representations of ZDType instances, and resolves
Test that parse_dtype accepts alternative representations of ZDType instances, and resolves
those inputs to the expected ZDType instance.
"""
dtype_spec: Any
Expand All @@ -189,3 +190,26 @@ def test_parse_data_type(data_type: ZDType[Any, Any], zarr_format: ZarrFormat) -
else:
observed = parse_dtype(dtype_spec, zarr_format=zarr_format)
assert observed == data_type


@pytest.mark.filterwarnings("ignore::zarr.core.dtype.common.UnstableSpecificationWarning")
@pytest.mark.parametrize("data_type", zdtype_examples, ids=str)
def test_parse_data_type_funcs(data_type: ZDType[Any, Any], zarr_format: ZarrFormat) -> None:
"""
Test that parse_data_type generates the same output as parse_dtype.
"""
dtype_spec: Any
if zarr_format == 2:
dtype_spec = data_type.to_json(zarr_format=zarr_format)["name"]
else:
dtype_spec = data_type.to_json(zarr_format=zarr_format)
if dtype_spec == "|O":
msg = "Zarr data type resolution from object failed."
with pytest.raises(ValueError, match=msg):
parse_dtype(dtype_spec, zarr_format=zarr_format)
with pytest.raises(ValueError, match=msg):
parse_data_type(dtype_spec, zarr_format=zarr_format)
else:
assert parse_dtype(dtype_spec, zarr_format=zarr_format) == parse_data_type(
dtype_spec, zarr_format=zarr_format
)
Loading