Skip to content

Commit eab1742

Browse files
maxrjonesd-v-b
andauthored
Suppress NumPy 2.4 VisibleDeprecationWarning for align=0 in backwards compatibility tests (#822)
Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
1 parent 47eebf7 commit eab1742

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

numcodecs/tests/common.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import array
22
import json as _json
33
import os
4+
import warnings
45
from glob import glob
56

67
import numpy as np
@@ -183,7 +184,11 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref
183184
for arr_fn in glob(os.path.join(fixture_dir, 'array.*.npy')):
184185
# setup
185186
i = int(arr_fn.split('.')[-2])
186-
arr = np.load(arr_fn, allow_pickle=True)
187+
with warnings.catch_warnings():
188+
# Old .npy fixture files contain dtype descriptors with align=0 (int).
189+
# NumPy 2.4+ requires align to be a boolean.
190+
warnings.filterwarnings("ignore", message="dtype.*align", category=UserWarning)
191+
arr = np.load(arr_fn, allow_pickle=True)
187192
arr_bytes = arr.tobytes(order='A')
188193
if arr.flags.f_contiguous:
189194
order = 'F'
@@ -222,9 +227,13 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref
222227
# load and decode data
223228
with open(enc_fn, mode='rb') as ef:
224229
enc = ef.read()
225-
dec = codec.decode(enc)
226-
dec_arr = ensure_ndarray(dec).reshape(-1, order='A')
227-
dec_arr = dec_arr.view(dtype=arr.dtype).reshape(arr.shape, order=order)
230+
with warnings.catch_warnings():
231+
# Old fixture data may contain dtypes with align=0 (int).
232+
# NumPy 2.4+ requires align to be a boolean.
233+
warnings.filterwarnings("ignore", message="dtype.*align", category=UserWarning)
234+
dec = codec.decode(enc)
235+
dec_arr = ensure_ndarray(dec).reshape(-1, order='A')
236+
dec_arr = dec_arr.view(dtype=arr.dtype).reshape(arr.shape, order=order)
228237
if precision and precision[j] is not None:
229238
assert_array_almost_equal(arr, dec_arr, decimal=precision[j])
230239
elif arr.dtype == 'object':

0 commit comments

Comments
 (0)