Skip to content

Commit d54f25c

Browse files
Avoid deprecated product in numpy=1.25 (#1405)
* Avoid deprecated product in numpy=1.25 * Add changelog for np.prod --------- Co-authored-by: Josh Moore <[email protected]>
1 parent a2e864c commit d54f25c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

docs/release.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Maintenance
3434
* Remove ``codecov`` from GitHub actions.
3535
By :user:`John A. Kirkham <jakirkham>` :issue:`1391`.
3636

37+
* Replace ``np.product`` with ``np.prod`` due to deprecation.
38+
By :user:`James Bourbeau <jrbourbeau>` :issue:`1405`.
39+
3740
Documentation
3841
~~~~~~~~~~~~~
3942

zarr/tests/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ def test_iter(self):
14791479
)
14801480
for shape, chunks in params:
14811481
z = self.create_array(shape=shape, chunks=chunks, dtype=int)
1482-
a = np.arange(np.product(shape)).reshape(shape)
1482+
a = np.arange(np.prod(shape)).reshape(shape)
14831483
z[:] = a
14841484
for expect, actual in zip_longest(a, z):
14851485
assert_array_equal(expect, actual)
@@ -1500,7 +1500,7 @@ def test_islice(self):
15001500
)
15011501
for shape, chunks, start, end in params:
15021502
z = self.create_array(shape=shape, chunks=chunks, dtype=int)
1503-
a = np.arange(np.product(shape)).reshape(shape)
1503+
a = np.arange(np.prod(shape)).reshape(shape)
15041504
z[:] = a
15051505
end_array = min(end, a.shape[0])
15061506
for expect, actual in zip_longest(a[start:end_array],

zarr/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def guess_chunks(shape: Tuple[int, ...], typesize: int) -> Tuple[int, ...]:
111111

112112
# Determine the optimal chunk size in bytes using a PyTables expression.
113113
# This is kept as a float.
114-
dset_size = np.product(chunks)*typesize
114+
dset_size = np.prod(chunks)*typesize
115115
target_size = CHUNK_BASE * (2**np.log10(dset_size/(1024.*1024)))
116116

117117
if target_size > CHUNK_MAX:
@@ -126,14 +126,14 @@ def guess_chunks(shape: Tuple[int, ...], typesize: int) -> Tuple[int, ...]:
126126
# 1b. We're within 50% of the target chunk size, AND
127127
# 2. The chunk is smaller than the maximum chunk size
128128

129-
chunk_bytes = np.product(chunks)*typesize
129+
chunk_bytes = np.prod(chunks)*typesize
130130

131131
if (chunk_bytes < target_size or
132132
abs(chunk_bytes-target_size)/target_size < 0.5) and \
133133
chunk_bytes < CHUNK_MAX:
134134
break
135135

136-
if np.product(chunks) == 1:
136+
if np.prod(chunks) == 1:
137137
break # Element size larger than CHUNK_MAX
138138

139139
chunks[idx % ndims] = math.ceil(chunks[idx % ndims] / 2.0)

0 commit comments

Comments
 (0)