Skip to content

Commit de7b7b9

Browse files
committed
Add tests for large itemsizes for zeros and nans too
1 parent 4cd7cb4 commit de7b7b9

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

tests/ndarray/test_nans.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,18 @@ def test_nans_simple(shape, dtype):
2727

2828
b = np.full(shape=shape, fill_value=np.nan, dtype=a.dtype)
2929
np.testing.assert_allclose(a[...], b)
30+
31+
32+
@pytest.mark.parametrize("asarray", [True, False])
33+
@pytest.mark.parametrize("typesize", [1, 3, 255, 256, 257, 256 * 256])
34+
@pytest.mark.parametrize("shape", [(1,), (3,), (10,), (2*10,)])
35+
def test_large_typesize(shape, typesize, asarray):
36+
dtype = np.dtype([("f_001", "f8", (typesize,)), ("f_002", "f4", (typesize,))])
37+
a = np.full(shape, np.nan, dtype=dtype)
38+
if asarray:
39+
b = blosc2.asarray(a)
40+
else:
41+
# b = blosc2.nans(shape, dtype=dtype) # TODO: this is not working; perhaps deprecate blosc2.nans()?
42+
b = blosc2.full(shape, np.nan, dtype=dtype)
43+
for field in dtype.fields:
44+
np.testing.assert_allclose(b[field], a[field], equal_nan=True)

tests/ndarray/test_zeros.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,16 @@ def test_zeros_minimal(shape, dtype):
122122
assert all(c >= b for c, b in zip(a.chunks, a.blocks, strict=False))
123123
assert a.dtype == dtype
124124
assert a.schunk.typesize == dtype.itemsize
125+
126+
127+
@pytest.mark.parametrize("asarray", [True, False])
128+
@pytest.mark.parametrize("typesize", [255, 256, 257, 261, 256 * 256])
129+
@pytest.mark.parametrize("shape", [(1,), (3,), (10,), (2*10,), (2**8 - 1, 3)])
130+
def test_large_typesize(shape, typesize, asarray):
131+
dtype = np.dtype([("f_001", "<i1", (typesize,)), ("f_002", "f4", (typesize,))])
132+
a = np.zeros(shape, dtype=dtype)
133+
if asarray:
134+
b = blosc2.asarray(a)
135+
else:
136+
b = blosc2.zeros(shape, dtype=dtype)
137+
assert np.array_equal(b[0], a[0])

0 commit comments

Comments
 (0)