Skip to content

Commit 3d34092

Browse files
authored
Merge pull request matplotlib#29873 from AdarshDec/bugfix/29860-handle-nan-inf
Handled non finite values in ax.pie - issue matplotlib#29860
2 parents 5fd55b4 + ca40674 commit 3d34092

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/matplotlib/axes/_axes.py

+3
Original file line numberDiff line numberDiff line change
@@ -3303,6 +3303,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
33033303
if np.any(x < 0):
33043304
raise ValueError("Wedge sizes 'x' must be non negative values")
33053305

3306+
if not np.all(np.isfinite(x)):
3307+
raise ValueError('Wedge sizes must be finite numbers')
3308+
33063309
sx = x.sum()
33073310

33083311
if normalize:

lib/matplotlib/tests/test_axes.py

+8
Original file line numberDiff line numberDiff line change
@@ -9731,3 +9731,11 @@ def test_bar_shape_mismatch():
97319731
)
97329732
with pytest.raises(ValueError, match=error_message):
97339733
plt.bar(x, height)
9734+
9735+
9736+
def test_pie_non_finite_values():
9737+
fig, ax = plt.subplots()
9738+
df = [5, float('nan'), float('inf')]
9739+
9740+
with pytest.raises(ValueError, match='Wedge sizes must be finite numbers'):
9741+
ax.pie(df, labels=['A', 'B', 'C'])

0 commit comments

Comments
 (0)