Skip to content

Inconsistency between return type of Group.attrs and AsyncGroup.attrs #2214

Open

Description

@TomAugspurger

Zarr version

v3

Numcodecs version

na

Python Version

na

Operating System

na

Installation

na

Description

There's an inconsistency between Group.attrs and AsyncGroup.attrs. Group.attrs returns an Attributes object while AsyncGroup.attrs returns an Attributes object. Just wanted to confirm that this is deliberate.

I'm planning to add an asdict() method to Attributes for v2 compatibility.

Steps to reproduce

In [13]: g = zarr.open_group(store={}, mode="w")

In [14]: g.attrs
Out[14]: <zarr.core.attributes.Attributes at 0x10bd902e0>

In [15]: g._async_group.attrs
Out[15]: {}

Additional output

No response

Activity

  1. added
    bug
    on Sep 19, 2024
  2. jhamman commented on Sep 24, 2024

    @jhamman
    Member

    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)
  3. dstansby commented on Dec 30, 2024

    @dstansby
    Contributor

    Is this something that wants fixing before v3, or something that is going to be intentionally left as is?

  4. added this to the 3.0.0 milestone on Dec 30, 2024
  5. jhamman commented on Jan 8, 2025

    @jhamman
    Member

    We can fix this after 3.0.0.

  6. modified the milestones: 3.0.0, After 3.0.0 on Jan 8, 2025
  7. removed this from the After 3.0.0 milestone on May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions