zarr-developers / zarr-python

An implementation of chunked, compressed, N-dimensional arrays for Python.
https://zarr.readthedocs.io
MIT License
1.45k stars 273 forks source link

Group.create in V2 vs V3 #1928

Open rabernat opened 3 months ago

rabernat commented 3 months ago

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.

jhamman commented 3 months ago

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

v3

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 commented 3 months ago

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.