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

[v3] Missing `array` method on groups #2028

Closed tomwhite closed 1 month ago

tomwhite commented 1 month ago

Zarr version

3.0.0a1

Numcodecs version

0.12.1

Python Version

3.11.9

Operating System

Mac

Installation

pip

Description

There is no Group.array method in v3, which is a fairly common way of creating nested arrays.

Steps to reproduce

>>> import numpy as np
>>> import zarr.v2 as zarr
>>> a = np.arange(100000000).reshape(10000, 10000)
>>> root = zarr.group()
>>> root.array("a", a)
<zarr.v2.core.Array '/a' (10000, 10000) int64>
>>> import zarr
>>> root = zarr.group()
>>> root.array("a", a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Group' object has no attribute 'array'. Did you mean: 'arrays'?

Additional output

No response

d-v-b commented 1 month ago

this functionality is handled by Group.create_array (that's the async function, which is wrapped by a method with the same name on the synchronous group class)

tomwhite commented 1 month ago

It's an incompatible change - and it doesn't allow the data to be passed in to the function.

d-v-b commented 1 month ago

noted. my personal view is that create_array is a better name for this routine than array and so long-term that function should be what people use, and I do think create_array should be changed to take a data parameter. As a stop-gap measure for v2 compatibility, perhaps we could implement SyncGroup.array as a wrapper around SyncGroup.create_array, with a loud deprecation warning? Not sure what the deprecation window should be.

thoughts @jhamman ?

rabernat commented 1 month ago

I strongly favor not breaking existing public Zarr API with the V3 release as much as feasible. Doing so will make users unhappy. Yes the API may be too broad. So let's deprecate things carefully, rather than releasing breaking changes.

d-v-b commented 1 month ago

@tomwhite I started working on this over here. Feel free to weigh in on that branch, or on the PR it will become in a few days.