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

Commitf8bc604

Browse files
committed
FIX: _safe_first_finite on all non-finite array
1 parent161c96c commitf8bc604

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
@@ -2208,19 +2208,11 @@ def _convert_dx(dx, x0, xconv, convert):
22082208
x0=cbook._safe_first_finite(x0)
22092209
except (TypeError,IndexError,KeyError):
22102210
pass
2211-
exceptStopIteration:
2212-
# this means we found no finite element, fall back to first
2213-
# element unconditionally
2214-
x0=cbook.safe_first_element(x0)
22152211

22162212
try:
22172213
x=cbook._safe_first_finite(xconv)
22182214
except (TypeError,IndexError,KeyError):
22192215
x=xconv
2220-
exceptStopIteration:
2221-
# this means we found no finite element, fall back to first
2222-
# element unconditionally
2223-
x=cbook.safe_first_element(xconv)
22242216

22252217
delist=False
22262218
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
@@ -608,6 +608,18 @@ def test_flatiter():
608608
assert1==next(it)
609609

610610

611+
deftest__safe_first_finite_all_nan():
612+
arr=np.full(2,np.nan)
613+
ret=cbook._safe_first_finite(arr)
614+
assertnp.isnan(ret)
615+
616+
617+
deftest__safe_first_finite_all_inf():
618+
arr=np.full(2,np.inf)
619+
ret=cbook._safe_first_finite(arr)
620+
assertnp.isinf(ret)
621+
622+
611623
deftest_reshape2d():
612624

613625
classDummy:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp