zarr-python icon indicating copy to clipboard operation
zarr-python copied to clipboard

Group.create in V2 vs V3

Open rabernat opened this issue 1 year ago • 2 comments

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 avatar May 29 '24 02:05 rabernat

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.

jhamman avatar May 29 '24 02:05 jhamman

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.

d-v-b avatar Jun 02 '24 17:06 d-v-b

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 avatar Oct 18 '24 15:10 jhamman