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

Skip to content

Commit b025271

Browse files
committed
fix wording & simplify function
1 parent 9b5bbe7 commit b025271

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,7 +3180,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
31803180
errors.
31813181
- *None*: No errorbar.
31823182
3183-
Note that all error arrays should have *positive* values.
3183+
Note that all error arrays should have *non-negative* values.
31843184
31853185
See :doc:`/gallery/statistics/errorbar_features`
31863186
for an example on the usage of ``xerr`` and ``yerr``.
@@ -3284,17 +3284,21 @@ def errorbar(self, x, y, yerr=None, xerr=None,
32843284
if len(x) != len(y):
32853285
raise ValueError("'x' and 'y' must have the same size")
32863286

3287-
def check_if_negative(array):
3287+
def has_negative_values(array):
32883288
if array is None:
32893289
return False
32903290
try:
3291+
return np.any(array < 0)
3292+
except TypeError:
3293+
pass # Don't fail on 'datetime.*' types
32913294
if np.any(array < 0):
32923295
return True
32933296
except TypeError: # Don't fail on 'datetime.*' types
32943297
pass
32953298

3296-
if check_if_negative(xerr) or check_if_negative(yerr):
3297-
raise ValueError("'xerr' and 'yerr' must have positive numbers")
3299+
if has_negative_values(xerr) or has_negative_values(yerr):
3300+
raise ValueError(
3301+
"'xerr' and 'yerr' must have non-negative numbers")
32983302

32993303
if isinstance(errorevery, Integral):
33003304
errorevery = (0, errorevery)

lib/matplotlib/tests/test_axes.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3516,14 +3516,13 @@ def test_errorbar_every_invalid():
35163516
def test_xerr_yerr_positive():
35173517
ax = plt.figure().subplots()
35183518

3519-
with pytest.raises(ValueError,
3520-
match="'xerr' and 'yerr' must have positive numbers"):
3519+
error_message = "'xerr' and 'yerr' must have non-negative numbers"
3520+
3521+
with pytest.raises(ValueError, match=error_message):
35213522
ax.errorbar(x=[0], y=[0], xerr=[[-0.5], [1]], yerr=[[-0.5], [1]])
3522-
with pytest.raises(ValueError,
3523-
match="'xerr' and 'yerr' must have positive numbers"):
3523+
with pytest.raises(ValueError, match=error_message):
35243524
ax.errorbar(x=[0], y=[0], xerr=[[-0.5], [1]])
3525-
with pytest.raises(ValueError,
3526-
match="'xerr' and 'yerr' must have positive numbers"):
3525+
with pytest.raises(ValueError, match=error_message):
35273526
ax.errorbar(x=[0], y=[0], yerr=[[-0.5], [1]])
35283527

35293528

0 commit comments

Comments
 (0)