Skip to content

MemoryStore.list_dir incorrectly includes non-immediate children #2116

Description

@TomAugspurger

Zarr version

v3

Numcodecs version

n/a

Python Version

n/a

Operating System

n/a

Installation

n/a

Description

MemoryStore.list_dir incorrectly includes an entry for each nested child of a group. This differs from the behavior of LocalStore.list_dir

Steps to reproduce

This program sets up a store with some nested objects:

import zarr.store
import zarr.core.buffer


async def main():
    local = zarr.store.LocalStore("/tmp/foo", mode="w")
    mem = zarr.store.MemoryStore({}, mode="w")

    paths = [
        'root/a0/zarr.json',
        'root/g0/zarr.json',
        'root/g0/a1/zarr.json',
        'root/g0/g1/zarr.json',
        'root/g0/g1/a2/zarr.json',
        'root/g0/g1/g2/zarr.json',
    ]

    for store in [local, mem]:
        for path in paths:
            await store.set(path, zarr.core.buffer.Buffer.from_bytes(b""))

        print(type(store).__name__)
        print([x async for x in store.list_dir("root")])
        print("-" * 80)


if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

Here's the output:

LocalStore
['g0', 'a0']
--------------------------------------------------------------------------------
MemoryStore
['a0', 'g0', 'g0', 'g0', 'g0', 'g0']
--------------------------------------------------------------------------------

The g0 group is repeated once per child.

Additional output

I'll have a PR shortly.

Activity

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

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions