@@ -294,6 +294,36 @@ def flatten(
294294 return metadata
295295
296296
297+ class ArraysProxy :
298+ """
299+ Proxy for arrays in a group.
300+
301+ Used to implement the `Group.arrays` property
302+ """
303+
304+ def __init__ (self , group : Group ) -> None :
305+ self ._group = group
306+
307+ def __getitem__ (self , key : str ) -> Array :
308+ obj = self ._group [key ]
309+ if isinstance (obj , Array ):
310+ return obj
311+ raise KeyError (key )
312+
313+ def __setitem__ (self , key : str , value : npt .ArrayLike ) -> None :
314+ """
315+ Set an array in the group.
316+ """
317+ self ._group ._sync (self ._group ._async_group .set_array (key , value ))
318+
319+ def __iter__ (self ) -> Generator [tuple [str , Array ], None ]:
320+ for name , async_array in self ._group ._sync_iter (self ._group ._async_group .arrays ()):
321+ yield name , Array (async_array )
322+
323+ def __call__ (self ) -> Generator [tuple [str , Array ], None ]:
324+ return iter (self )
325+
326+
297327@dataclass (frozen = True )
298328class GroupMetadata (Metadata ):
299329 attributes : dict [str , Any ] = field (default_factory = dict )
@@ -596,7 +626,16 @@ def from_dict(
596626 store_path = store_path ,
597627 )
598628
599- async def setitem (self , key : str , value : Any ) -> None :
629+ async def set_array (self , key : str , value : Any ) -> None :
630+ """fastpath for creating a new array
631+
632+ Parameters
633+ ----------
634+ key : str
635+ Array name
636+ value : array-like
637+ Array data
638+ """
600639 path = self .store_path / key
601640 await async_api .save_array (
602641 store = path , arr = value , zarr_format = self .metadata .zarr_format , exists_ok = True
@@ -1374,9 +1413,14 @@ def __iter__(self) -> Iterator[str]:
13741413 def __len__ (self ) -> int :
13751414 return self .nmembers ()
13761415
1416+ @deprecated ("Use Group.arrays setter instead." )
13771417 def __setitem__ (self , key : str , value : Any ) -> None :
1378- """Create a new array"""
1379- self ._sync (self ._async_group .setitem (key , value ))
1418+ """Create a new array
1419+
1420+ .. deprecated:: 3.0.0
1421+ Use Group.arrays.setter instead.
1422+ """
1423+ self ._sync (self ._async_group .set_array (key , value ))
13801424
13811425 def __repr__ (self ) -> str :
13821426 return f"<Group { self .store_path } >"
@@ -1473,9 +1517,9 @@ def group_values(self) -> Generator[Group, None]:
14731517 for _ , group in self .groups ():
14741518 yield group
14751519
1476- def arrays ( self ) -> Generator [ tuple [ str , Array ], None ]:
1477- for name , async_array in self . _sync_iter ( self . _async_group . arrays ()) :
1478- yield name , Array ( async_array )
1520+ @ property
1521+ def arrays (self ) -> ArraysProxy :
1522+ return ArraysProxy ( self )
14791523
14801524 def array_keys (self ) -> Generator [str , None ]:
14811525 for name , _ in self .arrays ():
0 commit comments