Skip to content

Commit 75cba1d

Browse files
committed
check None in check_if_negative
1 parent e620e04 commit 75cba1d

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,20 +3285,16 @@ def errorbar(self, x, y, yerr=None, xerr=None,
32853285
raise ValueError("'x' and 'y' must have the same size")
32863286

32873287
def check_if_negative(array):
3288+
if array is None:
3289+
return False
32883290
try:
32893291
if np.any(array < 0):
32903292
return True
32913293
except TypeError: # Don't fail on 'datetime.*' types
32923294
pass
32933295

3294-
if xerr is not None and check_if_negative(xerr):
3295-
if yerr is not None and check_if_negative(yerr):
3296-
raise ValueError(
3297-
"'xerr' and 'yerr' must have positive numbers")
3298-
else:
3299-
raise ValueError("'xerr' must have positive numbers")
3300-
if check_if_negative(yerr):
3301-
raise ValueError("'yerr' must have positive numbers")
3296+
if check_if_negative(xerr) or check_if_negative(yerr):
3297+
raise ValueError("'xerr' and 'yerr' must have positive numbers")
33023298

33033299
if isinstance(errorevery, Integral):
33043300
errorevery = (0, errorevery)

lib/matplotlib/tests/test_axes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,9 +3519,11 @@ def test_xerr_yerr_positive():
35193519
with pytest.raises(ValueError,
35203520
match="'xerr' and 'yerr' must have positive numbers"):
35213521
ax.errorbar(x=[0], y=[0], xerr=[[-0.5], [1]], yerr=[[-0.5], [1]])
3522-
with pytest.raises(ValueError, match="'xerr' must have positive numbers"):
3522+
with pytest.raises(ValueError,
3523+
match="'xerr' and 'yerr' must have positive numbers"):
35233524
ax.errorbar(x=[0], y=[0], xerr=[[-0.5], [1]])
3524-
with pytest.raises(ValueError, match="'yerr' must have positive numbers"):
3525+
with pytest.raises(ValueError,
3526+
match="'xerr' and 'yerr' must have positive numbers"):
35253527
ax.errorbar(x=[0], y=[0], yerr=[[-0.5], [1]])
35263528

35273529

0 commit comments

Comments
 (0)