|
24 | 24 | from zarr.core._info import GroupInfo |
25 | 25 | from zarr.core.buffer import default_buffer_prototype |
26 | 26 | 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 |
28 | 28 | from zarr.core.dtype.common import unpack_dtype_json |
29 | 29 | from zarr.core.dtype.npy.int import UInt8 |
30 | 30 | from zarr.core.group import ( |
|
62 | 62 |
|
63 | 63 | from zarr.core.buffer.core import Buffer |
64 | 64 | from zarr.core.common import JSON, ZarrFormat |
| 65 | + from zarr.core.dtype import ZDType, ZDTypeLike |
65 | 66 |
|
66 | 67 |
|
67 | 68 | @pytest.fixture(params=["local", "memory", "zip"]) |
@@ -1440,17 +1441,27 @@ async def test_require_array(store: Store, zarr_format: ZarrFormat) -> None: |
1440 | 1441 | await root.require_array("bar", shape=(10,), dtype="int8") |
1441 | 1442 |
|
1442 | 1443 |
|
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 |
1446 | 1459 | """ |
1447 | 1460 | 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) |
1449 | 1462 |
|
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 |
1454 | 1465 |
|
1455 | 1466 |
|
1456 | 1467 | @pytest.mark.parametrize("consolidate", [True, False]) |
|
0 commit comments