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

Commitb61bb0b

Browse files
authored
Merge pull request#25547 from rcomer/safe_first_finite
FIX: `_safe_first_finite` on all non-finite array
2 parentsa179199 +f8bc604 commitb61bb0b

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

‎lib/matplotlib/axes/_axes.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,19 +2243,11 @@ def _convert_dx(dx, x0, xconv, convert):
22432243
x0=cbook._safe_first_finite(x0)
22442244
except (TypeError,IndexError,KeyError):
22452245
pass
2246-
exceptStopIteration:
2247-
# this means we found no finite element, fall back to first
2248-
# element unconditionally
2249-
x0=cbook.safe_first_element(x0)
22502246

22512247
try:
22522248
x=cbook._safe_first_finite(xconv)
22532249
except (TypeError,IndexError,KeyError):
22542250
x=xconv
2255-
exceptStopIteration:
2256-
# this means we found no finite element, fall back to first
2257-
# element unconditionally
2258-
x=cbook.safe_first_element(xconv)
22592251

22602252
delist=False
22612253
ifnotnp.iterable(dx):

‎lib/matplotlib/cbook.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,13 +1619,13 @@ def safe_first_element(obj):
16191619

16201620
def_safe_first_finite(obj,*,skip_nonfinite=True):
16211621
"""
1622-
Return the first non-None (and optionally finite) element in *obj*.
1622+
Return the first finite element in *obj* if one is available and skip_nonfinite is
1623+
True. Otherwise return the first element.
16231624
16241625
This is a method for internal use.
16251626
1626-
This is a type-independent way of obtaining the first non-None element,
1627-
supporting both index access and the iterator protocol.
1628-
The first non-None element will be obtained when skip_none is True.
1627+
This is a type-independent way of obtaining the first finite element, supporting
1628+
both index access and the iterator protocol.
16291629
"""
16301630
defsafe_isfinite(val):
16311631
ifvalisNone:
@@ -1657,7 +1657,7 @@ def safe_isfinite(val):
16571657
raiseRuntimeError("matplotlib does not "
16581658
"support generators as input")
16591659
else:
1660-
returnnext(valforvalinobjifsafe_isfinite(val))
1660+
returnnext((valforvalinobjifsafe_isfinite(val)),safe_first_element(obj))
16611661

16621662

16631663
defsanitize_sequence(data):

‎lib/matplotlib/tests/test_cbook.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,18 @@ def test_flatiter():
611611
assert1==next(it)
612612

613613

614+
deftest__safe_first_finite_all_nan():
615+
arr=np.full(2,np.nan)
616+
ret=cbook._safe_first_finite(arr)
617+
assertnp.isnan(ret)
618+
619+
620+
deftest__safe_first_finite_all_inf():
621+
arr=np.full(2,np.inf)
622+
ret=cbook._safe_first_finite(arr)
623+
assertnp.isinf(ret)
624+
625+
614626
deftest_reshape2d():
615627

616628
classDummy:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp