Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d34092

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

File tree

Expand file treeCollapse file tree

2 files changed

+11
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-0
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+3Lines changed: 3 additions & 0 deletions
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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+8Lines changed: 8 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.