Open TomAugspurger opened 1 month ago
Good catch @TomAugspurger. I had forgotten to come back to this.
The dict-like attrs property on the sync Array is not really possible for the AsyncArray
. My conclusion is that we probably need something like an AsyncAttributes
class:
class AsyncAttributes:
def __init__(self, obj: AsyncArray | AsyncGroup):
self._obj = obj
async def getitem(self, key: str) -> JSON:
return self._obj.metadata.attributes[key]
async def setitem(self, key: str, value: JSON) -> None:
new_attrs = dict(self._obj.metadata.attributes)
new_attrs[key] = value
self._obj = await self._obj.update_attributes(new_attrs)
def delitem(self, key: str) -> None:
new_attrs = dict(self._obj.metadata.attributes)
del new_attrs[key]
self._obj = await self._obj.update_attributes(new_attrs)
def __iter__(self) -> Iterator[str]:
return iter(self._obj.metadata.attributes)
def __len__(self) -> int:
return len(self._obj.metadata.attributes)
async def put(self, d: dict[str, JSON]) -> None:
self._obj = await self._obj.update_attributes(d)
Zarr version
v3
Numcodecs version
na
Python Version
na
Operating System
na
Installation
na
Description
There's an inconsistency between
Group.attrs
andAsyncGroup.attrs
. Group.attrs returns anAttributes
object whileAsyncGroup.attrs
returns anAttributes
object. Just wanted to confirm that this is deliberate.I'm planning to add an
asdict()
method toAttributes
for v2 compatibility.Steps to reproduce
Additional output
No response