Skip to content

Commit 3649b9b

Browse files
authored
open_array(): adding the meta_array argument (#1396)
* open_array(): adding the meta_array argument * updated release.txt * doc: fixed versionadded
1 parent cc16d8c commit 3649b9b

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

docs/release.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Enhancements
2828
* Getitems supports ``meta_array``.
2929
By :user:`Mads R. B. Kristensen <madsbk>` :issue:`1131`.
3030

31+
* ``open_array()`` now takes the ``meta_array`` argument.
32+
By :user:`Mads R. B. Kristensen <madsbk>` :issue:`1396`.
33+
3134
Maintenance
3235
~~~~~~~~~~~
3336

@@ -176,7 +179,7 @@ Bug fixes
176179
Documentation
177180
~~~~~~~~~~~~~
178181

179-
* Fix minor indexing errors in tutorial and specification examples of documentation.
182+
* Fix minor indexing errors in tutorial and specification examples of documentation.
180183
By :user:`Kola Babalola <sprynt001>` :issue:`1277`.
181184

182185
* Add `requirements_rtfd.txt` in `contributing.rst`.

zarr/creation.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ def open_array(
424424
*,
425425
zarr_version=None,
426426
dimension_separator=None,
427+
meta_array=None,
427428
**kwargs
428429
):
429430
"""Open an array using file-mode-like semantics.
@@ -498,6 +499,11 @@ def open_array(
498499
('/') format. If None, the appropriate value will be read from `store`
499500
when present. Otherwise, defaults to '.' when ``zarr_version == 2``
500501
and `/` otherwise.
502+
meta_array : array-like, optional
503+
An array instance to use for determining arrays to create and return
504+
to users. Use `numpy.empty(())` by default.
505+
506+
.. versionadded:: 2.15
501507
502508
Returns
503509
-------
@@ -607,7 +613,7 @@ def open_array(
607613
# instantiate array
608614
z = Array(store, read_only=read_only, synchronizer=synchronizer,
609615
cache_metadata=cache_metadata, cache_attrs=cache_attrs, path=path,
610-
chunk_store=chunk_store, write_empty_chunks=write_empty_chunks)
616+
chunk_store=chunk_store, write_empty_chunks=write_empty_chunks, meta_array=meta_array)
611617

612618
return z
613619

zarr/tests/test_meta_array.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import zarr.codecs
1010
from zarr.core import Array
11-
from zarr.creation import array, empty, full, ones, zeros
11+
from zarr.creation import array, empty, full, ones, open_array, zeros
1212
from zarr.hierarchy import open_group
1313
from zarr.storage import DirectoryStore, MemoryStore, Store, ZipStore
1414

@@ -148,6 +148,23 @@ def test_array(tmp_path, module, compressor, store_type):
148148
assert z.dtype == z2.dtype
149149
xp.testing.assert_array_equal(z[:], z2[:])
150150

151+
store = init_store(tmp_path / "open_array", store_type)
152+
a = xp.arange(100)
153+
z = open_array(
154+
store,
155+
shape=a.shape,
156+
dtype=a.dtype,
157+
chunks=10,
158+
compressor=compressor,
159+
meta_array=xp.empty(())
160+
)
161+
z[:] = a
162+
assert a.shape == z.shape
163+
assert a.dtype == z.dtype
164+
assert isinstance(a, type(z[:]))
165+
assert isinstance(z.meta_array, type(xp.empty(())))
166+
xp.testing.assert_array_equal(a, z[:])
167+
151168

152169
@pytest.mark.parametrize("module, compressor", param_module_and_compressor)
153170
def test_empty(module, compressor):

0 commit comments

Comments
 (0)