Skip to content

Commit 1ba9ad5

Browse files
committed
Deprecate group()
1 parent 3d0e40e commit 1ba9ad5

File tree

10 files changed

+35
-24
lines changed

10 files changed

+35
-24
lines changed

src/zarr/api/asynchronous.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ async def array(
622622
return z
623623

624624

625+
@deprecated("Use open_group() or create_group() instead")
625626
async def group(
626627
*, # Note: this is a change from v2
627628
store: StoreLike | None = None,

src/zarr/api/synchronous.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ def array(data: npt.ArrayLike | Array, **kwargs: Any) -> Array:
384384
return Array(sync(async_api.array(data=data, **kwargs)))
385385

386386

387+
@deprecated("Use open_group() or create_group() instead")
387388
def group(
388389
store: StoreLike | None = None,
389390
*,

tests/test_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_open_normalized_path(
159159
) -> None:
160160
node: Group | Array
161161
if node_type == "group":
162-
node = group(store=memory_store, path=path)
162+
node = create_group(store=memory_store, path=path)
163163
elif node_type == "array":
164164
node = create(store=memory_store, path=path, shape=(2,))
165165

@@ -514,7 +514,7 @@ def test_load_local(tmp_path: Path, path: str | None, load_read_only: bool) -> N
514514

515515
def test_tree() -> None:
516516
pytest.importorskip("rich")
517-
g1 = zarr.group()
517+
g1 = zarr.create_group(store={})
518518
g1.create_group("foo")
519519
g3 = g1.create_group("bar")
520520
g3.create_group("baz")
@@ -1379,6 +1379,7 @@ def test_no_overwrite_array(tmp_path: Path, create_function: Callable, overwrite
13791379
assert existing_fpath.exists()
13801380

13811381

1382+
@pytest.mark.filterwarnings(r"ignore:Use open_group\(\) or create_group\(\) instead")
13821383
@pytest.mark.parametrize("create_function", [create_group, group])
13831384
@pytest.mark.parametrize("overwrite", [True, False])
13841385
def test_no_overwrite_group(tmp_path: Path, create_function: Callable, overwrite: bool) -> None: # type:ignore[type-arg]

tests/test_api/test_asynchronous.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import json
4+
import re
45
from dataclasses import dataclass
56
from typing import TYPE_CHECKING
67

@@ -115,8 +116,14 @@ async def test_open_group_new_path(tmp_path: Path) -> None:
115116
"""
116117
# tmp_path exists, but tmp_path / "test.zarr" will not, which is important for this test
117118
path = tmp_path / "test.zarr"
118-
grp = await group(store=path, attributes={"a": 1})
119+
with pytest.warns(
120+
DeprecationWarning, match=re.escape("Use open_group() or create_group() instead")
121+
):
122+
grp = await group(store=path, attributes={"a": 1})
119123
assert isinstance(grp, AsyncGroup)
120124
# Calling group on an existing store should just open that store
121-
grp = await group(store=path)
125+
with pytest.warns(
126+
DeprecationWarning, match=re.escape("Use open_group() or create_group() instead")
127+
):
128+
grp = await group(store=path)
122129
assert grp.attrs == {"a": 1}

tests/test_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ def test_roundtrip_numcodecs() -> None:
17421742
]
17431743

17441744
# Create the array with the correct codecs
1745-
root = zarr.group(store)
1745+
root = zarr.create_group(store)
17461746
warn_msg = "Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations."
17471747
with pytest.warns(UserWarning, match=warn_msg):
17481748
root.create_array(

tests/test_group.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ def test_from_dict_extra_fields(self):
15841584
class TestInfo:
15851585
def test_info(self):
15861586
store = zarr.storage.MemoryStore()
1587-
A = zarr.group(store=store, path="A")
1587+
A = zarr.create_group(store=store, path="A")
15881588
B = A.create_group(name="B")
15891589

15901590
B.create_array(name="x", shape=(1,), dtype="uint8")
@@ -1624,7 +1624,7 @@ def test_update_attrs() -> None:
16241624
@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"])
16251625
def test_delitem_removes_children(store: Store, zarr_format: ZarrFormat) -> None:
16261626
# https://github.com/zarr-developers/zarr-python/issues/2191
1627-
g1 = zarr.group(store=store, zarr_format=zarr_format)
1627+
g1 = zarr.create_group(store=store, zarr_format=zarr_format)
16281628
g1.create_group("0")
16291629
g1.create_group("0/0")
16301630
arr = g1.create_array("0/0/0", shape=(1,), dtype="uint8")
@@ -2150,7 +2150,7 @@ def test_group_members_performance(store: Store) -> None:
21502150
get_latency = 0.1
21512151

21522152
# use the input store to create some groups
2153-
group_create = zarr.group(store=store)
2153+
group_create = zarr.create_group(store=store)
21542154
num_groups = 10
21552155

21562156
# Create some groups
@@ -2159,7 +2159,7 @@ def test_group_members_performance(store: Store) -> None:
21592159

21602160
latency_store = LatencyStore(store, get_latency=get_latency)
21612161
# create a group with some latency on get operations
2162-
group_read = zarr.group(store=latency_store)
2162+
group_read = zarr.open_group(store=latency_store)
21632163

21642164
# check how long it takes to iterate over the groups
21652165
# if .members is sensitive to IO latency,
@@ -2181,7 +2181,7 @@ def test_group_members_concurrency_limit(store: MemoryStore) -> None:
21812181
get_latency = 0.02
21822182

21832183
# use the input store to create some groups
2184-
group_create = zarr.group(store=store)
2184+
group_create = zarr.create_group(store=store)
21852185
num_groups = 10
21862186

21872187
# Create some groups
@@ -2190,7 +2190,7 @@ def test_group_members_concurrency_limit(store: MemoryStore) -> None:
21902190

21912191
latency_store = LatencyStore(store, get_latency=get_latency)
21922192
# create a group with some latency on get operations
2193-
group_read = zarr.group(store=latency_store)
2193+
group_read = zarr.open_group(store=latency_store)
21942194

21952195
# check how long it takes to iterate over the groups
21962196
# if .members is sensitive to IO latency,

tests/test_metadata/test_consolidated.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
from zarr import AsyncGroup
1414
from zarr.api.asynchronous import (
1515
consolidate_metadata,
16-
group,
16+
create_group,
1717
open,
1818
open_consolidated,
19+
open_group,
1920
)
2021
from zarr.core.buffer import cpu, default_buffer_prototype
2122
from zarr.core.dtype import parse_dtype
@@ -32,7 +33,7 @@
3233

3334
@pytest.fixture
3435
async def memory_store_with_hierarchy(memory_store: Store) -> Store:
35-
g = await group(store=memory_store, attributes={"foo": "bar"})
36+
g = await create_group(store=memory_store, attributes={"foo": "bar"})
3637
dtype = "uint8"
3738
await g.create_array(name="air", shape=(1, 2, 3), dtype=dtype)
3839
await g.create_array(name="lat", shape=(1,), dtype=dtype)
@@ -212,7 +213,7 @@ async def test_consolidated(self, memory_store_with_hierarchy: Store) -> None:
212213
]
213214

214215
def test_consolidated_sync(self, memory_store: Store) -> None:
215-
g = zarr.api.synchronous.group(store=memory_store, attributes={"foo": "bar"})
216+
g = zarr.api.synchronous.create_group(store=memory_store, attributes={"foo": "bar"})
216217
dtype = "uint8"
217218
g.create_array(name="air", shape=(1, 2, 3), dtype=dtype)
218219
g.create_array(name="lat", shape=(1,), dtype=dtype)
@@ -300,7 +301,7 @@ def test_consolidated_sync(self, memory_store: Store) -> None:
300301
assert group4.metadata == expected
301302

302303
async def test_not_writable_raises(self, memory_store: zarr.storage.MemoryStore) -> None:
303-
await group(store=memory_store, attributes={"foo": "bar"})
304+
await create_group(store=memory_store, attributes={"foo": "bar"})
304305
read_store = zarr.storage.MemoryStore(store_dict=memory_store._store_dict, read_only=True)
305306
with pytest.raises(ValueError, match="does not support writing"):
306307
await consolidate_metadata(read_store)
@@ -485,7 +486,7 @@ async def test_to_dict_order(
485486
self, memory_store: zarr.storage.MemoryStore, zarr_format: ZarrFormat
486487
) -> None:
487488
with zarr.config.set(default_zarr_format=zarr_format):
488-
g = await group(store=memory_store)
489+
g = await create_group(store=memory_store)
489490

490491
# Create groups in non-lexicographix order
491492
dtype = "float32"
@@ -602,7 +603,7 @@ async def test_use_consolidated_false(
602603
self, memory_store: zarr.storage.MemoryStore, zarr_format: ZarrFormat
603604
) -> None:
604605
with zarr.config.set(default_zarr_format=zarr_format):
605-
g = await group(store=memory_store, attributes={"foo": "bar"})
606+
g = await create_group(store=memory_store, attributes={"foo": "bar"})
606607
await g.create_group(name="a")
607608

608609
# test a stale read
@@ -648,7 +649,7 @@ async def test_stale_child_metadata_ignored(
648649
# https://github.com/zarr-developers/zarr-python/issues/2921
649650
# When consolidating metadata, we should ignore any (possibly stale) metadata
650651
# from previous consolidations, *including at child nodes*.
651-
root = await zarr.api.asynchronous.group(store=memory_store, zarr_format=3)
652+
root = await zarr.api.asynchronous.create_group(store=memory_store, zarr_format=3)
652653
await root.create_group("foo")
653654
await zarr.api.asynchronous.consolidate_metadata(memory_store, path="foo")
654655
await root.create_group("foo/bar/spam")
@@ -712,7 +713,7 @@ async def test_absolute_path_for_subgroup(self, memory_store: zarr.storage.Memor
712713
async def test_consolidated_metadata_encodes_special_chars(
713714
memory_store: Store, zarr_format: ZarrFormat, fill_value: float
714715
) -> None:
715-
root = await group(store=memory_store, zarr_format=zarr_format)
716+
root = await create_group(store=memory_store, zarr_format=zarr_format)
716717
_time = await root.create_array("time", shape=(12,), dtype=np.float64, fill_value=fill_value)
717718
if zarr_format == 3:
718719
with pytest.warns(
@@ -723,7 +724,7 @@ async def test_consolidated_metadata_encodes_special_chars(
723724
else:
724725
await zarr.api.asynchronous.consolidate_metadata(memory_store)
725726

726-
root = await group(store=memory_store, zarr_format=zarr_format)
727+
root = await open_group(store=memory_store, zarr_format=zarr_format)
727728
root_buffer = root.metadata.to_buffer_dict(default_buffer_prototype())
728729

729730
if zarr_format == 2:

tests/test_store/test_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_creates_new_directory(self, tmp_path: pathlib.Path) -> None:
5151
assert not target.exists()
5252

5353
store = self.store_cls(root=target)
54-
zarr.group(store=store)
54+
zarr.create_group(store=store)
5555

5656
def test_invalid_root_raises(self) -> None:
5757
"""

tests/test_tree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def test_tree(root_name: Any) -> None:
1414
os.environ["OVERRIDE_COLOR_SYSTEM"] = "truecolor"
1515

16-
g = zarr.group(path=root_name)
16+
g = zarr.create_group(store={}, path=root_name)
1717
A = g.create_group("A")
1818
B = g.create_group("B")
1919
C = B.create_group("C")
@@ -57,6 +57,6 @@ def test_tree(root_name: Any) -> None:
5757

5858

5959
def test_expand_not_implemented() -> None:
60-
g = zarr.group()
60+
g = zarr.create_group(store={})
6161
with pytest.raises(NotImplementedError):
6262
g.tree(expand=True)

tests/test_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def test_v2_encode_decode(
7575
dtype: str, expected_dtype: str, fill_value: bytes, fill_value_json: str
7676
) -> None:
7777
store = zarr.storage.MemoryStore()
78-
g = zarr.group(store=store, zarr_format=2)
78+
g = zarr.create_group(store=store, zarr_format=2)
7979
g.create_array(
8080
name="foo", shape=(3,), chunks=(3,), dtype=dtype, fill_value=fill_value, compressor=None
8181
)

0 commit comments

Comments
 (0)