@@ -846,6 +846,28 @@ def test_nchunks_initialized(self):
846
846
z [:] = 42
847
847
assert 10 == z .nchunks_initialized
848
848
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
+
849
871
def test_structured_array (self ):
850
872
851
873
# setup some data
@@ -875,6 +897,70 @@ def test_structured_array(self):
875
897
assert_array_equal (a ['bar' ], z ['bar' ])
876
898
assert_array_equal (a ['baz' ], z ['baz' ])
877
899
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
+
878
964
def test_dtypes (self ):
879
965
880
966
# integers
@@ -1489,6 +1575,10 @@ class TestArrayWithFilters(TestArray):
1489
1575
def create_array (read_only = False , ** kwargs ):
1490
1576
store = dict ()
1491
1577
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
1492
1582
filters = [
1493
1583
Delta (dtype = dtype ),
1494
1584
FixedScaleOffset (dtype = dtype , scale = 1 , offset = 0 ),
@@ -1563,6 +1653,14 @@ def test_structured_array(self):
1563
1653
# skip this one, cannot do delta on structured array
1564
1654
pass
1565
1655
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
+
1566
1664
def test_dtypes (self ):
1567
1665
# skip this one, delta messes up floats
1568
1666
pass
0 commit comments