Prevent update_attributes from erasing all prior attributes#2870
Merged
dstansby merged 3 commits intozarr-developers:mainfrom Feb 27, 2025
Merged
Prevent update_attributes from erasing all prior attributes#2870dstansby merged 3 commits intozarr-developers:mainfrom
dstansby merged 3 commits intozarr-developers:mainfrom
Conversation
d-v-b
reviewed
Feb 27, 2025
| """ | ||
| # metadata.attributes is "frozen" so we simply clear and update the dict | ||
| self.metadata.attributes.clear() | ||
| self.metadata.attributes.update(new_attributes) |
Contributor
There was a problem hiding this comment.
in principle we do want the metadata documents to be immutable, but as long as we are using plain python dicts for the attributes, immutability is not realistic. so updating in-place is fine.
dstansby
reviewed
Feb 27, 2025
| >>> attrs | ||
| {'a': 3, 'c': 4} | ||
| """ | ||
| self._obj.metadata.attributes.clear() |
Contributor
There was a problem hiding this comment.
Is this a separate bug fix to the change in zarr/core/array.py? If so, it should get it's own changelog entry, and test.
Contributor
Author
There was a problem hiding this comment.
This is to keep put (which formerly was using the undesired behavior in update_attributes) working as expected rather than a new feature or bugfix
dstansby
approved these changes
Feb 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes attribute updating logic by clearing in calls to
putand removingclearcalls from allupdate_attributesmethods. It also fixes an apparent oversight in the JSON type (advise if I'm wrong) which didn't allow lists. Sequence should handle bothtupleandlistcloses: #2867
TODO:
docs/user-guide/*.rstchanges/