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

Commit98b3fa6

Browse files
ksundenmeeseeksmachine
authored andcommitted
Backport PRmatplotlib#25547: FIX:_safe_first_finite on all non-finite array
1 parentdd380c6 commit98b3fa6

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/__init__.py‎

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

16771677
def_safe_first_finite(obj,*,skip_nonfinite=True):
16781678
"""
1679-
Return the first non-None (and optionally finite) element in *obj*.
1679+
Return the first finite element in *obj* if one is available and skip_nonfinite is
1680+
True. Otherwise return the first element.
16801681
16811682
This is a method for internal use.
16821683
1683-
This is a type-independent way of obtaining the first non-None element,
1684-
supporting both index access and the iterator protocol.
1685-
The first non-None element will be obtained when skip_none is True.
1684+
This is a type-independent way of obtaining the first finite element, supporting
1685+
both index access and the iterator protocol.
16861686
"""
16871687
defsafe_isfinite(val):
16881688
ifvalisNone:
@@ -1714,7 +1714,7 @@ def safe_isfinite(val):
17141714
raiseRuntimeError("matplotlib does not "
17151715
"support generators as input")
17161716
else:
1717-
returnnext(valforvalinobjifsafe_isfinite(val))
1717+
returnnext((valforvalinobjifsafe_isfinite(val)),safe_first_element(obj))
17181718

17191719

17201720
defsanitize_sequence(data):

‎lib/matplotlib/tests/test_cbook.py‎

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

611611

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

614626
classDummy:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp