FIX: `_safe_first_finite` on all non-finite array by rcomer · Pull Request #25547 · matplotlib/matplotlib · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions lib/matplotlib/axes/_axes.py
10 changes: 5 additions & 5 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,13 +1619,13 @@ def safe_first_element(obj):

def _safe_first_finite(obj, *, skip_nonfinite=True):
"""
Return the first non-None (and optionally finite) element in *obj*.
Return the first finite element in *obj* if one is available and skip_nonfinite is
True. Otherwise return the first element.

This is a method for internal use.

This is a type-independent way of obtaining the first non-None element,
supporting both index access and the iterator protocol.
The first non-None element will be obtained when skip_none is True.
This is a type-independent way of obtaining the first finite element, supporting
both index access and the iterator protocol.
"""
def safe_isfinite(val):
if val is None:
Expand Down Expand Up @@ -1657,7 +1657,7 @@ def safe_isfinite(val):
raise RuntimeError("matplotlib does not "
"support generators as input")
else:
return next(val for val in obj if safe_isfinite(val))
return next((val for val in obj if safe_isfinite(val)), safe_first_element(obj))


def sanitize_sequence(data):
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_cbook.py