Skip to content

Commit 1c7efb8

Browse files
authored
Merge pull request #210 from jakirkham/tst_empty_structured_array
Test 0-length structured array
2 parents 5234709 + 1d34166 commit 1c7efb8

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

zarr/tests/test_core.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -815,25 +815,28 @@ def test_nchunks_initialized(self):
815815
def test_structured_array(self):
816816

817817
# setup some data
818-
a = np.array([(b'aaa', 1, 4.2),
818+
d = np.array([(b'aaa', 1, 4.2),
819819
(b'bbb', 2, 8.4),
820820
(b'ccc', 3, 12.6)],
821821
dtype=[('foo', 'S3'), ('bar', 'i4'), ('baz', 'f8')])
822-
for fill_value in None, b'', (b'zzz', 0, 0.0):
823-
z = self.create_array(shape=a.shape, chunks=2, dtype=a.dtype,
824-
fill_value=fill_value)
825-
eq(3, len(z))
826-
if fill_value is not None:
827-
np_fill_value = np.array(fill_value, dtype=a.dtype)[()]
828-
eq(np_fill_value, z.fill_value)
829-
eq(np_fill_value, z[0])
830-
eq(np_fill_value, z[-1])
831-
z[...] = a
832-
eq(a[0], z[0])
833-
assert_array_equal(a, z[...])
834-
assert_array_equal(a['foo'], z['foo'])
835-
assert_array_equal(a['bar'], z['bar'])
836-
assert_array_equal(a['baz'], z['baz'])
822+
for a in (d, d[:0]):
823+
for fill_value in None, b'', (b'zzz', 0, 0.0):
824+
z = self.create_array(shape=a.shape, chunks=2, dtype=a.dtype,
825+
fill_value=fill_value)
826+
eq(len(a), len(z))
827+
if fill_value is not None:
828+
np_fill_value = np.array(fill_value, dtype=a.dtype)[()]
829+
eq(np_fill_value, z.fill_value)
830+
if len(z):
831+
eq(np_fill_value, z[0])
832+
eq(np_fill_value, z[-1])
833+
z[...] = a
834+
if len(a):
835+
eq(a[0], z[0])
836+
assert_array_equal(a, z[...])
837+
assert_array_equal(a['foo'], z['foo'])
838+
assert_array_equal(a['bar'], z['bar'])
839+
assert_array_equal(a['baz'], z['baz'])
837840

838841
with assert_raises(ValueError):
839842
# dodgy fill value

0 commit comments

Comments
 (0)