@@ -448,7 +448,7 @@ def test_array(self):
448448 assert_equal (r , np .ones ((2 , 6 , 6 )))
449449
450450 d = np .ones ((6 , ))
451- r = np .array ([[d , d + 1 ], d + 2 ])
451+ r = np .array ([[d , d + 1 ], d + 2 ], dtype = object )
452452 assert_equal (len (r ), 2 )
453453 assert_equal (r [0 ], [d , d + 1 ])
454454 assert_equal (r [1 ], d + 2 )
@@ -1051,34 +1051,60 @@ def test_array_too_big(self):
10511051 assert_raises (ValueError , np .ndarray , buffer = buf , strides = (0 ,),
10521052 shape = (max_bytes // itemsize + 1 ,), dtype = dtype )
10531053
1054- def test_jagged_ndim_object (self ):
1054+ def _ragged_creation (self , seq ):
1055+ # without dtype=object, the ragged object should raise
1056+ with assert_warns (DeprecationWarning ):
1057+ a = np .array (seq )
1058+ b = np .array (seq , dtype = object )
1059+ assert_equal (a , b )
1060+ return b
1061+
1062+ def test_ragged_ndim_object (self ):
10551063 # Lists of mismatching depths are treated as object arrays
1056- a = np . array ([[1 ], 2 , 3 ])
1064+ a = self . _ragged_creation ([[1 ], 2 , 3 ])
10571065 assert_equal (a .shape , (3 ,))
10581066 assert_equal (a .dtype , object )
10591067
1060- a = np . array ([1 , [2 ], 3 ])
1068+ a = self . _ragged_creation ([1 , [2 ], 3 ])
10611069 assert_equal (a .shape , (3 ,))
10621070 assert_equal (a .dtype , object )
10631071
1064- a = np . array ([1 , 2 , [3 ]])
1072+ a = self . _ragged_creation ([1 , 2 , [3 ]])
10651073 assert_equal (a .shape , (3 ,))
10661074 assert_equal (a .dtype , object )
10671075
1068- def test_jagged_shape_object (self ):
1076+ def test_ragged_shape_object (self ):
10691077 # The jagged dimension of a list is turned into an object array
1070- a = np .array ([[1 , 1 ], [2 ], [3 ]])
1071- assert_equal (a .shape , (3 ,))
1072- assert_equal (a .dtype , object )
1073-
1074- a = np .array ([[1 ], [2 , 2 ], [3 ]])
1078+ a = self ._ragged_creation ([[1 , 1 ], [2 ], [3 ]])
10751079 assert_equal (a .shape , (3 ,))
10761080 assert_equal (a .dtype , object )
10771081
1078- a = np . array ([[1 ], [2 ], [ 3 , 3 ]])
1082+ a = self . _ragged_creation ([[1 ], [2 , 2 ], [ 3 ]])
10791083 assert_equal (a .shape , (3 ,))
10801084 assert_equal (a .dtype , object )
10811085
1086+ a = self ._ragged_creation ([[1 ], [2 ], [3 , 3 ]])
1087+ assert a .shape == (3 ,)
1088+ assert a .dtype == object
1089+
1090+ def test_array_of_ragged_array (self ):
1091+ outer = np .array ([None , None ])
1092+ outer [0 ] = outer [1 ] = np .array ([1 , 2 , 3 ])
1093+ assert np .array (outer ).shape == (2 ,)
1094+ assert np .array ([outer ]).shape == (1 , 2 )
1095+
1096+ outer_ragged = np .array ([None , None ])
1097+ outer_ragged [0 ] = np .array ([1 , 2 , 3 ])
1098+ outer_ragged [1 ] = np .array ([1 , 2 , 3 , 4 ])
1099+ # should both of these emit deprecation warnings?
1100+ assert np .array (outer_ragged ).shape == (2 ,)
1101+ assert np .array ([outer_ragged ]).shape == (1 , 2 ,)
1102+
1103+ def test_deep_nonragged_object (self ):
1104+ # None of these should raise, even though they are missing dtype=object
1105+ a = np .array ([[[Decimal (1 )]]])
1106+ a = np .array ([1 , Decimal (1 )])
1107+ a = np .array ([[1 ], [Decimal (1 )]])
10821108
10831109class TestStructured (object ):
10841110 def test_subarray_field_access (self ):
0 commit comments