Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 676f3eb

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

File tree

Expand file treeCollapse file tree

1 file changed

+17
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-6
lines changed

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+17-6Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.