Skip to content

Group.create in V2 vs V3 #1928

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
rabernat opened this issue May 29, 2024 · 3 comments
Closed

Group.create in V2 vs V3 #1928

rabernat opened this issue May 29, 2024 · 3 comments
Milestone

Comments

@rabernat
Copy link
Contributor

In V2, the way you create an array with a Group is

import zarr
root = zarr.open_group('data/example.zarr', mode='w')
array = root.create("foo", shape=10)

https://zarr.readthedocs.io/en/stable/api/hierarchy.html#zarr.hierarchy.Group.create

V3 Groups also have a create method; but it is a class method to create a new group

import zarr
root = zarr.Group.create(store)
# new syntax for creating an array
array = root.create_array("foo", ...)
# old syntax doesn't work...tries to create another group!
root.create('foo', shape=(10,))
# -> TypeError: Group.create() got an unexpected keyword argument 'shape'

I predict this is going to be a big source of confusion with V3. We should think about how to minimize the pain.

@rabernat rabernat added the V3 label May 29, 2024
@jhamman
Copy link
Member

jhamman commented May 29, 2024

Thanks for opening this one. It's a bit tricky but we can make something work here. As an end state, it would be better if we had a Group.create_array and Group.create_group methods. How can we get there?

v2

  • Group.create -> new child array
  • Group.create_group -> new child group

v3

  • Group.create -> class method to create a new Group
  • Group.create_array -> new child array
  • Group.create_group -> new child group

We don't really need to expose the Group.create class method in v3. We could rename this to anything (like _create or even __new__). I don't have particularly strong feelings on this one but do agree that we should do something here to ease the transition.

@d-v-b
Copy link
Contributor

d-v-b commented Jun 2, 2024

Why do we need Group.create to initialize a Group, instead of justGroup() (and the same goes for the Array class...)?

And although I personally think the polymorphic Group.create from v2 isn't great, and we should probably steer people toward Group.create_group and Group.create_array, I dont think we lose anything by being compatible with v2 here. I.e., I think we should try to make Group.create match the v2 behavior.

@jhamman
Copy link
Member

jhamman commented Oct 18, 2024

The v2 style for creating an array now works:

In [206]: root = zarr.open_group()

In [207]: root.create("foo", shape=10)
Out[207]: <Array memory://4686914240/foo shape=(10,) dtype=float64>

@jhamman jhamman closed this as completed Oct 18, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Zarr-Python - 3.0 Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants