8000 FIX #30007: Raise ValueError when all wedge sizes are zero in ax.pie … · QuLogic/matplotlib@9174093 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9174093

Browse files
authored
FIX matplotlib#30007: Raise ValueError when all wedge sizes are zero in ax.pie (matplotlib#30019)
* Added a condition that throws a ValueError if all wedges are zero * Removed "=" and added "==" for the condition statement * Added a test case with all wedges as zero * Fixed linting issue using pre-commit * Adding more linting changes missed by pre-commit * Running pre-commit hook again to remove the error
1 parent 2d87c95 commit 9174093

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,6 +3308,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
33083308

33093309
sx = x.sum()
33103310

3311+
if sx == 0:
3312+
raise ValueError('All wedge sizes are zero')
3313+
33113314
if normalize:
33123315
x = x / sx
33133316
elif sx > 1:

lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9747,3 +9747,9 @@ def test_pie_non_finite_values():
97479747

97489748
with pytest.raises(ValueError, match='Wedge sizes must be finite numbers'):
97499749
ax.pie(df, labels=['A', 'B', 'C'])
9750+
9751+
9752+
def test_pie_all_zeros():
9753+
fig, ax = plt.subplots()
9754+
with pytest.raises(ValueError, match="All wedge sizes are zero"):
9755+
ax.pie([0, 0], labels=["A", "B"])

0 commit comments

Comments
 (0)
0