|
4 | 4 | import pickle |
5 | 5 | import re |
6 | 6 | from itertools import accumulate |
7 | | -from typing import Any, Literal |
| 7 | +from typing import TYPE_CHECKING, Any, Literal |
8 | 8 |
|
9 | 9 | import numcodecs |
10 | 10 | import numpy as np |
|
43 | 43 | from zarr.storage import LocalStore, MemoryStore |
44 | 44 | from zarr.storage.common import StorePath |
45 | 45 |
|
| 46 | +if TYPE_CHECKING: |
| 47 | + from zarr.core.array_spec import ArrayConfigParams |
| 48 | + |
46 | 49 |
|
47 | 50 | @pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) |
48 | 51 | @pytest.mark.parametrize("zarr_format", [2, 3]) |
@@ -421,16 +424,16 @@ async def test_nbytes_stored_async() -> None: |
421 | 424 |
|
422 | 425 |
|
423 | 426 | def test_default_fill_values() -> None: |
424 | | - a = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="<U4") |
| 427 | + a = zarr.Array.create(MemoryStore(), shape=5, chunk_shape=5, dtype="<U4") |
425 | 428 | assert a.fill_value == "" |
426 | 429 |
|
427 | | - b = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="<S4") |
| 430 | + b = zarr.Array.create(MemoryStore(), shape=5, chunk_shape=5, dtype="<S4") |
428 | 431 | assert b.fill_value == b"" |
429 | 432 |
|
430 | | - c = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="i") |
| 433 | + c = zarr.Array.create(MemoryStore(), shape=5, chunk_shape=5, dtype="i") |
431 | 434 | assert c.fill_value == 0 |
432 | 435 |
|
433 | | - d = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="f") |
| 436 | + d = zarr.Array.create(MemoryStore(), shape=5, chunk_shape=5, dtype="f") |
434 | 437 | assert d.fill_value == 0.0 |
435 | 438 |
|
436 | 439 |
|
@@ -458,15 +461,17 @@ def test_vlen_errors() -> None: |
458 | 461 | match="For string dtype, ArrayBytesCodec must be `VLenUTF8Codec`, got `BytesCodec`.", |
459 | 462 | ): |
460 | 463 | zarr.create_array( |
461 | | - MemoryStore(), shape=5, chunks=5, dtype="<U4", array_bytes_codec=BytesCodec() |
| 464 | + MemoryStore(), shape=(5,), chunks=(5,), dtype="<U4", array_bytes_codec=BytesCodec() |
462 | 465 | ) |
463 | 466 |
|
464 | 467 |
|
465 | 468 | @pytest.mark.parametrize("zarr_format", [2, 3]) |
466 | | -def test_update_attrs(zarr_format: int) -> None: |
| 469 | +def test_update_attrs(zarr_format: Literal[2, 3]) -> None: |
467 | 470 | # regression test for https://github.com/zarr-developers/zarr-python/issues/2328 |
468 | 471 | store = MemoryStore() |
469 | | - arr = zarr.create_array(store=store, shape=5, chunks=5, dtype="f8", zarr_format=zarr_format) |
| 472 | + arr = zarr.create_array( |
| 473 | + store=store, shape=(5,), chunks=(5,), dtype="f8", zarr_format=zarr_format |
| 474 | + ) |
470 | 475 | arr.attrs["foo"] = "bar" |
471 | 476 | assert arr.attrs["foo"] == "bar" |
472 | 477 |
|
@@ -794,13 +799,14 @@ def test_array_create_metadata_order_v2( |
794 | 799 | @pytest.mark.parametrize("store", ["memory"], indirect=True) |
795 | 800 | def test_array_create_order( |
796 | 801 | order_config: MemoryOrder | None, |
797 | | - zarr_format: int, |
| 802 | + zarr_format: Literal[2, 3], |
798 | 803 | store: MemoryStore, |
799 | 804 | ) -> None: |
800 | 805 | """ |
801 | 806 | Test that the arrays generated by array indexing have a memory order defined by the config order |
802 | 807 | value |
803 | 808 | """ |
| 809 | + config: ArrayConfigParams = {} |
804 | 810 | if order_config is None: |
805 | 811 | config = {} |
806 | 812 | expected = zarr.config.get("array.order") |
@@ -963,16 +969,16 @@ def test_chunks_and_shards() -> None: |
963 | 969 |
|
964 | 970 |
|
965 | 971 | def test_create_array_default_fill_values() -> None: |
966 | | - a = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="<U4") |
| 972 | + a = zarr.create_array(MemoryStore(), shape=(5,), chunks=(5,), dtype="<U4") |
967 | 973 | assert a.fill_value == "" |
968 | 974 |
|
969 | | - b = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="<S4") |
| 975 | + b = zarr.create_array(MemoryStore(), shape=(5,), chunks=(5,), dtype="<S4") |
970 | 976 | assert b.fill_value == b"" |
971 | 977 |
|
972 | | - c = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="i") |
| 978 | + c = zarr.create_array(MemoryStore(), shape=(5,), chunks=(5,), dtype="i") |
973 | 979 | assert c.fill_value == 0 |
974 | 980 |
|
975 | | - d = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="f") |
| 981 | + d = zarr.create_array(MemoryStore(), shape=(5,), chunks=(5,), dtype="f") |
976 | 982 | assert d.fill_value == 0.0 |
977 | 983 |
|
978 | 984 |
|
|
0 commit comments