Skip to content

Commit e584f68

Browse files
committed
add vlen tests
1 parent 116d168 commit e584f68

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

zarr/tests/test_core.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
from zarr.compat import PY2
2525
from zarr.util import buffer_size
2626
from numcodecs import (Delta, FixedScaleOffset, Zlib, Blosc, BZ2, MsgPack, Pickle,
27-
Categorize, JSON)
27+
Categorize, JSON, VLenUTF8, VLenBytes, VLenArray)
28+
from numcodecs.tests.common import greetings
2829

2930

3031
# needed for PY2/PY3 consistent behaviour
@@ -932,11 +933,14 @@ def test_object_arrays(self):
932933
a = z[:]
933934
assert a.dtype == object
934935

935-
def test_object_arrays_text(self):
936+
def test_object_arrays_vlen_text(self):
936937

937-
from numcodecs.tests.common import greetings
938938
data = np.array(greetings * 1000, dtype=object)
939939

940+
z = self.create_array(shape=data.shape, dtype=object, object_codec=VLenUTF8())
941+
z[:] = data
942+
assert_array_equal(data, z[:])
943+
940944
z = self.create_array(shape=data.shape, dtype=object, object_codec=MsgPack())
941945
z[:] = data
942946
assert_array_equal(data, z[:])
@@ -954,6 +958,38 @@ def test_object_arrays_text(self):
954958
z[:] = data
955959
assert_array_equal(data, z[:])
956960

961+
def test_object_arrays_vlen_bytes(self):
962+
963+
greetings_bytes = [g.encode('utf8') for g in greetings]
964+
data = np.array(greetings_bytes * 1000, dtype=object)
965+
966+
z = self.create_array(shape=data.shape, dtype=object, object_codec=VLenBytes())
967+
z[:] = data
968+
assert_array_equal(data, z[:])
969+
970+
z = self.create_array(shape=data.shape, dtype=object, object_codec=Pickle())
971+
z[:] = data
972+
assert_array_equal(data, z[:])
973+
974+
def test_object_arrays_vlen_array(self):
975+
976+
data = np.array([np.array([1, 3, 7]),
977+
np.array([5]),
978+
np.array([2, 8, 12])] * 1000, dtype=object)
979+
980+
codecs = VLenArray(int), VLenArray('<u4')
981+
for codec in codecs:
982+
z = self.create_array(shape=data.shape, dtype=object, object_codec=codec)
983+
z[:] = data
984+
a = z[:]
985+
assert isinstance(a, np.ndarray)
986+
assert a.dtype == object
987+
assert a.shape == data.shape
988+
for expected, actual in zip(data.flat, a.flat):
989+
assert isinstance(actual, np.ndarray)
990+
assert_array_equal(expected, actual)
991+
assert actual.dtype == codec.dtype
992+
957993
def test_object_arrays_danger(self):
958994

959995
# do something dangerous - manually force an object array with no object codec
@@ -1426,7 +1462,15 @@ def test_object_arrays(self):
14261462
# skip this one, cannot use delta with objects
14271463
pass
14281464

1429-
def test_object_arrays_text(self):
1465+
def test_object_arrays_vlen_text(self):
1466+
# skip this one, cannot use delta with objects
1467+
pass
1468+
1469+
def test_object_arrays_vlen_bytes(self):
1470+
# skip this one, cannot use delta with objects
1471+
pass
1472+
1473+
def test_object_arrays_vlen_array(self):
14301474
# skip this one, cannot use delta with objects
14311475
pass
14321476

0 commit comments

Comments
 (0)