Skip to content

Commit

Permalink
rollback deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamman committed Oct 23, 2024
1 parent 4ab2698 commit 056398e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 48 deletions.
6 changes: 3 additions & 3 deletions src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ async def load(

obj = await open(store=store, path=path, zarr_format=zarr_format)
if isinstance(obj, AsyncArray):
return await obj.getitem(slice(None))
return await obj.getitem(...)
else:
raise NotImplementedError("loading groups not yet supported")

Expand Down Expand Up @@ -408,7 +408,7 @@ async def save_array(
chunks=chunks,
**kwargs,
)
await new.setitem(slice(None), arr)
await new.setitem(..., arr)


async def save_group(
Expand Down Expand Up @@ -520,7 +520,7 @@ async def array(
z = await create(**kwargs)

# fill with data
await z.setitem(slice(None), data)
await z.setitem(..., data)

return z

Expand Down
50 changes: 10 additions & 40 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,36 +295,6 @@ def flatten(
return metadata


class ArraysProxy:
"""
Proxy for arrays in a group.
Used to implement the `Group.arrays` property
"""

def __init__(self, group: Group) -> None:
self._group = group

def __getitem__(self, key: str) -> Array:
obj = self._group[key]
if isinstance(obj, Array):
return obj
raise KeyError(key)

def __setitem__(self, key: str, value: npt.ArrayLike) -> None:
"""
Set an array in the group.
"""
self._group._sync(self._group._async_group.set_array(key, value))

def __iter__(self) -> Generator[tuple[str, Array], None]:
for name, async_array in self._group._sync_iter(self._group._async_group.arrays()):
yield name, Array(async_array)

def __call__(self) -> Generator[tuple[str, Array], None]:
return iter(self)


@dataclass(frozen=True)
class GroupMetadata(Metadata):
attributes: dict[str, Any] = field(default_factory=dict)
Expand Down Expand Up @@ -630,8 +600,10 @@ def from_dict(
store_path=store_path,
)

async def set_array(self, key: str, value: Any) -> None:
"""fastpath for creating a new array
async def setitem(self, key: str, value: Any) -> None:
"""Fastpath for creating a new array
New arrays will be created with default array settings for the array type.
Parameters
----------
Expand Down Expand Up @@ -1438,14 +1410,12 @@ def __iter__(self) -> Iterator[str]:
def __len__(self) -> int:
return self.nmembers()

@deprecated("Use Group.arrays setter instead.")
def __setitem__(self, key: str, value: Any) -> None:
"""Create a new array
"""Fastpath for creating a new array.
.. deprecated:: 3.0.0
Use Group.arrays.setter instead.
New arrays will be created using default settings for the array type.
"""
self._sync(self._async_group.set_array(key, value))
self._sync(self._async_group.setitem(key, value))

def __repr__(self) -> str:
return f"<Group {self.store_path}>"
Expand Down Expand Up @@ -1542,9 +1512,9 @@ def group_values(self) -> Generator[Group, None]:
for _, group in self.groups():
yield group

@property
def arrays(self) -> ArraysProxy:
return ArraysProxy(self)
def arrays(self) -> Generator[tuple[str, Array], None]:
for name, async_array in self._sync_iter(self._async_group.arrays()):
yield name, Array(async_array)

def array_keys(self) -> Generator[str, None]:
for name, _ in self.arrays():
Expand Down
10 changes: 5 additions & 5 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,12 @@ def test_group_len(store: Store, zarr_format: ZarrFormat) -> None:

def test_group_setitem(store: Store, zarr_format: ZarrFormat) -> None:
"""
Test the `Group.__setitem__` method.
Test the `Group.__setitem__` method. (Deprecated)
"""
group = Group.from_store(store, zarr_format=zarr_format)
arr = np.ones((2, 4))
with pytest.warns(DeprecationWarning):
group["key"] = arr
group["key"] = arr
assert list(group.array_keys()) == ["key"]
assert group["key"].shape == (2, 4)
np.testing.assert_array_equal(group["key"][:], arr)

Expand All @@ -442,8 +442,8 @@ def test_group_setitem(store: Store, zarr_format: ZarrFormat) -> None:

# overwrite with another array
arr = np.zeros((3, 5))
with pytest.warns(DeprecationWarning):
group[key] = arr
group[key] = arr
assert key in list(group.array_keys())
assert group[key].shape == (3, 5)
np.testing.assert_array_equal(group[key], arr)

Expand Down

0 comments on commit 056398e

Please sign in to comment.