Skip to content

MemoryStore.list_dir incorrectly includes non-immediate children #2116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TomAugspurger opened this issue Aug 25, 2024 · 0 comments · Fixed by #2117
Closed

MemoryStore.list_dir incorrectly includes non-immediate children #2116

TomAugspurger opened this issue Aug 25, 2024 · 0 comments · Fixed by #2117
Labels
bug Potential issues with the zarr-python library

Comments

@TomAugspurger
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Potential issues with the zarr-python library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant