8000 handled non finite values in ax.pie · matplotlib/matplotlib@a129589 · GitHub
[go: up one dir, main page]

Skip to content

Commit a129589

Browse files
committed
handled non finite values in ax.pie
1 parent 33dbc47 commit a129589

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3302,8 +3302,10 @@ def pie(self, x, explode=None, labels=None, colors=None,
33023302

33033303
if np.any(x < 0):
33043304
raise ValueError("Wedge sizes 'x' must be non negative values")
3305+
3306+
if not np.all(np.isfinite(x)):
3307+
raise ValueError('Wedge sizes must be finite numbers')
33053308

3306-
sx = x.sum()
33073309

33083310
if normalize:
33093311
x = x / sx

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9720,3 +9720,11 @@ def test_bar_shape_mismatch():
97209720
)
97219721
with pytest.raises(ValueError, match=error_message):
97229722
plt.bar(x, height)
9723+
9724+
9725+
def test_pie_non_finite_values():
9726+
fig, ax = plt.subplots()
9727+
df = [5, float('nan'), float('inf')]
9728+
9729+
with pytest.raises(ValueError, match = 'Wedge sizes must be finite numbers'):
9730+
ax.pie(df, labels=['A', 'B', 'C'])

0 commit comments

Comments
 (0)
0