@@ -19,7 +19,8 @@ def create(shape, chunks=True, dtype=None, compressor='default',
19
19
fill_value = 0 , order = 'C' , store = None , synchronizer = None ,
20
20
overwrite = False , path = None , chunk_store = None , filters = None ,
21
21
cache_metadata = True , cache_attrs = True , read_only = False ,
22
- object_codec = None , dimension_separator = None , write_empty_chunks = True , ** kwargs ):
22
+ object_codec = None , dimension_separator = None , write_empty_chunks = True , * ,
23
+ zarr_version = None , ** kwargs ):
23
24
"""Create an array.
24
25
25
26
Parameters
@@ -77,7 +78,10 @@ def create(shape, chunks=True, dtype=None, compressor='default',
77
78
that chunk's key is deleted. This setting enables sparser storage,
78
79
as only chunks with non-fill-value data are stored, at the expense
79
80
of overhead associated with checking the data of each chunk.
80
-
81
+ zarr_version : {None, 2, 3}, optional
82
+ The zarr protocol version of the created array. If None, it will be
83
+ inferred from ``store`` or ``chunk_store`` if they are provided,
84
+ otherwise defaulting to 2.
81
85
82
86
Returns
83
87
-------
@@ -122,9 +126,12 @@ def create(shape, chunks=True, dtype=None, compressor='default',
122
126
<zarr.core.Array (10000, 10000) float64>
123
127
124
128
"""
129
+ if zarr_version is None and store is None :
130
+ zarr_version = getattr (chunk_store , '_store_version' , 2 )
125
131
126
132
# handle polymorphic store arg
127
- store = normalize_store_arg (store )
133
+ store = normalize_store_arg (store , zarr_version = zarr_version )
134
+ zarr_version = getattr (store , '_store_version' , 2 )
128
135
129
136
# API compatibility with h5py
130
137
compressor , fill_value = _kwargs_compat (compressor , fill_value , kwargs )
@@ -141,6 +148,9 @@ def create(shape, chunks=True, dtype=None, compressor='default',
141
148
f"{ store_separator } " )
142
149
dimension_separator = normalize_dimension_separator (dimension_separator )
143
150
151
+ if zarr_version > 2 and path is None :
152
+ raise ValueError ("path must be supplied to initialize a zarr v3 array" )
153
+
144
154
# initialize array metadata
145
155
init_array (store , shape = shape , chunks = chunks , dtype = dtype , compressor = compressor ,
146
156
fill_value = fill_value , order = order , overwrite = overwrite , path = path ,
@@ -388,6 +398,8 @@ def open_array(
388
398
storage_options = None ,
389
399
partial_decompress = False ,
390
400
write_empty_chunks = True ,
401
+ * ,
402
+ zarr_version = None ,
391
403
** kwargs
392
404
):
393
405
"""Open an array using file-mode-like semantics.
@@ -450,6 +462,10 @@ def open_array(
450
462
that chunk's key is deleted. This setting enables sparser storage,
451
463
as only chunks with non-fill-value data are stored, at the expense
452
464
of overhead associated with checking the data of each chunk.
465
+ zarr_version : {None, 2, 3}, optional
466
+ The zarr protocol version of the array to be opened. If None, it will
467
+ be inferred from ``store`` or ``chunk_store`` if they are provided,
468
+ otherwise defaulting to 2.
453
469
454
470
Returns
455
471
-------
@@ -484,12 +500,21 @@ def open_array(
484
500
# w- or x : create, fail if exists
485
501
# a : read/write if exists, create otherwise (default)
486
502
503
+ if zarr_version is None and store is None :
504
+ zarr_version = getattr (chunk_store , '_store_version' , 2 )
505
+
487
506
# handle polymorphic store arg
488
507
clobber = (mode == 'w' )
489
- store = normalize_store_arg (store , clobber = clobber , storage_options = storage_options , mode = mode )
508
+ store = normalize_store_arg (store , clobber = clobber , storage_options = storage_options ,
509
+ mode = mode , zarr_version = zarr_version )
510
+ zarr_version = getattr (store , '_store_version' , 2 )
490
511
if chunk_store is not None :
491
512
chunk_store = normalize_store_arg (chunk_store , clobber = clobber ,
492
- storage_options = storage_options )
513
+ storage_options = storage_options ,
514
+ zarr_version = zarr_version )
515
+
516
+ if zarr_version == 3 and path is None :
517
+ path = 'array' # TODO: raise ValueError instead?
493
518
path = normalize_storage_path (path )
494
519
495
520
# API compatibility with h5py
@@ -559,6 +584,7 @@ def _like_args(a, kwargs):
559
584
kwargs .setdefault ('compressor' , a .compressor )
560
585
kwargs .setdefault ('order' , a .order )
561
586
kwargs .setdefault ('filters' , a .filters )
587
+ kwargs .setdefault ('zarr_version' , a ._version )
562
588
else :
563
589
kwargs .setdefault ('compressor' , 'default' )
564
590
kwargs .setdefault ('order' , 'C' )
0 commit comments