@@ -846,34 +846,90 @@ def test_nchunks_initialized(self):
846
846
z [:] = 42
847
847
assert 10 == z .nchunks_initialized
848
848
849
- def test_structured_array (self ):
849
+ def test_array_dtype_shape (self ):
850
850
851
+ dt = "(2, 2)f4"
851
852
# setup some data
852
- d = np .array ([(b'aaa' , 1 , 4.2 ),
853
- (b'bbb' , 2 , 8.4 ),
854
- (b'ccc' , 3 , 12.6 )],
855
- dtype = [('foo' , 'S3' ), ('bar' , 'i4' ), ('baz' , 'f8' )])
853
+ d = np .array ([((0 , 1 ),
854
+ (1 , 2 )),
855
+ ((1 , 2 ),
856
+ (2 , 3 )),
857
+ ((2 , 3 ),
858
+ (3 , 4 ))],
859
+ dtype = dt )
860
+
856
861
for a in (d , d [:0 ]):
857
- for fill_value in None , b'' , (b'zzz' , 42 , 16.8 ):
862
+ for fill_value in None , 0 :
863
+ z = self .create_array (shape = a .shape [:- 2 ], chunks = 2 , dtype = dt , fill_value = fill_value )
864
+ assert len (a ) == len (z )
865
+ if fill_value is not None :
866
+ assert fill_value == z .fill_value
867
+ z [...] = a
868
+ assert_array_equal (a , z [...])
869
+
870
+ def check_structured_array (self , d , fill_values ):
871
+ for a in (d , d [:0 ]):
872
+ for fill_value in fill_values :
858
873
z = self .create_array (shape = a .shape , chunks = 2 , dtype = a .dtype , fill_value = fill_value )
859
874
assert len (a ) == len (z )
875
+ assert a .shape == z .shape
876
+ assert a .dtype == z .dtype
877
+
878
+ # check use of fill value before array is initialised with data
860
879
if fill_value is not None :
861
880
if fill_value == b'' :
862
881
# numpy 1.14 compatibility
863
882
np_fill_value = np .array (fill_value , dtype = a .dtype .str ).view (a .dtype )[()]
864
883
else :
865
884
np_fill_value = np .array (fill_value , dtype = a .dtype )[()]
866
885
assert np_fill_value == z .fill_value
867
- if len (z ):
886
+ if len (a ):
868
887
assert np_fill_value == z [0 ]
869
888
assert np_fill_value == z [- 1 ]
889
+ empty = np .empty_like (a )
890
+ empty [:] = np_fill_value
891
+ assert empty [0 ] == z [0 ]
892
+ assert_array_equal (empty [0 :2 ], z [0 :2 ])
893
+ assert_array_equal (empty , z [...])
894
+ for f in a .dtype .names :
895
+ assert_array_equal (empty [f ], z [f ])
896
+
897
+ # store data in array
870
898
z [...] = a
899
+
900
+ # check stored data
871
901
if len (a ):
872
902
assert a [0 ] == z [0 ]
873
- assert_array_equal (a , z [...])
874
- assert_array_equal (a ['foo' ], z ['foo' ])
875
- assert_array_equal (a ['bar' ], z ['bar' ])
876
- assert_array_equal (a ['baz' ], z ['baz' ])
903
+ assert a [- 1 ] == z [- 1 ]
904
+ assert_array_equal (a [0 :2 ], z [0 :2 ])
905
+ assert_array_equal (a , z [...])
906
+ for f in a .dtype .names :
907
+ assert_array_equal (a [f ], z [f ])
908
+
909
+ def test_structured_array (self ):
910
+ d = np .array ([(b'aaa' , 1 , 4.2 ),
911
+ (b'bbb' , 2 , 8.4 ),
912
+ (b'ccc' , 3 , 12.6 )],
913
+ dtype = [('foo' , 'S3' ), ('bar' , 'i4' ), ('baz' , 'f8' )])
914
+ fill_values = None , b'' , (b'zzz' , 42 , 16.8 )
915
+ self .check_structured_array (d , fill_values )
916
+
917
+ def test_structured_array_subshapes (self ):
918
+ d = np .array ([(0 , ((0 , 1 , 2 ), (1 , 2 , 3 )), b'aaa' ),
919
+ (1 , ((1 , 2 , 3 ), (2 , 3 , 4 )), b'bbb' ),
920
+ (2 , ((2 , 3 , 4 ), (3 , 4 , 5 )), b'ccc' )],
921
+ dtype = [('foo' , 'i8' ), ('bar' , '(2, 3)f4' ), ('baz' , 'S3' )])
922
+ fill_values = None , b'' , (0 , ((0 , 0 , 0 ), (1 , 1 , 1 )), b'zzz' )
923
+ self .check_structured_array (d , fill_values )
924
+
925
+ def test_structured_array_nested (self ):
926
+ d = np .array ([(0 , (0 , ((0 , 1 ), (1 , 2 ), (2 , 3 )), 0 ), b'aaa' ),
927
+ (1 , (1 , ((1 , 2 ), (2 , 3 ), (3 , 4 )), 1 ), b'bbb' ),
928
+ (2 , (2 , ((2 , 3 ), (3 , 4 ), (4 , 5 )), 2 ), b'ccc' )],
929
+ dtype = [('foo' , 'i8' ), ('bar' , [('foo' , 'i4' ), ('bar' , '(3, 2)f4' ),
930
+ ('baz' , 'u1' )]), ('baz' , 'S3' )])
931
+ fill_values = None , b'' , (0 , (0 , ((0 , 0 ), (1 , 1 ), (2 , 2 )), 0 ), b'zzz' )
932
+ self .check_structured_array (d , fill_values )
877
933
878
934
def test_dtypes (self ):
879
935
@@ -1559,10 +1615,22 @@ def test_astype(self):
1559
1615
expected = data .astype (astype )
1560
1616
assert_array_equal (expected , z2 )
1561
1617
1618
+ def test_array_dtype_shape (self ):
1619
+ # skip this one, cannot do delta on unstructured array
1620
+ pass
1621
+
1562
1622
def test_structured_array (self ):
1563
1623
# skip this one, cannot do delta on structured array
1564
1624
pass
1565
1625
1626
+ def test_structured_array_subshapes (self ):
1627
+ # skip this one, cannot do delta on structured array
1628
+ pass
1629
+
1630
+ def test_structured_array_nested (self ):
1631
+ # skip this one, cannot do delta on structured array
1632
+ pass
1633
+
1566
1634
def test_dtypes (self ):
1567
1635
# skip this one, delta messes up floats
1568
1636
pass
0 commit comments