Skip to content

Adding attrs arg to create_group and create_dataset #121

Closed

Description

@jakirkham

As it stands now, when one writes a group or dataset, one must write the attributes as a separate operation. This results in creation of .zattrs once. Then if one update the attributes, it results in writing .zattrs again. With something like a ZipStore backed Zarr Group, one gets a warning on writing .zattrs the second time, which AFAICT is unavoidable unless someone sets the attributes correctly the first time. So if we include an argument for attrs to create_group and create_dataset, we should be able to avoid this warning by setting the attributes during creation of these Zarr objects.

Activity

  1. alimanfoo commented on Feb 22, 2017

    @alimanfoo
    Member
  2. jakirkham commented on Oct 18, 2017

    @jakirkham
    MemberAuthor

    Would also add open_group to this list. Though I guess this function raises a question about how to handle cases where the group already exists and what to do if these attrs match or don't.

  3. alimanfoo commented on Oct 18, 2017

    @alimanfoo
    Member
  4. jakirkham commented on Oct 18, 2017

    @jakirkham
    MemberAuthor

    If one makes any changes to the attributes, it will be added as a new entry in the Zip file, which is exactly what I would like to avoid.

  5. alimanfoo commented on Oct 19, 2017

    @alimanfoo
    Member
  6. jakirkham commented on Oct 23, 2017

    @jakirkham
    MemberAuthor

    Maybe that would be ok if we check that they don't differ first. Wouldn't want to lose information here. Alternatively we could just start adding copy_from_* style-methods, which would be generally useful and maybe less kludgy than my original suggestion.

    In any event, had to switch to using the zipfile module directly to get tighter control on memory consumption and squeeze out every last bit of efficiency possible. As such this is not a pressing feature for me personally (though may be nice for others). Am happy to let it sit or close as deemed appropriate.

  7. added this to the v2.2 milestone on Nov 19, 2017
  8. jakirkham commented on Nov 20, 2017

    @jakirkham
    MemberAuthor

    Honestly I'd be ok closing this one. While attrs certainly could be an optional argument to functions creating datasets and groups, it diverges from h5py a bit. I think the problem that I had can be solved better ways. Not to mention, the copy suggestion I made above ends up being the same as issue ( https://github.com/alimanfoo/zarr/issues/113 ). Having copy would be of significantly more utility than optionally adding attrs. Thoughts?

  9. alimanfoo commented on Nov 24, 2017

    @alimanfoo
    Member

    Thinking about this some more, I actually think the current behaviour is a bit pointless: when an array or group is created, an empty dict is written to the .zattrs key, but there is no need to write .zattrs at all unless the user actually wants to store some attributes. I'm tempted to change this so that .zattrs is only written when the user actually wants to store some attributes. This would obviate the need for an 'attrs' argument to array or group creation, because, e.g.:

    g = zarr.group()
    g.attrs.update(foo='bar', baz='qux')
    

    ...would then imply only a single write to .zattrs.

  10. jakirkham commented on Nov 24, 2017

    @jakirkham
    MemberAuthor

    Yeah I like that idea better as well. Does it mean a change in the spec though? Not sure if .zattrs was guaranteed to always be there or not.

  11. alimanfoo commented on Nov 24, 2017

    @alimanfoo
    Member
  12. self-assigned this
    on Nov 24, 2017
  13. alimanfoo commented on Nov 24, 2017

    @alimanfoo
    Member

    I've gone ahead and implemented this in #200, everything works fine and should be fully backwards compatible with code and data, so seems like a good thing to me.

  14. added
    release notes doneAutomatically applied to PRs which have release notes.
    and removed
    in progressSomeone is currently working on this
    on Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew features or improvementsrelease notes doneAutomatically applied to PRs which have release notes.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions