Skip to content

Commit aad7e94

Browse files
Tarik Onalanalimanfoo
authored andcommitted
Move crude tests to core tests
1 parent 7bd2a7e commit aad7e94

File tree

2 files changed

+98
-53
lines changed

2 files changed

+98
-53
lines changed

zarr/tests/test_core.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,28 @@ def test_nchunks_initialized(self):
846846
z[:] = 42
847847
assert 10 == z.nchunks_initialized
848848

849+
def test_unstructured_array(self):
850+
851+
subshape = (2, 2)
852+
dt = np.dtype("%sf4" % (subshape,))
853+
# setup some data
854+
d = np.array([((0, 1),
855+
(1, 2)),
856+
((1, 2),
857+
(2, 3)),
858+
((2, 3),
859+
(3, 4))],
860+
dtype=dt)
861+
862+
for a in (d, d[:0]):
863+
for fill_value in None, 0:
864+
z = self.create_array(shape=a.shape[:-len(subshape)], chunks=2, dtype=dt, fill_value=fill_value)
865+
assert len(a) == len(z)
866+
if fill_value is not None:
867+
assert fill_value == z.fill_value
868+
z[...] = a
869+
assert_array_equal(a, z[...])
870+
849871
def test_structured_array(self):
850872

851873
# setup some data
@@ -875,6 +897,70 @@ def test_structured_array(self):
875897
assert_array_equal(a['bar'], z['bar'])
876898
assert_array_equal(a['baz'], z['baz'])
877899

900+
def test_structured_array_subshapes(self):
901+
902+
# setup some data
903+
d = np.array([(0, ((0, 1, 2), (1, 2, 3)), b'aaa'),
904+
(1, ((1, 2, 3), (2, 3, 4)), b'bbb'),
905+
(2, ((2, 3, 4), (3, 4, 5)), b'ccc')],
906+
dtype=[('foo', 'i8'), ('bar', '(2, 3)f4'), ('baz', 'S3')])
907+
for a in (d, d[:0]):
908+
for fill_value in None, b'', (0, ((0, 0, 0), (1, 1, 1)), b'zzz'):
909+
z = self.create_array(shape=a.shape, chunks=2, dtype=a.dtype, fill_value=fill_value)
910+
assert len(a) == len(z)
911+
if fill_value is not None:
912+
if fill_value == b'':
913+
# numpy 1.14 compatibility
914+
np_fill_value = np.array(fill_value, dtype=a.dtype.str).view(a.dtype)[()]
915+
else:
916+
np_fill_value = np.array(fill_value, dtype=a.dtype)[()]
917+
assert np_fill_value == z.fill_value
918+
if len(z):
919+
assert np_fill_value == z[0]
920+
assert np_fill_value == z[-1]
921+
z[...] = a
922+
if len(a):
923+
assert a[0] == z[0]
924+
assert_array_equal(a, z[...])
925+
assert_array_equal(a['foo'], z['foo'])
926+
assert_array_equal(a['bar'], z['bar'])
927+
assert_array_equal(a['baz'], z['baz'])
928+
else:
929+
# BUG(onalant): numpy cannot compare empty arrays of structured dtypes with shapes
930+
assert a.tobytes() == z[...].tobytes()
931+
932+
def test_structured_array_nested(self):
933+
934+
# setup some data
935+
d = np.array([(0, (0, ((0, 1), (1, 2), (2, 3)), 0), b'aaa'),
936+
(1, (1, ((1, 2), (2, 3), (3, 4)), 1), b'bbb'),
937+
(2, (2, ((2, 3), (3, 4), (4, 5)), 2), b'ccc')],
938+
dtype=[('foo', 'i8'), ('bar', [('foo', 'i4'), ('bar', '(3, 2)f4'), ('baz', 'u1')]), ('baz', 'S3')])
939+
for a in (d, d[:0]):
940+
for fill_value in None, b'', (0, (0, ((0, 0), (1, 1), (2, 2)), 0), b'zzz'):
941+
z = self.create_array(shape=a.shape, chunks=2, dtype=a.dtype, fill_value=fill_value)
942+
assert len(a) == len(z)
943+
if fill_value is not None:
944+
if fill_value == b'':
945+
# numpy 1.14 compatibility
946+
np_fill_value = np.array(fill_value, dtype=a.dtype.str).view(a.dtype)[()]
947+
else:
948+
np_fill_value = np.array(fill_value, dtype=a.dtype)[()]
949+
assert np_fill_value == z.fill_value
950+
if len(z):
951+
assert np_fill_value == z[0]
952+
assert np_fill_value == z[-1]
953+
z[...] = a
954+
if len(a):
955+
assert a[0] == z[0]
956+
assert_array_equal(a, z[...])
957+
assert_array_equal(a['foo'], z['foo'])
958+
assert_array_equal(a['bar'], z['bar'])
959+
assert_array_equal(a['baz'], z['baz'])
960+
else:
961+
# BUG(onalant): numpy cannot compare empty arrays of structured dtypes with shapes
962+
assert a.tobytes() == z[...].tobytes()
963+
878964
def test_dtypes(self):
879965

880966
# integers
@@ -1489,6 +1575,10 @@ class TestArrayWithFilters(TestArray):
14891575
def create_array(read_only=False, **kwargs):
14901576
store = dict()
14911577
dtype = kwargs.get('dtype', None)
1578+
# WARN(onalant): this is to compensate for unstructured dtypes
1579+
# should this be in upstream numcodecs?
1580+
if isinstance(dtype, np.dtype):
1581+
dtype = dtype.base
14921582
filters = [
14931583
Delta(dtype=dtype),
14941584
FixedScaleOffset(dtype=dtype, scale=1, offset=0),
@@ -1563,6 +1653,14 @@ def test_structured_array(self):
15631653
# skip this one, cannot do delta on structured array
15641654
pass
15651655

1656+
def test_structured_array_subshapes(self):
1657+
# skip this one, cannot do delta on structured array
1658+
pass
1659+
1660+
def test_structured_array_nested(self):
1661+
# skip this one, cannot do delta on structured array
1662+
pass
1663+
15661664
def test_dtypes(self):
15671665
# skip this one, delta messes up floats
15681666
pass

zarr/tests/test_crude.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)