|
11 | 11 | from zarr import Array, zeros |
12 | 12 | from zarr.abc.codec import CodecInput, CodecOutput, CodecPipeline |
13 | 13 | from zarr.abc.store import ByteSetter, Store |
14 | | -from zarr.codecs import BloscCodec, BytesCodec, Crc32cCodec, ShardingCodec, TransposeCodec, GzipCodec, VLenBytesCodec, \ |
15 | | - VLenUTF8Codec |
| 14 | +from zarr.codecs import ( |
| 15 | + BloscCodec, |
| 16 | + BytesCodec, |
| 17 | + Crc32cCodec, |
| 18 | + GzipCodec, |
| 19 | + ShardingCodec, |
| 20 | + VLenBytesCodec, |
| 21 | + VLenUTF8Codec, |
| 22 | +) |
16 | 23 | from zarr.core.array_spec import ArraySpec |
17 | 24 | from zarr.core.buffer import NDBuffer |
18 | 25 | from zarr.core.codec_pipeline import BatchedCodecPipeline |
@@ -216,39 +223,44 @@ def test_config_buffer_implementation() -> None: |
216 | 223 | arr[:] = np.arange(100) |
217 | 224 |
|
218 | 225 | register_buffer(TestBuffer) |
219 | | - config.set({"buffer": fully_qualified_name(TestBuffer)}) |
220 | | - assert get_buffer_class() == TestBuffer |
221 | | - |
222 | | - # no error using TestBuffer |
223 | | - data = np.arange(100) |
224 | | - arr[:] = np.arange(100) |
225 | | - assert np.array_equal(arr[:], data) |
226 | | - |
227 | | - data2d = np.arange(1000).reshape(100, 10) |
228 | | - arr_sharding = zeros( |
229 | | - shape=(100, 10), |
230 | | - store=StoreExpectingTestBuffer(), |
231 | | - codecs=[ShardingCodec(chunk_shape=(10, 10))], |
232 | | - ) |
233 | | - arr_sharding[:] = data2d |
234 | | - assert np.array_equal(arr_sharding[:], data2d) |
| 226 | + with config.set({"buffer": fully_qualified_name(TestBuffer)}): |
| 227 | + assert get_buffer_class() == TestBuffer |
| 228 | + |
| 229 | + # no error using TestBuffer |
| 230 | + data = np.arange(100) |
| 231 | + arr[:] = np.arange(100) |
| 232 | + assert np.array_equal(arr[:], data) |
| 233 | + |
| 234 | + data2d = np.arange(1000).reshape(100, 10) |
| 235 | + arr_sharding = zeros( |
| 236 | + shape=(100, 10), |
| 237 | + store=StoreExpectingTestBuffer(), |
| 238 | + codecs=[ShardingCodec(chunk_shape=(10, 10))], |
| 239 | + ) |
| 240 | + arr_sharding[:] = data2d |
| 241 | + assert np.array_equal(arr_sharding[:], data2d) |
| 242 | + |
| 243 | + arr_Crc32c = zeros( |
| 244 | + shape=(100, 10), |
| 245 | + store=StoreExpectingTestBuffer(), |
| 246 | + codecs=[BytesCodec(), Crc32cCodec()], |
| 247 | + ) |
| 248 | + arr_Crc32c[:] = data2d |
| 249 | + assert np.array_equal(arr_Crc32c[:], data2d) |
235 | 250 |
|
236 | | - arr_Crc32c = zeros( |
237 | | - shape=(100, 10), |
238 | | - store=StoreExpectingTestBuffer(), |
239 | | - codecs=[BytesCodec(), Crc32cCodec()], |
240 | | - ) |
241 | | - arr_Crc32c[:] = data2d |
242 | | - assert np.array_equal(arr_Crc32c[:], data2d) |
243 | 251 |
|
244 | 252 | @pytest.mark.parametrize("dtype", ["int", "bytes", "str"]) |
245 | | -def test_default_codecs(dtype:str) -> None: |
246 | | - with config.set({"array.v3_default_codecs": { |
247 | | - "numeric": ["bytes", "gzip"], # test setting non-standard codecs |
248 | | - "string": ["vlen-utf8"], |
249 | | - "bytes": ["vlen-bytes"], |
250 | | - }}): |
251 | | - arr = zeros(shape=(100), store=StoreExpectingTestBuffer(), dtype=dtype) |
| 253 | +def test_default_codecs(dtype: str) -> None: |
| 254 | + with config.set( |
| 255 | + { |
| 256 | + "array.v3_default_codecs": { |
| 257 | + "numeric": ["bytes", "gzip"], # test setting non-standard codecs |
| 258 | + "string": ["vlen-utf8"], |
| 259 | + "bytes": ["vlen-bytes"], |
| 260 | + } |
| 261 | + } |
| 262 | + ): |
| 263 | + arr = zeros(shape=(100), dtype=dtype) |
252 | 264 | if dtype == "int": |
253 | 265 | assert arr.metadata.codecs == [BytesCodec(), GzipCodec()] |
254 | 266 | elif dtype == "bytes": |
|
0 commit comments