Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbf0cd2

Browse files
committed
MNT: shorten logic + docstring
1 parent cfb27b3 commit bbf0cd2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,14 +1708,17 @@ def safe_first_element(obj):
17081708

17091709
def _safe_first_finite(obj, *, skip_nonfinite=True):
17101710
"""
1711-
Return the first non-None element in *obj*.
1711+
Return the first non-None (and optionally finite) element in *obj*.
1712+
17121713
This is a method for internal use.
17131714
17141715
This is an type-independent way of obtaining the first non-None element,
17151716
supporting both index access and the iterator protocol.
17161717
The first non-None element will be obtained when skip_none is True.
17171718
"""
17181719
def safe_isfinite(val):
1720+
if val is None:
1721+
return False
17191722
try:
17201723
return np.isfinite(val) if np.isscalar(val) else True
17211724
except TypeError:
@@ -1743,10 +1746,7 @@ def safe_isfinite(val):
17431746
raise RuntimeError("matplotlib does not "
17441747
"support generators as input")
17451748
else:
1746-
return next(
1747-
val for val in obj
1748-
if val is not None and safe_isfinite(val)
1749-
)
1749+
return next(val for val in obj if safe_isfinite(val))
17501750

17511751

17521752
def sanitize_sequence(data):

0 commit comments

Comments
 (0)