Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0d64ff

Browse files
committed
Add test code and change negative number detect
1 parent 1e23003 commit d0d64ff

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,9 +2921,8 @@ def pie(self, x, explode=None, labels=None, colors=None,
29212921
"and will be removed %(removal)s; pass a 1D array instead.")
29222922
x = np.atleast_1d(x.squeeze())
29232923

2924-
for part in x:
2925-
if part < 0:
2926-
raise ValueError("wedge sizes must be non negative values")
2924+
if np.any(x < 0):
2925+
raise ValueError("wedge sizes must be non negative values")
29272926

29282927
sx = x.sum()
29292928
if sx > 1:

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6849,3 +6849,10 @@ def test_bbox_aspect_axes_init():
68496849
sizes.extend([bb.width, bb.height])
68506850

68516851
assert_allclose(sizes, sizes[0])
6852+
6853+
6854+
def test_pi_get_negative_values():
6855+
# Test the ValueError raised when feeding negative values into axes.pie
6856+
fig, ax = plt.subplots()
6857+
with pytest.raises(ValueError):
6858+
ax.pie([5, 5, -3], explode=[0, .1, .2])

0 commit comments

Comments
 (0)