24
24
from zarr .compat import PY2
25
25
from zarr .util import buffer_size
26
26
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
28
29
29
30
30
31
# needed for PY2/PY3 consistent behaviour
@@ -932,11 +933,14 @@ def test_object_arrays(self):
932
933
a = z [:]
933
934
assert a .dtype == object
934
935
935
- def test_object_arrays_text (self ):
936
+ def test_object_arrays_vlen_text (self ):
936
937
937
- from numcodecs .tests .common import greetings
938
938
data = np .array (greetings * 1000 , dtype = object )
939
939
940
+ z = self .create_array (shape = data .shape , dtype = object , object_codec = VLenUTF8 ())
941
+ z [:] = data
942
+ assert_array_equal (data , z [:])
943
+
940
944
z = self .create_array (shape = data .shape , dtype = object , object_codec = MsgPack ())
941
945
z [:] = data
942
946
assert_array_equal (data , z [:])
@@ -954,6 +958,38 @@ def test_object_arrays_text(self):
954
958
z [:] = data
955
959
assert_array_equal (data , z [:])
956
960
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
+
957
993
def test_object_arrays_danger (self ):
958
994
959
995
# do something dangerous - manually force an object array with no object codec
@@ -1426,7 +1462,15 @@ def test_object_arrays(self):
1426
1462
# skip this one, cannot use delta with objects
1427
1463
pass
1428
1464
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 ):
1430
1474
# skip this one, cannot use delta with objects
1431
1475
pass
1432
1476
0 commit comments