@@ -1273,6 +1273,26 @@ async def update_attributes(self, new_attributes: dict[str, Any]) -> AsyncGroup:
12731273
12741274 return self
12751275
1276+ async def refresh_attributes (self ) -> AsyncGroup :
1277+ """Reload the attributes of this group from the store.
1278+
1279+ Returns
1280+ -------
1281+ self : AsyncGroup
1282+ The group updated with the newest attributes from storage.
1283+ """
1284+
1285+ reparsed_metadata = await _read_group_metadata (
1286+ store = self .store_path .store ,
1287+ path = self .store_path .path ,
1288+ zarr_format = self .metadata .zarr_format ,
1289+ )
1290+
1291+ self .metadata .attributes .clear ()
1292+ self .metadata .attributes .update (reparsed_metadata .attributes )
1293+
1294+ return self
1295+
12761296 def __repr__ (self ) -> str :
12771297 return f"<AsyncGroup { self .store_path } >"
12781298
@@ -1774,6 +1794,7 @@ class Group(SyncMixin):
17741794 """
17751795
17761796 _async_group : AsyncGroup
1797+ cache_attrs : bool | None = field (default = None )
17771798
17781799 @classmethod
17791800 def from_store (
@@ -1783,6 +1804,7 @@ def from_store(
17831804 attributes : dict [str , Any ] | None = None ,
17841805 zarr_format : ZarrFormat = 3 ,
17851806 overwrite : bool = False ,
1807+ cache_attrs : bool | None = None ,
17861808 ) -> Group :
17871809 """Instantiate a group from an initialized store.
17881810
@@ -1816,13 +1838,14 @@ def from_store(
18161838 ),
18171839 )
18181840
1819- return cls (obj )
1841+ return cls (obj , cache_attrs = cache_attrs )
18201842
18211843 @classmethod
18221844 def open (
18231845 cls ,
18241846 store : StoreLike ,
18251847 zarr_format : ZarrFormat | None = 3 ,
1848+ cache_attrs : bool | None = None ,
18261849 ) -> Group :
18271850 """Open a group from an initialized store.
18281851
@@ -1839,7 +1862,7 @@ def open(
18391862 Group instantiated from the store.
18401863 """
18411864 obj = sync (AsyncGroup .open (store , zarr_format = zarr_format ))
1842- return cls (obj )
1865+ return cls (obj , cache_attrs = cache_attrs )
18431866
18441867 def __getitem__ (self , path : str ) -> Array | Group :
18451868 """Obtain a group member.
@@ -2024,6 +2047,8 @@ def basename(self) -> str:
20242047 @property
20252048 def attrs (self ) -> Attributes :
20262049 """Attributes of this Group"""
2050+ if self .cache_attrs is False :
2051+ self .refresh_attributes ()
20272052 return Attributes (self )
20282053
20292054 @property
@@ -2090,6 +2115,11 @@ def update_attributes(self, new_attributes: dict[str, Any]) -> Group:
20902115 self ._sync (self ._async_group .update_attributes (new_attributes ))
20912116 return self
20922117
2118+ def refresh_attributes (self ) -> Group :
2119+ """Reload the attributes of this Group from the store."""
2120+ self ._sync (self ._async_group .refresh_attributes ())
2121+ return self
2122+
20932123 def nmembers (self , max_depth : int | None = 0 ) -> int :
20942124 """Count the number of members in this group.
20952125
0 commit comments