From b16b74341ec354a3fc4c9f76ce8ab95c1c875dea Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 12 Dec 2024 15:22:15 +0000 Subject: [PATCH] Un-pin numpy (#2552) * Un-pin numpy * Fix doctests --------- Co-authored-by: Davis Bennett --- pyproject.toml | 2 +- zarr/convenience.py | 34 ++++++++++++++++++---------------- zarr/core.py | 17 +++++++++-------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index abc825162c..ed643e496f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ maintainers = [{ name = "Alistair Miles", email = "alimanfoo@googlemail.com" }] requires-python = ">=3.11" dependencies = [ 'asciitree', - 'numpy>=1.24,<2.2', + 'numpy>=1.24', 'fasteners; sys_platform != "emscripten"', 'numcodecs>=0.10.0,!=0.14.0,!=0.14.1', ] diff --git a/zarr/convenience.py b/zarr/convenience.py index bd284e0844..a3cd702c9d 100644 --- a/zarr/convenience.py +++ b/zarr/convenience.py @@ -31,6 +31,8 @@ _builtin_open = open # builtin open is later shadowed by a local open function +__doctest_requires__ = {("*"): ["numpy>=2.2"]} + def _check_and_update_path(store: BaseStore, path): if getattr(store, "_store_version", 2) > 2 and not path: @@ -174,13 +176,13 @@ def save_array(store: StoreLike, arr, *, zarr_version=None, path=None, **kwargs) >>> arr = np.arange(10000) >>> zarr.save_array('data/example.zarr', arr) >>> zarr.load('data/example.zarr') - array([ 0, 1, 2, ..., 9997, 9998, 9999]) + array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,)) Save an array to a single file (uses a :class:`ZipStore`):: >>> zarr.save_array('data/example.zip', arr) >>> zarr.load('data/example.zip') - array([ 0, 1, 2, ..., 9997, 9998, 9999]) + array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,)) """ may_need_closing = _might_close(store) @@ -234,9 +236,9 @@ def save_group(store: StoreLike, *args, zarr_version=None, path=None, **kwargs): >>> loader >>> loader['arr_0'] - array([ 0, 1, 2, ..., 9997, 9998, 9999]) + array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,)) >>> loader['arr_1'] - array([10000, 9999, 9998, ..., 3, 2, 1]) + array([10000, 9999, 9998, ..., 3, 2, 1], shape=(10000,)) Save several arrays using named keyword arguments:: @@ -245,9 +247,9 @@ def save_group(store: StoreLike, *args, zarr_version=None, path=None, **kwargs): >>> loader >>> loader['foo'] - array([ 0, 1, 2, ..., 9997, 9998, 9999]) + array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,)) >>> loader['bar'] - array([10000, 9999, 9998, ..., 3, 2, 1]) + array([10000, 9999, 9998, ..., 3, 2, 1], shape=(10000,)) Store several arrays in a single zip file (uses a :class:`ZipStore`):: @@ -256,9 +258,9 @@ def save_group(store: StoreLike, *args, zarr_version=None, path=None, **kwargs): >>> loader >>> loader['foo'] - array([ 0, 1, 2, ..., 9997, 9998, 9999]) + array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,)) >>> loader['bar'] - array([10000, 9999, 9998, ..., 3, 2, 1]) + array([10000, 9999, 9998, ..., 3, 2, 1], shape=(10000,)) Notes ----- @@ -316,13 +318,13 @@ def save(store: StoreLike, *args, zarr_version=None, path=None, **kwargs): >>> arr = np.arange(10000) >>> zarr.save('data/example.zarr', arr) >>> zarr.load('data/example.zarr') - array([ 0, 1, 2, ..., 9997, 9998, 9999]) + array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,)) Save an array to a Zip file (uses a :class:`ZipStore`):: >>> zarr.save('data/example.zip', arr) >>> zarr.load('data/example.zip') - array([ 0, 1, 2, ..., 9997, 9998, 9999]) + array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,)) Save several arrays to a directory on the file system (uses a :class:`DirectoryStore` and stores arrays in a group):: @@ -336,9 +338,9 @@ def save(store: StoreLike, *args, zarr_version=None, path=None, **kwargs): >>> loader >>> loader['arr_0'] - array([ 0, 1, 2, ..., 9997, 9998, 9999]) + array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,)) >>> loader['arr_1'] - array([10000, 9999, 9998, ..., 3, 2, 1]) + array([10000, 9999, 9998, ..., 3, 2, 1], shape=(10000,)) Save several arrays using named keyword arguments:: @@ -347,9 +349,9 @@ def save(store: StoreLike, *args, zarr_version=None, path=None, **kwargs): >>> loader >>> loader['foo'] - array([ 0, 1, 2, ..., 9997, 9998, 9999]) + array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,)) >>> loader['bar'] - array([10000, 9999, 9998, ..., 3, 2, 1]) + array([10000, 9999, 9998, ..., 3, 2, 1], shape=(10000,)) Store several arrays in a single zip file (uses a :class:`ZipStore`):: @@ -358,9 +360,9 @@ def save(store: StoreLike, *args, zarr_version=None, path=None, **kwargs): >>> loader >>> loader['foo'] - array([ 0, 1, 2, ..., 9997, 9998, 9999]) + array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,)) >>> loader['bar'] - array([10000, 9999, 9998, ..., 3, 2, 1]) + array([10000, 9999, 9998, ..., 3, 2, 1], shape=(10000,)) See Also -------- diff --git a/zarr/core.py b/zarr/core.py index d13da27bc6..817de34528 100644 --- a/zarr/core.py +++ b/zarr/core.py @@ -61,6 +61,7 @@ ) __all__ = ["Array"] +__doctest_requires__ = {("*"): ["numpy>=2.2"]} # noinspection PyUnresolvedReferences @@ -2793,12 +2794,12 @@ def view( >>> a = zarr.array(data, chunks=1000, filters=filters) >>> a[:] array(['female', 'male', 'female', ..., 'male', 'male', 'female'], - dtype='>> v = a.view(dtype='u1', filters=[]) >>> v.is_view True >>> v[:] - array([1, 2, 1, ..., 2, 2, 1], dtype=uint8) + array([1, 2, 1, ..., 2, 2, 1], shape=(10000,), dtype=uint8) Views can be used to modify data: @@ -2806,20 +2807,20 @@ def view( >>> x.sort() >>> v[:] = x >>> v[:] - array([1, 1, 1, ..., 2, 2, 2], dtype=uint8) + array([1, 1, 1, ..., 2, 2, 2], shape=(10000,), dtype=uint8) >>> a[:] array(['female', 'female', 'female', ..., 'male', 'male', 'male'], - dtype='>> data = np.random.randint(0, 2, size=10000, dtype='u1') >>> a = zarr.array(data, chunks=1000) >>> a[:] - array([0, 0, 1, ..., 1, 0, 0], dtype=uint8) + array([0, 0, 1, ..., 1, 0, 0], shape=(10000,), dtype=uint8) >>> v = a.view(dtype=bool) >>> v[:] - array([False, False, True, ..., True, False, False]) + array([False, False, True, ..., True, False, False], shape=(10000,)) >>> np.all(a[:].view(dtype=bool) == v[:]) np.True_ @@ -2841,10 +2842,10 @@ def view( >>> a = zarr.full(10000, chunks=1000, fill_value=-1, dtype='i1') >>> a[:] - array([-1, -1, -1, ..., -1, -1, -1], dtype=int8) + array([-1, -1, -1, ..., -1, -1, -1], shape=(10000,), dtype=int8) >>> v = a.view(fill_value=42) >>> v[:] - array([42, 42, 42, ..., 42, 42, 42], dtype=int8) + array([42, 42, 42, ..., 42, 42, 42], shape=(10000,), dtype=int8) Note that resizing or appending to views is not permitted: