8000 Fix doctests with numpy 2.0 · zarr-developers/zarr-python@a75a977 · GitHub
[go: up one dir, main page]

Skip to content

Commit a75a977

Browse files
committed
Fix doctests with numpy 2.0
1 parent 0855bd6 commit a75a977

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

zarr/core.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
from functools import reduce
88
from typing import Any
9+
import sys
910

1011
import numpy as np
1112
from numcodecs.compat import ensure_bytes
@@ -62,6 +63,14 @@
6263

6364
__all__ = ["Array"]
6465

66+
if "pytest" in sys.modules:
67+
from packaging.version import Version
68+
69+
if Version(np.__version__) < Version("2"):
70+
# Some data types returned by numpy changed in numpy 2.0, so skip
71+
# doc tests on older versions
72+
__doctest_skip__ = ["*"]
73+
6574

6675
# noinspection PyUnresolvedReferences
6776
class Array:
@@ -609,11 +618,11 @@ def islice(self, start=None, end=None):
609618
610619
Iterate over part of the array:
611620
>>> for value in z.islice(25, 30): value;
612-
25
613-
26
614-
27
615-
28
616-
29
621+
np.int64(25)
622+
np.int64(26)
623+
np.int64(27)
624+
np.int64(28)
625+
np.int64(29)
617626
"""
618627

619628
if len(self.shape) == 0:
@@ -679,7 +688,7 @@ def __getitem__(self, selection):
679688
Retrieve a single item::
680689
681690
>>> z[5]
682-
5
691+
np.int64(5)
683692
684693
Retrieve a region via slicing::
685694
@@ -706,7 +715,7 @@ def __getitem__(self, selection):
706715
Retrieve an item::
707716
708717
>>> z[2, 2]
709-
22
718+
np.int64(22)
710719
711720
Retrieve a region via slicing::
712721
@@ -830,7 +839,7 @@ def get_basic_selection(self, selection=Ellipsis, out=None, fields=None):
830839
Retrieve a single item::
831840
832841
>>> z.get_basic_selection(5)
833-
5
842+
np.int64(5)
834843
835844
Retrieve a region via slicing::
836845
@@ -852,7 +861,7 @@ def get_basic_selection(self, selection=Ellipsis, out=None, fields=None):
852861
Retrieve an item::
853862
854863
>>> z.get_basic_selection((2, 2))
855-
22
864+
np.int64(22)
856865
857866
Retrieve a region via slicing::
858867
@@ -2819,7 +2828,7 @@ def view(
28192828
>>> v[:]
28202829
array([False, False, True, ..., True, False, False])
28212830
>>> np.all(a[:].view(dtype=bool) == v[:])
2822-
True
2831+
np.True_
28232832
28242833
An array can be viewed with a dtype with a different item size, however
28252834
some care is needed to adjust the shape and chunk shape so that chunk
@@ -2833,7 +2842,7 @@ def view(
28332842
>>> v[:10]
28342843
array([0, 0, 1, 0, 2, 0, 3, 0, 4, 0], dtype=uint8)
28352844
>>> np.all(a[:].view('u1') == v[:])
2836-
True
2845+
np.True_
28372846
28382847
Change fill value for uninitialized chunks:
28392848

zarr/creation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def open_array(
569569
>>> z2
570570
<zarr.core.Array (10000, 10000) float64 read-only>
571571
>>> np.all(z1[:] == z2[:])
572-
True
572+
np.True_
573573
574574
Notes
575575
-----

0 commit comments

Comments
 (0)
0