@@ -1300,48 +1300,16 @@ def _to_unmasked_float_array(x):
13001300
13011301def _check_1d (x ):
13021302 """Convert scalars to 1D arrays; pass-through arrays as is."""
1303+ if hasattr (x , 'to_numpy' ):
1304+ # if we are given an object that creates a numpy, we should use it...
1305+ x = x .to_numpy ()
13031306 if not hasattr (x , 'shape' ) or len (x .shape ) < 1 :
13041307 return np .atleast_1d (x )
13051308 else :
1306- try :
1307- # work around
1308- # https://github.com/pandas-dev/pandas/issues/27775 which
1309- # means the shape of multi-dimensional slicing is not as
1310- # expected. That this ever worked was an unintentional
1311- # quirk of pandas and will raise an exception in the
1312- # future. This slicing warns in pandas >= 1.0rc0 via
1313- # https://github.com/pandas-dev/pandas/pull/30588
1314- #
1315- # < 1.0rc0 : x[:, None].ndim == 1, no warning, custom type
1316- # >= 1.0rc1 : x[:, None].ndim == 2, warns, numpy array
1317- # future : x[:, None] -> raises
1318- #
1319- # This code should correctly identify and coerce to a
1320- # numpy array all pandas versions.
1321- with warnings .catch_warnings (record = True ) as w :
1322- warnings .filterwarnings (
1323- "always" ,
1324- category = Warning ,
1325- message = 'Support for multi-dimensional indexing' )
1326-
1327- ndim = x [:, None ].ndim
1328- # we have definitely hit a pandas index or series object
1329- # cast to a numpy array.
1330- if len (w ) > 0 :
1331- return np .asanyarray (x )
1332- # We have likely hit a pandas object, or at least
1333- # something where 2D slicing does not result in a 2D
1334- # object.
1335- if ndim < 2 :
1336- return np .atleast_1d (x )
1337- return x
1338- # In pandas 1.1.0, multidimensional indexing leads to an
1339- # AssertionError for some Series objects, but should be
1340- # IndexError as described in
1341- # https://github.com/pandas-dev/pandas/issues/35527
1342- # ValueError: https://github.com/matplotlib/matplotlib/issues/22125
1343- except (AssertionError , IndexError , TypeError , ValueError ):
1309+ ndim = x [:, None ].ndim
1310+ if ndim < 2 :
13441311 return np .atleast_1d (x )
1312+ return x
13451313
13461314
13471315def _reshape_2D (X , name ):
0 commit comments