FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Backport PR #24149 on branch v3.6.x (FIX: handle input to ax.bar that is all nan) by meeseeksmachine · Pull Request #24151 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 8 additions & 0 deletions lib/matplotlib/axes/_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2182,11 +2182,19 @@ 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
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8144,3 +8144,16 @@ def test_bar_leading_nan():
for b in rest:
assert np.isfinite(b.xy).all()
assert np.isfinite(b.get_width())


@check_figures_equal(extensions=["png"])
def test_bar_all_nan(fig_test, fig_ref):
mpl.style.use("mpl20")
ax_test = fig_test.subplots()
ax_ref = fig_ref.subplots()

ax_test.bar([np.nan], [np.nan])
ax_test.bar([1], [1])

ax_ref.bar([1], [1]).remove()
ax_ref.bar([1], [1])

Back | FazBrowse Home | New Git URL