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

Skip to content

Commit 237e492

Browse files
committed
FIX: _safe_first_finite on all nan array
1 parent 161c96c commit 237e492

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/matplotlib/cbook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ def safe_isfinite(val):
16571657
raise RuntimeError("matplotlib does not "
16581658
"support generators as input")
16591659
else:
1660-
return next(val for val in obj if safe_isfinite(val))
1660+
return next((val for val in obj if safe_isfinite(val)), np.nan)
16611661

16621662

16631663
def sanitize_sequence(data):

lib/matplotlib/tests/test_cbook.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ def test_flatiter():
608608
assert 1 == next(it)
609609

610610

611+
def test__safe_first_finite_all_nan():
612+
arr = np.full(2, np.nan)
613+
ret = cbook._safe_first_finite(arr)
614+
assert ret is np.nan
615+
616+
611617
def test_reshape2d():
612618

613619
class Dummy:

0 commit comments

Comments
 (0)