22
33import numpy as np
44import pytest
5- from zarr import Array
5+ import zarr
66from zarr .abc .codec import Codec
77from zarr .abc .store import Store
8- from zarr .codecs import VLenBytesCodec , VLenUTF8Codec , ZstdCodec
8+ from zarr .codecs import ZstdCodec
99from zarr .core .metadata .v3 import ArrayV3Metadata , DataType
1010from zarr .core .strings import _NUMPY_SUPPORTS_VLEN_STRING
1111from zarr .storage import StorePath
1212
13- pytest .skip (allow_module_level = True )
14-
1513numpy_str_dtypes : list [type | str | None ] = [None , str , "str" , np .dtypes .StrDType ]
1614expected_zarr_string_dtype : np .dtype [Any ]
1715if _NUMPY_SUPPORTS_VLEN_STRING :
2119 expected_zarr_string_dtype = np .dtype ("O" )
2220
2321
24- @pytest .mark .parametrize ("store" , ["memory" , " local" ], indirect = ["store" ])
22+ @pytest .mark .parametrize ("store" , ["local" ], indirect = ["store" ])
2523@pytest .mark .parametrize ("dtype" , numpy_str_dtypes )
2624@pytest .mark .parametrize ("as_object_array" , [False , True ])
27- @pytest .mark .parametrize (
28- "codecs" , [None , [VLenUTF8Codec ()], [VLenUTF8Codec (), ZstdCodec ()]]
29- )
25+ @pytest .mark .parametrize ("compressor" , [None , ZstdCodec ()])
3026def test_vlen_string (
31- * ,
3227 store : Store ,
33- dtype : None | np .dtype [Any ],
28+ dtype : np .dtype [Any ] | None ,
29+ * ,
3430 as_object_array : bool ,
35- codecs : None | list [ Codec ] ,
31+ compressor : Codec | None ,
3632) -> None :
3733 strings = ["hello" , "world" , "this" , "is" , "a" , "test" ]
3834 data = np .array (strings , dtype = dtype ).reshape ((2 , 3 ))
3935
4036 sp = StorePath (store , path = "string" )
41- a = Array . create (
37+ a = zarr . create_array (
4238 sp ,
4339 shape = data .shape ,
44- chunk_shape = data .shape ,
40+ chunks = data .shape ,
4541 dtype = data .dtype ,
4642 fill_value = "" ,
47- codecs = codecs ,
43+ compressors = compressor ,
4844 )
4945 assert isinstance (a .metadata , ArrayV3Metadata ) # needed for mypy
5046
@@ -59,33 +55,31 @@ def test_vlen_string(
5955 assert a .dtype == expected_zarr_string_dtype
6056
6157 # test round trip
62- b = Array .open (sp )
58+ b = zarr .open (sp )
6359 assert isinstance (b .metadata , ArrayV3Metadata ) # needed for mypy
6460 assert np .array_equal (data , b [:, :])
6561 assert b .metadata .data_type == DataType .string
6662 assert a .dtype == expected_zarr_string_dtype
6763
6864
69- @pytest .mark .parametrize ("store" , ["memory" , " local" ], indirect = ["store" ])
65+ @pytest .mark .parametrize ("store" , ["local" ], indirect = ["store" ])
7066@pytest .mark .parametrize ("as_object_array" , [False , True ])
71- @pytest .mark .parametrize (
72- "codecs" , [None , [VLenBytesCodec ()], [VLenBytesCodec (), ZstdCodec ()]]
73- )
67+ @pytest .mark .parametrize ("compressor" , [None , ZstdCodec ()])
7468def test_vlen_bytes (
75- * , store : Store , as_object_array : bool , codecs : None | list [ Codec ]
69+ store : Store , * , as_object_array : bool , compressor : Codec | None
7670) -> None :
7771 bstrings = [b"hello" , b"world" , b"this" , b"is" , b"a" , b"test" ]
7872 data = np .array (bstrings ).reshape ((2 , 3 ))
7973 assert data .dtype == "|S5"
8074
8175 sp = StorePath (store , path = "string" )
82- a = Array . create (
76+ a = zarr . create_array (
8377 sp ,
8478 shape = data .shape ,
85- chunk_shape = data .shape ,
79+ chunks = data .shape ,
8680 dtype = data .dtype ,
8781 fill_value = b"" ,
88- codecs = codecs ,
82+ compressors = compressor ,
8983 )
9084 assert isinstance (a .metadata , ArrayV3Metadata ) # needed for mypy
9185
@@ -99,7 +93,7 @@ def test_vlen_bytes(
9993 assert a .dtype == "O"
10094
10195 # test round trip
102- b = Array .open (sp )
96+ b = zarr .open (sp )
10397 assert isinstance (b .metadata , ArrayV3Metadata ) # needed for mypy
10498 assert np .array_equal (data , b [:, :])
10599 assert b .metadata .data_type == DataType .bytes
0 commit comments