@@ -1367,12 +1367,20 @@ def _check_1d(x):
1367
1367
return np .atleast_1d (x )
1368
1368
else :
1369
1369
try :
1370
- # work around https://github.com/pandas-dev/pandas/issues/27775
1371
- # which mean the shape is not as expected. That this ever worked
1372
- # was an unintentional quirk of pandas the above line will raise
1373
- # an exception in the future.
1374
- # This warns in pandas >= 1.0 via
1370
+ # work around
1371
+ # https://github.com/pandas-dev/pandas/issues/27775 which
1372
+ # means the shape of multi-dimensional slicing is not as
1373
+ # expected. That this ever worked was an unintentional
1374
+ # quirk of pandas and will raise an exception in the
1375
+ # future. This slicing warns in pandas >= 1.0rc0 via
1375
1376
# https://github.com/pandas-dev/pandas/pull/30588
1377
+ #
1378
+ # < 1.0rc0 : x[:, None].ndim == 1, no warning, custom type
1379
+ # >= 1.0rc1 : x[:, None].ndim == 2, warns, numpy array
1380
+ # future : x[:, None] -> raises
1381
+ #
1382
+ # This code should correctly identify and coerce to a
1383
+ # numpy array all pandas versions.
1376
1384
with warnings .catch_warnings (record = True ) as w :
1377
1385
warnings .filterwarnings ("always" ,
1378
1386
category = DeprecationWarning ,
@@ -1381,8 +1389,11 @@ def _check_1d(x):
1381
1389
ndim = x [:, None ].ndim
1382
1390
# we have definitely hit a pandas index or series object
1383
1391
# cast to a numpy array.
1384
- if len (w ) != 0 :
1392
+ if len (w ) > 0 :
1385
1393
return np .asanyarray (x )
1394
+ # We have likely hit a pandas object, or at least
1395
+ # something where 2D slicing does not result in a 2D
1396
+ # object.
1386
1397
if ndim < 2 :
1387
1398
return np .atleast_1d (x )
1388
1399
return x
0 commit comments