Skip to content

abstracting over arrays, groups, zarr versions #113

@d-v-b

Description

@d-v-b

Bringing this up because I'm writing something like this in a separate project:

When writing functions that work equally well for V2 Arrays or V3 arrays (and the same for groups), it would be useful to have a array-like type that doesn't depend on the V2 / V3 Array classes, but works for both. These could be very simple runtime checkable protocols:

from typing import Protocol, runtime_checkable, Generic

@runtime_checkable
class ProtoNode(Protocol):
    attributes: Mapping[str, Any]

@runtime_checkable
class ProtoArray(Protocol):
    shape: tuple[int, ...]

TMembers = TypeVar('TMembers', bound=Mapping[str, object])

@runtime_checkable
class ProtoGroup(Protocol, Generic[TMembers]):
    members: TMembers

This is just a sketch -- these can be made fancier of course, and the names are bad, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions