Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3303,6 +3303,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
if np.any(x < 0):
raise ValueError("Wedge sizes 'x' must be non negative values")

if not np.all(np.isfinite(x)):
raise ValueError('Wedge sizes must be finite numbers')

sx = x.sum()

if normalize:
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9720,3 +9720,11 @@ def test_bar_shape_mismatch():
)
with pytest.raises(ValueError, match=error_message):
plt.bar(x, height)


def test_pie_non_finite_values():
fig, ax = plt.subplots()
df = [5, float('nan'), float('inf')]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
df = [5, float('nan'), float('inf')]
values = [5, float('nan'), float('inf')]

Optional. df is typically used as variable name for dataframes, so it's slightly misleading here.


with pytest.raises(ValueError, match='Wedge sizes must be finite numbers'):
ax.pie(df, labels=['A', 'B', 'C'])
Loading