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

Skip to content

Commit ab67ee1

Browse files
committed
Check that xerr/yerr values are not None in errorbar
1 parent 88e4a43 commit ab67ee1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,6 +3682,11 @@ def apply_mask(arrays, mask):
36823682
f"'{dep_axis}err' (shape: {np.shape(err)}) must be a "
36833683
f"scalar or a 1D or (2, n) array-like whose shape matches "
36843684
f"'{dep_axis}' (shape: {np.shape(dep)})") from None
3685+
if err.dtype is np.dtype(object) and np.any(err == None): # noqa: E711
3686+
raise ValueError(
3687+
f"'{dep_axis}err' must not contain None. "
3688+
"Use NaN if you want to skip a value.")
3689+
36853690
res = np.zeros(err.shape, dtype=bool) # Default in case of nan
36863691
if np.any(np.less(err, -err, out=res, where=(err == err))):
36873692
# like err<0, but also works for timedelta and nan.

lib/matplotlib/tests/test_axes.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,6 +4127,20 @@ def test_xerr_yerr_not_negative():
41274127
yerr=datetime.timedelta(days=-10))
41284128

41294129

4130+
def test_xerr_yerr_not_none():
4131+
ax = plt.figure().subplots()
4132+
4133+
with pytest.raises(ValueError,
4134+
match="'xerr' must not contain None"):
4135+
ax.errorbar(x=[0], y=[0], xerr=[[None], [1]], yerr=[[None], [1]])
4136+
with pytest.raises(ValueError,
4137+
match="'xerr' must not contain None"):
4138+
ax.errorbar(x=[0], y=[0], xerr=[[None], [1]])
4139+
with pytest.raises(ValueError,
4140+
match="'yerr' must not contain None"):
4141+
ax.errorbar(x=[0], y=[0], yerr=[[None], [1]])
4142+
4143+
41304144
@check_figures_equal()
41314145
def test_errorbar_every(fig_test, fig_ref):
41324146
x = np.linspace(0, 1, 15)

0 commit comments

Comments
 (0)