Skip to content

Commit 676f3eb

Browse files
committed
DOC: clarified comments in code about what this code is doing
1 parent c7eddd6 commit 676f3eb

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,12 +1367,20 @@ def _check_1d(x):
13671367
return np.atleast_1d(x)
13681368
else:
13691369
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
13751376
# 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.
13761384
with warnings.catch_warnings(record=True) as w:
13771385
warnings.filterwarnings("always",
13781386
category=DeprecationWarning,
@@ -1381,8 +1389,11 @@ def _check_1d(x):
13811389
ndim = x[:, None].ndim
13821390
# we have definitely hit a pandas index or series object
13831391
# cast to a numpy array.
1384-
if len(w) != 0:
1392+
if len(w) > 0:
13851393
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.
13861397
if ndim < 2:
13871398
return np.atleast_1d(x)
13881399
return x

0 commit comments

Comments
 (0)