Skip to content

Backport PR #30162 on branch v3.10.x (TST: Fix runtime error checking NaN input to format_cursor_data) #30167

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
6 changes: 4 additions & 2 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,9 @@ def _g_sig_digits(value, delta):
Return the number of significant digits to %g-format *value*, assuming that
it is known with an error of *delta*.
"""
# For inf or nan, the precision doesn't matter.
if not math.isfinite(value):
return 0
if delta == 0:
if value == 0:
# if both value and delta are 0, np.spacing below returns 5e-324
Expand All @@ -2221,11 +2224,10 @@ def _g_sig_digits(value, delta):
# digits before the decimal point (floor(log10(45.67)) + 1 = 2): the total
# is 4 significant digits. A value of 0 contributes 1 "digit" before the
# decimal point.
# For inf or nan, the precision doesn't matter.
return max(
0,
(math.floor(math.log10(abs(value))) + 1 if value else 1)
- math.floor(math.log10(delta))) if math.isfinite(value) else 0
- math.floor(math.log10(delta)))


def _unikey_or_keysym_to_mplkey(unikey, keysym):
Expand Down
Loading