Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Backport PR #25547 on branch v3.7.x (FIX:_safe_first_finite on all non-finite array)#25879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall 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 deletionslib/matplotlib/axes/_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2208,19 +2208,11 @@ def _convert_dx(dx, x0, xconv, convert):
x0 = cbook._safe_first_finite(x0)
except (TypeError, IndexError, KeyError):
pass
except StopIteration:
# this means we found no finite element, fall back to first
# element unconditionally
x0 = cbook.safe_first_element(x0)

try:
x = cbook._safe_first_finite(xconv)
except (TypeError, IndexError, KeyError):
x = xconv
except StopIteration:
# this means we found no finite element, fall back to first
# element unconditionally
x = cbook.safe_first_element(xconv)

delist = False
if not np.iterable(dx):
Expand Down
10 changes: 5 additions & 5 deletionslib/matplotlib/cbook/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1676,13 +1676,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 DownExpand Up@@ -1714,7 +1714,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 deletionslib/matplotlib/tests/test_cbook.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -609,6 +609,18 @@ def test_flatiter():
assert 1 == next(it)


def test__safe_first_finite_all_nan():
arr = np.full(2, np.nan)
ret = cbook._safe_first_finite(arr)
assert np.isnan(ret)


def test__safe_first_finite_all_inf():
arr = np.full(2, np.inf)
ret = cbook._safe_first_finite(arr)
assert np.isinf(ret)


def test_reshape2d():

class Dummy:
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp