@@ -989,7 +989,12 @@ def _combine_masks(*args):
989
989
else :
990
990
if isinstance (x , np .ma .MaskedArray ) and x .ndim > 1 :
991
991
raise ValueError ("Masked arrays must be 1-D" )
992
- x = np .asanyarray (x )
992
+ try :
993
+ x = np .asanyarray (x )
994
+ except (np .VisibleDeprecationWarning , ValueError ):
995
+ # NumPy 1.19 raises a warning about ragged arrays, but we want
996
+ # to accept basically anything here.
997
+ x = np .asanyarray (x , dtype = object )
993
998
if x .ndim == 1 :
994
999
x = safe_masked_invalid (x )
995
1000
seqlist [i ] = True
@@ -1316,24 +1321,48 @@ def _reshape_2D(X, name):
1316
1321
Use Fortran ordering to convert ndarrays and lists of iterables to lists of
1317
1322
1D arrays.
1318
1323
1319
- Lists of iterables are converted by applying `np.asarray ` to each of their
1320
- elements. 1D ndarrays are returned in a singleton list containing them.
1321
- 2D ndarrays are converted to the list of their *columns*.
1324
+ Lists of iterables are converted by applying `np.asanyarray ` to each of
1325
+ their elements. 1D ndarrays are returned in a singleton list containing
1326
+ them. 2D ndarrays are converted to the list of their *columns*.
1322
1327
1323
1328
*name* is used to generate the error message for invalid inputs.
1324
1329
"""
1325
- # Iterate over columns for ndarrays, over rows otherwise.
1326
- X = np .atleast_1d (X .T if isinstance (X , np .ndarray ) else np .asarray (X ))
1330
+ # Iterate over columns for ndarrays.
1331
+ if isinstance (X , np .ndarray ):
1332
+ X = X .T
1333
+
1334
+ if len (X ) == 0 :
1335
+ return [[]]
1336
+ elif X .ndim == 1 and np .ndim (X [0 ]) == 0 :
1337
+ # 1D array of scalars: directly return it.
1338
+ return [X ]
1339
+ elif X .ndim in [1 , 2 ]:
1340
+ # 2D array, or 1D array of iterables: flatten them first.
1341
+ return [np .reshape (x , - 1 ) for x in X ]
1342
+ else :
1343
+ raise ValueError (f'{ name } must have 2 or fewer dimensions' )
1344
+
1345
+ # Iterate over list of iterables.
1327
1346
if len (X ) == 0 :
1328
1347
return [[]]
1329
- elif X .ndim == 1 and np .ndim (X [0 ]) == 0 :
1348
+
1349
+ result = []
1350
+ is_1d = True
1351
+ for xi in X :
1352
+ xi = np .asanyarray (xi )
1353
+ nd = np .ndim (xi )
1354
+ if nd > 1 :
1355
+ raise ValueError (f'{ name } must have 2 or fewer dimensions' )
1356
+ elif nd == 1 and len (xi ) != 1 :
1357
+ is_1d = False
1358
+ result .append (xi .reshape (- 1 ))
1359
+
1360
+ if is_1d :
1330
1361
# 1D array of scalars: directly return it.
1331
- return [X ]
1332
- elif X .ndim in [1 , 2 ]:
1333
- # 2D array, or 1D array of iterables: flatten them first.
1334
- return [np .reshape (x , - 1 ) for x in X ]
1362
+ return [np .reshape (result , - 1 )]
1335
1363
else :
1336
- raise ValueError ("{} must have 2 or fewer dimensions" .format (name ))
1364
+ # 2D array, or 1D array of iterables: use flattened version.
1365
+ return result
1337
1366
1338
1367
1339
1368
def violin_stats (X , method , points = 100 , quantiles = None ):
@@ -1399,10 +1428,10 @@ def violin_stats(X, method, points=100, quantiles=None):
1399
1428
quantiles = _reshape_2D (quantiles , "quantiles" )
1400
1429
# Else, mock quantiles if is none or empty
1401
1430
else :
1402
- quantiles = [[]] * np . shape (X )[ 0 ]
1431
+ quantiles = [[]] * len (X )
1403
1432
1404
1433
# quantiles should has the same size as dataset
1405
- if np . shape (X )[: 1 ] != np . shape (quantiles )[: 1 ] :
1434
+ if len (X ) != len (quantiles ):
1406
1435
raise ValueError ("List of violinplot statistics and quantiles values"
1407
1436
" must have the same length" )
1408
1437
@@ -1577,8 +1606,15 @@ def index_of(y):
1577
1606
try :
1578
1607
return y .index .values , y .values
1579
1608
except AttributeError :
1609
+ pass
1610
+ try :
1580
1611
y = _check_1d (y )
1612
+ except (np .VisibleDeprecationWarning , ValueError ):
1613
+ # NumPy 1.19 will warn on ragged input, and we can't actually use it.
1614
+ pass
1615
+ else :
1581
1616
return np .arange (y .shape [0 ], dtype = float ), y
1617
+ raise ValueError ('Input could not be cast to an at-least-1D NumPy array' )
1582
1618
1583
1619
1584
1620
def safe_first_element (obj ):
0 commit comments