Skip to content

Commit 98376b1

Browse files
committed
test: parametrize require_array dtype cases over (input, expected) pairs
Covers the `dtype=None` path, which resolves to float64 and was previously untested, and asserts on the resulting ZDType rather than the native dtype.
1 parent 80e7047 commit 98376b1

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

‎tests/test_group.py‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from zarr.core._info import GroupInfo
2525
from zarr.core.buffer import default_buffer_prototype
2626
from zarr.core.config import config as zarr_config
27-
from zarr.core.dtype import parse_data_type
27+
from zarr.core.dtype import Float64, Int32
2828
from zarr.core.dtype.common import unpack_dtype_json
2929
from zarr.core.dtype.npy.int import UInt8
3030
from zarr.core.group import (
@@ -62,6 +62,7 @@
6262

6363
from zarr.core.buffer.core import Buffer
6464
from zarr.core.common import JSON, ZarrFormat
65+
from zarr.core.dtype import ZDType, ZDTypeLike
6566

6667

6768
@pytest.fixture(params=["local", "memory", "zip"])
@@ -1440,17 +1441,27 @@ async def test_require_array(store: Store, zarr_format: ZarrFormat) -> None:
14401441
await root.require_array("bar", shape=(10,), dtype="int8")
14411442

14421443

1443-
async def test_require_array_zdtype(store: Store, zarr_format: ZarrFormat) -> None:
1444-
"""An existing array can be required with a ZDType, as well as a string or
1445-
a NumPy dtype. See https://github.com/zarr-developers/zarr-python/issues/3377
1444+
@pytest.mark.parametrize(
1445+
("dtype", "expected"),
1446+
[
1447+
(Int32(), Int32()),
1448+
(np.dtype("int32"), Int32()),
1449+
("int32", Int32()),
1450+
(None, Float64()),
1451+
],
1452+
ids=["zdtype", "numpy", "str", "none"],
1453+
)
1454+
async def test_require_array_zdtype(
1455+
store: Store, zarr_format: ZarrFormat, dtype: ZDTypeLike | None, expected: ZDType[Any, Any]
1456+
) -> None:
1457+
"""An existing array can be required with a ZDType, as well as a string, a NumPy dtype,
1458+
or None. See https://github.com/zarr-developers/zarr-python/issues/3377
14461459
"""
14471460
root = await AsyncGroup.from_store(store=store, zarr_format=zarr_format)
1448-
await root.require_array("foo", shape=(10,), dtype="int32")
1461+
await root.create_array("foo", shape=(10,), dtype=expected)
14491462

1450-
zdtype = parse_data_type("int32", zarr_format=zarr_format)
1451-
for dtype in (zdtype, np.dtype("int32"), "int32"):
1452-
foo = await root.require_array("foo", shape=(10,), dtype=dtype, exact=True)
1453-
assert foo.dtype == np.dtype("int32")
1463+
foo = await root.require_array("foo", shape=(10,), dtype=dtype, exact=True)
1464+
assert foo._zdtype == expected
14541465

14551466

14561467
@pytest.mark.parametrize("consolidate", [True, False])

0 commit comments

Comments
 (0)