Skip to content

Commit ace0846

Browse files
committed
example data-type extension
1 parent 24ef221 commit ace0846

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/zarr/core/metadata/v3.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ class DataType(Enum):
612612
complex128 = "complex128"
613613
string = "string"
614614
bytes = "bytes"
615+
example = "https://example.com"
615616

616617
@property
617618
def byte_count(self) -> int | None:
@@ -630,6 +631,7 @@ def byte_count(self) -> int | None:
630631
DataType.float64: 8,
631632
DataType.complex64: 8,
632633
DataType.complex128: 16,
634+
DataType.example: 32,
633635
}
634636
try:
635637
return data_type_byte_counts[self]
@@ -657,9 +659,11 @@ def to_numpy_shortname(self) -> str:
657659
DataType.float64: "f8",
658660
DataType.complex64: "c8",
659661
DataType.complex128: "c16",
662+
DataType.example: np.dtype(object),
660663
}
661664
return data_type_to_numpy[self]
662665

666+
663667
def to_numpy(self) -> np.dtypes.StringDType | np.dtypes.ObjectDType | np.dtype[Any]:
664668
# note: it is not possible to round trip DataType <-> np.dtype
665669
# due to the fact that DataType.string and DataType.bytes both

tests/test_metadata/test_v3.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,18 @@ def test_dtypes(dtype_str: str) -> None:
411411
else:
412412
# return type for vlen types may vary depending on numpy version
413413
assert dt.byte_count is None
414+
415+
async def test_ext_uri() -> None:
416+
metadata_dict = {
417+
"zarr_format": 3,
418+
"node_type": "array",
419+
"shape": (1,),
420+
"chunk_grid": {"name": "regular", "configuration": {"chunk_shape": (1,)}},
421+
"data_type": "https://example.com",
422+
"chunk_key_encoding": {"name": "default", "separator": "."},
423+
"codecs": [{"name": "bytes"}],
424+
"fill_value": 0,
425+
}
426+
m = ArrayV3Metadata.from_dict(metadata_dict)
427+
d = json.loads(m.to_buffer_dict(default_buffer_prototype())["zarr.json"].to_bytes())
428+
assert m.data_type is DataType.example

0 commit comments

Comments
 (0)