Skip to content

Commit ef2acb6

Browse files
committed
add tests for structured dtypes
1 parent 67df487 commit ef2acb6

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

zarr/tests/test_array.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,11 @@ def _test_persistence(self, a, chunks):
360360
z3[:] = 0
361361

362362
# check effect of write
363-
assert_array_equal(np.zeros_like(a), z3[:])
364-
assert_array_equal(np.zeros_like(a), z2[:])
365-
assert_array_equal(np.zeros_like(a), z[:])
363+
expect = np.empty_like(a)
364+
expect[:] = 0
365+
assert_array_equal(expect, z3[:])
366+
assert_array_equal(expect, z2[:])
367+
assert_array_equal(expect, z[:])
366368

367369
# open for writing (must not exist)
368370
with assert_raises(ValueError):
@@ -372,13 +374,22 @@ def _test_persistence(self, a, chunks):
372374
shutil.rmtree(path)
373375

374376
def test_persistence_1d(self):
377+
# simple dtype
375378
self._test_persistence(np.arange(1050), chunks=(100,))
379+
# structured dtype
380+
dtype = np.dtype([('a', 'i4'), ('b', 'S10')])
381+
self._test_persistence(np.empty(10000, dtype=dtype), chunks=(100,))
376382

377383
def test_persistence_2d(self):
378-
a = np.arange(10000).reshape((1000, 10))
379384
chunks = (100, 2)
385+
# simple dtype
386+
a = np.arange(10000).reshape((1000, 10))
380387
self._test_persistence(a, chunks=chunks)
381-
388+
# structured dtype
389+
dtype = np.dtype([('a', 'i4'), ('b', 'S10')])
390+
self._test_persistence(np.empty((1000, 10), dtype=dtype),
391+
chunks=chunks)
392+
382393
def test_resize_persistence(self):
383394

384395
# setup path

zarr/tests/test_chunk.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ def test_create_chunk(self):
9292
self._test_create_chunk(np.linspace(-1, 1, 1e4, dtype=dtype)
9393
.reshape(100, -1))
9494

95+
# structured dtype
96+
dtype = np.dtype([('a', 'i4'), ('b', 'S10')])
97+
print(dtype)
98+
print('1-dimensional')
99+
self._test_create_chunk(np.empty(10000, dtype=dtype))
100+
print('2-dimensional')
101+
self._test_create_chunk(np.empty((100, 100), dtype=dtype))
102+
95103
def test_create_chunk_fill_value(self):
96104

97105
for shape in 100, (100, 100):

0 commit comments

Comments
 (0)