Skip to content

Commit 6f56881

Browse files
committed
Passing (or xfailing) test_array tests
1 parent ace0846 commit 6f56881

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/zarr/core/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ def parse_bool(data: Any) -> bool:
168168

169169

170170
def parse_dtype(dtype: Any, zarr_format: ZarrFormat) -> np.dtype[Any]:
171+
if "datatype" in type(dtype).__name__.lower():
172+
# Workaround until we have the class in place
173+
return dtype.to_numpy() # TODO: call conversion method
171174
if dtype is str or dtype == "str":
172175
if zarr_format == 2:
173176
# special case as object

src/zarr/core/metadata/v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ def to_numpy_shortname(self) -> str:
659659
DataType.float64: "f8",
660660
DataType.complex64: "c8",
661661
DataType.complex128: "c16",
662-
DataType.example: np.dtype(object),
662+
DataType.example: "bool", # Something numpy-ish
663663
}
664664
return data_type_to_numpy[self]
665665

src/zarr/registry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def register(self, cls: type[T]) -> None:
5353
__pipeline_registry: Registry[CodecPipeline] = Registry()
5454
__buffer_registry: Registry[Buffer] = Registry()
5555
__ndbuffer_registry: Registry[NDBuffer] = Registry()
56+
__dtype_registry: Registry[DataType] = Registry()
5657

5758
"""
5859
The registry module is responsible for managing implementations of codecs,

tests/test_array.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,3 +1444,36 @@ async def test_sharding_coordinate_selection() -> None:
14441444
)
14451445
arr[:] = np.arange(2 * 3 * 4).reshape((2, 3, 4))
14461446
assert (arr[1, [0, 1]] == np.array([[12, 13, 14, 15], [16, 17, 18, 19]])).all() # type: ignore[index]
1447+
1448+
1449+
@pytest.mark.xfail(reason="zarr.common.core maps any string to the string type")
1450+
async def test_array_v3_ext_uri_by_string(
1451+
) -> None:
1452+
"""
1453+
Test the user impact of the extension mechanism
1454+
"""
1455+
store = MemoryStore()
1456+
g = zarr.open_group(store, mode="w")
1457+
arr = g.create_array(
1458+
name="a",
1459+
dtype="https://example.com", # Or require here a DataType instance
1460+
shape=(12,),
1461+
chunks=(3,),
1462+
)
1463+
assert arr.data_type == None # TODO: import the example dtype
1464+
1465+
1466+
async def test_array_v3_ext_uri_by_class(
1467+
) -> None:
1468+
"""
1469+
Test the user impact of the extension mechanism
1470+
"""
1471+
store = MemoryStore()
1472+
g = zarr.open_group(store, mode="w")
1473+
arr = g.create_array(
1474+
name="a",
1475+
dtype=DataType.example,
1476+
shape=(12,),
1477+
chunks=(3,),
1478+
)
1479+
assert arr.dtype == np.dtype(bool)

0 commit comments

Comments
 (0)