25
25
from zarr .chunk_key_encodings import ChunkKeyEncoding , DefaultChunkKeyEncoding , V2ChunkKeyEncoding
26
26
from zarr .codecs import BytesCodec
27
27
from zarr .codecs ._v2 import V2Compressor , V2Filters
28
- from zarr .codecs .pipeline import BatchedCodecPipeline
29
28
from zarr .common import (
30
29
JSON ,
31
30
ZARR_JSON ,
61
60
pop_fields ,
62
61
)
63
62
from zarr .metadata import ArrayMetadata , ArrayV2Metadata , ArrayV3Metadata
63
+ from zarr .registry import get_pipeline_class
64
64
from zarr .store import StoreLike , StorePath , make_store_path
65
65
from zarr .store .core import (
66
66
ensure_no_existing_node ,
@@ -79,11 +79,11 @@ def parse_array_metadata(data: Any) -> ArrayV2Metadata | ArrayV3Metadata:
79
79
raise TypeError
80
80
81
81
82
- def create_codec_pipeline (metadata : ArrayV2Metadata | ArrayV3Metadata ) -> BatchedCodecPipeline :
82
+ def create_codec_pipeline (metadata : ArrayV2Metadata | ArrayV3Metadata ) -> CodecPipeline :
83
83
if isinstance (metadata , ArrayV3Metadata ):
84
- return BatchedCodecPipeline .from_list (metadata .codecs )
84
+ return get_pipeline_class () .from_list (metadata .codecs )
85
85
elif isinstance (metadata , ArrayV2Metadata ):
86
- return BatchedCodecPipeline .from_list (
86
+ return get_pipeline_class () .from_list (
87
87
[V2Filters (metadata .filters or []), V2Compressor (metadata .compressor )]
88
88
)
89
89
else :
@@ -483,8 +483,13 @@ async def _get_selection(
483
483
return out_buffer .as_ndarray_like ()
484
484
485
485
async def getitem (
486
- self , selection : BasicSelection , * , prototype : BufferPrototype = default_buffer_prototype
486
+ self ,
487
+ selection : BasicSelection ,
488
+ * ,
489
+ prototype : BufferPrototype | None = None ,
487
490
) -> NDArrayLike :
491
+ if prototype is None :
492
+ prototype = default_buffer_prototype ()
488
493
indexer = BasicIndexer (
489
494
selection ,
490
495
shape = self .metadata .shape ,
@@ -493,7 +498,7 @@ async def getitem(
493
498
return await self ._get_selection (indexer , prototype = prototype )
494
499
495
500
async def _save_metadata (self , metadata : ArrayMetadata ) -> None :
496
- to_save = metadata .to_buffer_dict ()
501
+ to_save = metadata .to_buffer_dict (default_buffer_prototype () )
497
502
awaitables = [set_or_delete (self .store_path / key , value ) for key , value in to_save .items ()]
498
503
await gather (* awaitables )
499
504
@@ -545,8 +550,10 @@ async def setitem(
545
550
self ,
546
551
selection : BasicSelection ,
547
552
value : npt .ArrayLike ,
548
- prototype : BufferPrototype = default_buffer_prototype ,
553
+ prototype : BufferPrototype | None = None ,
549
554
) -> None :
555
+ if prototype is None :
556
+ prototype = default_buffer_prototype ()
550
557
indexer = BasicIndexer (
551
558
selection ,
552
559
shape = self .metadata .shape ,
@@ -1001,7 +1008,7 @@ def get_basic_selection(
1001
1008
selection : BasicSelection = Ellipsis ,
1002
1009
* ,
1003
1010
out : NDBuffer | None = None ,
1004
- prototype : BufferPrototype = default_buffer_prototype ,
1011
+ prototype : BufferPrototype | None = None ,
1005
1012
fields : Fields | None = None ,
1006
1013
) -> NDArrayLike :
1007
1014
"""Retrieve data for an item or region of the array.
@@ -1108,6 +1115,8 @@ def get_basic_selection(
1108
1115
1109
1116
"""
1110
1117
1118
+ if prototype is None :
1119
+ prototype = default_buffer_prototype ()
1111
1120
return sync (
1112
1121
self ._async_array ._get_selection (
1113
1122
BasicIndexer (selection , self .shape , self .metadata .chunk_grid ),
@@ -1123,7 +1132,7 @@ def set_basic_selection(
1123
1132
value : npt .ArrayLike ,
1124
1133
* ,
1125
1134
fields : Fields | None = None ,
1126
- prototype : BufferPrototype = default_buffer_prototype ,
1135
+ prototype : BufferPrototype | None = None ,
1127
1136
) -> None :
1128
1137
"""Modify data for an item or region of the array.
1129
1138
@@ -1207,6 +1216,8 @@ def set_basic_selection(
1207
1216
vindex, oindex, blocks, __getitem__, __setitem__
1208
1217
1209
1218
"""
1219
+ if prototype is None :
1220
+ prototype = default_buffer_prototype ()
1210
1221
indexer = BasicIndexer (selection , self .shape , self .metadata .chunk_grid )
1211
1222
sync (self ._async_array ._set_selection (indexer , value , fields = fields , prototype = prototype ))
1212
1223
@@ -1216,7 +1227,7 @@ def get_orthogonal_selection(
1216
1227
* ,
1217
1228
out : NDBuffer | None = None ,
1218
1229
fields : Fields | None = None ,
1219
- prototype : BufferPrototype = default_buffer_prototype ,
1230
+ prototype : BufferPrototype | None = None ,
1220
1231
) -> NDArrayLike :
1221
1232
"""Retrieve data by making a selection for each dimension of the array. For
1222
1233
example, if an array has 2 dimensions, allows selecting specific rows and/or
@@ -1325,6 +1336,8 @@ def get_orthogonal_selection(
1325
1336
vindex, oindex, blocks, __getitem__, __setitem__
1326
1337
1327
1338
"""
1339
+ if prototype is None :
1340
+ prototype = default_buffer_prototype ()
1328
1341
indexer = OrthogonalIndexer (selection , self .shape , self .metadata .chunk_grid )
1329
1342
return sync (
1330
1343
self ._async_array ._get_selection (
@@ -1338,7 +1351,7 @@ def set_orthogonal_selection(
1338
1351
value : npt .ArrayLike ,
1339
1352
* ,
1340
1353
fields : Fields | None = None ,
1341
- prototype : BufferPrototype = default_buffer_prototype ,
1354
+ prototype : BufferPrototype | None = None ,
1342
1355
) -> None :
1343
1356
"""Modify data via a selection for each dimension of the array.
1344
1357
@@ -1435,6 +1448,8 @@ def set_orthogonal_selection(
1435
1448
vindex, oindex, blocks, __getitem__, __setitem__
1436
1449
1437
1450
"""
1451
+ if prototype is None :
1452
+ prototype = default_buffer_prototype ()
1438
1453
indexer = OrthogonalIndexer (selection , self .shape , self .metadata .chunk_grid )
1439
1454
return sync (
1440
1455
self ._async_array ._set_selection (indexer , value , fields = fields , prototype = prototype )
@@ -1446,7 +1461,7 @@ def get_mask_selection(
1446
1461
* ,
1447
1462
out : NDBuffer | None = None ,
1448
1463
fields : Fields | None = None ,
1449
- prototype : BufferPrototype = default_buffer_prototype ,
1464
+ prototype : BufferPrototype | None = None ,
1450
1465
) -> NDArrayLike :
1451
1466
"""Retrieve a selection of individual items, by providing a Boolean array of the
1452
1467
same shape as the array against which the selection is being made, where True
@@ -1513,6 +1528,8 @@ def get_mask_selection(
1513
1528
vindex, oindex, blocks, __getitem__, __setitem__
1514
1529
"""
1515
1530
1531
+ if prototype is None :
1532
+ prototype = default_buffer_prototype ()
1516
1533
indexer = MaskIndexer (mask , self .shape , self .metadata .chunk_grid )
1517
1534
return sync (
1518
1535
self ._async_array ._get_selection (
@@ -1526,7 +1543,7 @@ def set_mask_selection(
1526
1543
value : npt .ArrayLike ,
1527
1544
* ,
1528
1545
fields : Fields | None = None ,
1529
- prototype : BufferPrototype = default_buffer_prototype ,
1546
+ prototype : BufferPrototype | None = None ,
1530
1547
) -> None :
1531
1548
"""Modify a selection of individual items, by providing a Boolean array of the
1532
1549
same shape as the array against which the selection is being made, where True
@@ -1593,6 +1610,8 @@ def set_mask_selection(
1593
1610
vindex, oindex, blocks, __getitem__, __setitem__
1594
1611
1595
1612
"""
1613
+ if prototype is None :
1614
+ prototype = default_buffer_prototype ()
1596
1615
indexer = MaskIndexer (mask , self .shape , self .metadata .chunk_grid )
1597
1616
sync (self ._async_array ._set_selection (indexer , value , fields = fields , prototype = prototype ))
1598
1617
@@ -1602,7 +1621,7 @@ def get_coordinate_selection(
1602
1621
* ,
1603
1622
out : NDBuffer | None = None ,
1604
1623
fields : Fields | None = None ,
1605
- prototype : BufferPrototype = default_buffer_prototype ,
1624
+ prototype : BufferPrototype | None = None ,
1606
1625
) -> NDArrayLike :
1607
1626
"""Retrieve a selection of individual items, by providing the indices
1608
1627
(coordinates) for each selected item.
@@ -1671,6 +1690,8 @@ def get_coordinate_selection(
1671
1690
vindex, oindex, blocks, __getitem__, __setitem__
1672
1691
1673
1692
"""
1693
+ if prototype is None :
1694
+ prototype = default_buffer_prototype ()
1674
1695
indexer = CoordinateIndexer (selection , self .shape , self .metadata .chunk_grid )
1675
1696
out_array = sync (
1676
1697
self ._async_array ._get_selection (
@@ -1689,7 +1710,7 @@ def set_coordinate_selection(
1689
1710
value : npt .ArrayLike ,
1690
1711
* ,
1691
1712
fields : Fields | None = None ,
1692
- prototype : BufferPrototype = default_buffer_prototype ,
1713
+ prototype : BufferPrototype | None = None ,
1693
1714
) -> None :
1694
1715
"""Modify a selection of individual items, by providing the indices (coordinates)
1695
1716
for each item to be modified.
@@ -1753,6 +1774,8 @@ def set_coordinate_selection(
1753
1774
vindex, oindex, blocks, __getitem__, __setitem__
1754
1775
1755
1776
"""
1777
+ if prototype is None :
1778
+ prototype = default_buffer_prototype ()
1756
1779
# setup indexer
1757
1780
indexer = CoordinateIndexer (selection , self .shape , self .metadata .chunk_grid )
1758
1781
@@ -1776,7 +1799,7 @@ def get_block_selection(
1776
1799
* ,
1777
1800
out : NDBuffer | None = None ,
1778
1801
fields : Fields | None = None ,
1779
- prototype : BufferPrototype = default_buffer_prototype ,
1802
+ prototype : BufferPrototype | None = None ,
1780
1803
) -> NDArrayLike :
1781
1804
"""Retrieve a selection of individual items, by providing the indices
1782
1805
(coordinates) for each selected item.
@@ -1859,6 +1882,8 @@ def get_block_selection(
1859
1882
vindex, oindex, blocks, __getitem__, __setitem__
1860
1883
1861
1884
"""
1885
+ if prototype is None :
1886
+ prototype = default_buffer_prototype ()
1862
1887
indexer = BlockIndexer (selection , self .shape , self .metadata .chunk_grid )
1863
1888
return sync (
1864
1889
self ._async_array ._get_selection (
@@ -1872,7 +1897,7 @@ def set_block_selection(
1872
1897
value : npt .ArrayLike ,
1873
1898
* ,
1874
1899
fields : Fields | None = None ,
1875
- prototype : BufferPrototype = default_buffer_prototype ,
1900
+ prototype : BufferPrototype | None = None ,
1876
1901
) -> None :
1877
1902
"""Modify a selection of individual blocks, by providing the chunk indices
1878
1903
(coordinates) for each block to be modified.
@@ -1950,6 +1975,8 @@ def set_block_selection(
1950
1975
vindex, oindex, blocks, __getitem__, __setitem__
1951
1976
1952
1977
"""
1978
+ if prototype is None :
1979
+ prototype = default_buffer_prototype ()
1953
1980
indexer = BlockIndexer (selection , self .shape , self .metadata .chunk_grid )
1954
1981
sync (self ._async_array ._set_selection (indexer , value , fields = fields , prototype = prototype ))
1955
1982
0 commit comments