File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -1395,7 +1395,7 @@ def _reshape_2D(X, name):
1395
1395
"""
1396
1396
# Iterate over columns for ndarrays, over rows otherwise.
1397
1397
X = np .atleast_1d (X .T if isinstance (X , np .ndarray ) else np .asarray (X ))
1398
- if X .ndim == 1 and X . dtype . type != np . object_ :
1398
+ if X .ndim == 1 and not isinstance ( X [ 0 ], collections . abc . Iterable ) :
1399
1399
# 1D array of scalars: directly return it.
1400
1400
return [X ]
1401
1401
elif X .ndim in [1 , 2 ]:
Original file line number Diff line number Diff line change @@ -482,3 +482,24 @@ def test_flatiter():
482
482
483
483
assert 0 == next (it )
484
484
assert 1 == next (it )
485
+
486
+
487
+ def test_reshape2d ():
488
+ class dummy ():
489
+ pass
490
+ x = [dummy () for j in range (5 )]
491
+ xnew = cbook ._reshape_2D (x , 'x' )
492
+ assert np .shape (xnew ) == (1 , 5 )
493
+
494
+ x = np .arange (5 )
495
+ xnew = cbook ._reshape_2D (x , 'x' )
496
+ assert np .shape (xnew ) == (1 , 5 )
497
+
498
+ x = [[dummy () for j in range (5 )] for i in range (3 )]
499
+ xnew = cbook ._reshape_2D (x , 'x' )
500
+ assert np .shape (xnew ) == (3 , 5 )
501
+
502
+ # this is strange behaviour, but...
503
+ x = np .random .rand (3 , 5 )
504
+ xnew = cbook ._reshape_2D (x , 'x' )
505
+ assert np .shape (xnew ) == (5 , 3 )
You can’t perform that action at this time.
0 commit comments