Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Prevent creation of arrays/groups under a parent array#3407

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
d-v-b merged 12 commits intozarr-developers:mainfromK-Meech:km/child-of-array
Sep 18, 2025

Conversation

@K-Meech
Copy link
Contributor

@K-MeechK-Meech commentedAug 26, 2025
edited
Loading

Closes#2582

Prevents creation of arrays / groups under a parent array with.create_array and.create_group e.g.root.create_array(name='foo/bar') (wherefoo is an existing array)

This required changes to the_save_metadata function of bothzarr/core/array.py andzarr/core/group.py. As both used pretty much identical code, I refactored this into a common function inzarr/core/metadata/io.py (along with the_build_parents function both relied upon). Happy to move this elsewhere - if there is a more suitable location for it!

I tried to avoid looping over the parents multiple times in_save_metadata for the sake of performance (potentially this path could be deeply nested). Hence looping once, and creating two sets of awaitables: one for checking if an array exists at the location + one to actually modify the metadata there. Again, happy to update this if there's a simpler solution.

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented indocs/user-guide/*.rst
  • Changes documented as a new file inchanges/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@github-actionsgithub-actionsbot added the needs release notesAutomatically applied to PRs which haven't added release notes labelAug 26, 2025
@codecov
Copy link

codecovbot commentedAug 26, 2025
edited
Loading

Codecov Report

❌ Patch coverage is72.22222% with15 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.21%. Comparing base (62551c7) to head (c8157fd).
⚠️ Report is 2 commits behind head on main.

Files with missing linesPatch %Lines
src/zarr/core/metadata/io.py74.28%9 Missing⚠️
src/zarr/storage/_common.py73.33%4 Missing⚠️
src/zarr/core/array.py50.00%1 Missing⚠️
src/zarr/core/group.py50.00%1 Missing⚠️
Additional details and impacted files
@@            Coverage Diff             @@##             main    #3407      +/-   ##==========================================- Coverage   61.24%   61.21%   -0.04%==========================================  Files          83       84       +1       Lines        9907     9923      +16     ==========================================+ Hits         6068     6074       +6- Misses       3839     3849      +10
Files with missing linesCoverage Δ
src/zarr/core/array.py68.62% <50.00%> (-0.48%)⬇️
src/zarr/core/group.py70.24% <50.00%> (-0.28%)⬇️
src/zarr/storage/_common.py67.00% <73.33%> (+0.16%)⬆️
src/zarr/core/metadata/io.py74.28% <74.28%> (ø)
🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@d-v-b
Copy link
Contributor

conceptually I don't think we want azarr.core.metadata.io module. So far, thezarr.core.metadata module has been exclusively for definitions of the metadata classes, which is distinct from the routines for saving metadata documents to disk.

right now I think a better location would bezarr.core.group -- would that be possible?

@K-Meech
Copy link
ContributorAuthor

Thanks@d-v-b - I think the only issue with this is it may introduce a circular import?zarr.core.group already imports multiple functions fromzarr.core.array, andzarr.core.array would need to import these common metadata saving functions fromzarr.core.group.

I could move those functions intozarr.core.array instead?_build_parents used to be in that file, and was imported by bothzarr.core.array andzarr.core.group (although only by putting an import inside that function to avoid another circular import 😅 )

@d-v-b
Copy link
Contributor

d-v-b commentedAug 26, 2025
edited
Loading

very good points@K-Meech. Now I do think we should havezarr.core.metadata.io. But I don't think it should depend onAsyncArray orAsyncGroup. Looking at_build_parents, all it does is save metadata. I don't think this class needs to useAsyncGroup for that, we can just write the metadata out directly without that class.

In fact, we might not need the metadata-saving logic in_build_parents, since it's being called byanother routine that's already creating metadata (save_metadata). IMO_build_parents should just decide where metadata documents need to be created, and then return a{name: GroupMetadata} dict with the names of the groups that need to be created by the calling function (e.g.,save_metadata).

I suspect all of this could be handled bycreate_hierarchy. In any case, that function should also be moved tozarr.core.metadata.io (i'm happy to do this in another PR if you don't want to)

edit: I mistakenly linked to thecreate_hierarchy method defined on theAsyncGroup class. I meant to link to the stand-alone function:

asyncdefcreate_hierarchy(

@K-Meech
Copy link
ContributorAuthor

Thanks@d-v-b - sounds like a good plan. I'll look into removing the dependency onAsyncArray +AsyncGroup.
I'm away for the next few weeks, but can look into this + any other comments left on the PR in the meantime once I'm back.

@github-actionsgithub-actionsbot removed the needs release notesAutomatically applied to PRs which haven't added release notes labelSep 18, 2025
@K-Meech
Copy link
ContributorAuthor

@d-v-b I've updated the code now to match your suggestion above. The dependency onAsyncArray /AsyncGroup is removed, and_build_parents now returns a dict of{name: GroupMetadata} thatsave_metadata then creates.

I agree thatcreate_hierarchy could probably handle much of this functionality, but perhaps it's best to change this in a separate PR to keep the changes minimal here? What do you think?

@d-v-b
Copy link
Contributor

I agree thatcreate_hierarchy could probably handle much of this functionality, but perhaps it's best to change this in a separate PR to keep the changes minimal here? What do you think?

That works for me!


@pytest.mark.asyncio
asyncdeftest_async_oindex_with_zarr_array(self,store):
z1=zarr.create_array(store=store,shape=(2,2),chunks=(1,1),zarr_format=3,dtype="i8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

why did we need to change this test?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This test creates an array as a child of another array, so would throw an error (I changed it to create a group then put both arrays inside instead).

E.g. running the equivalent for a local store, shows an array inside an array:

store = LocalStore("data/images/arr")z1 = zarr.create_array(store=store, shape=(2, 2), chunks=(1, 1), zarr_format=3, dtype="i8")z1[...] = np.array([[1, 2], [3, 4]])async_zarr = z1._async_array# create boolean zarr array to index withz2 = zarr.create_array(    store=store, name="z2", shape=(2,), chunks=(1,), zarr_format=3, dtype="?")z2[...] = np.array([True, False])

d-v-b reacted with thumbs up emoji
Copy link
Contributor

@d-v-bd-v-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

thank you!

@d-v-bd-v-b merged commitde94764 intozarr-developers:mainSep 18, 2025
29 checks passed
@K-MeechK-Meech deleted the km/child-of-array branchSeptember 19, 2025 08:11
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@d-v-bd-v-bd-v-b approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Silent failure when creating an array where there is an existing node

2 participants

@K-Meech@d-v-b

[8]ページ先頭

©2009-2025 Movatter.jp