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

Skip to content

Simplify test for negative xerr/yerr. #21677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import math
from numbers import Integral, Number
from datetime import timedelta

import numpy as np
from numpy import ma
Expand Down Expand Up @@ -3291,19 +3290,6 @@ def errorbar(self, x, y, yerr=None, xerr=None,
if len(x) != len(y):
raise ValueError("'x' and 'y' must have the same size")

def has_negative_values(array):
if array is None:
return False
try:
return np.any(array < 0)
except TypeError: # if array contains 'datetime.timedelta' types
return np.any(array < timedelta(0))

if has_negative_values(xerr):
raise ValueError("'xerr' must not contain negative values")
if has_negative_values(yerr):
raise ValueError("'yerr' must not contain negative values")

if isinstance(errorevery, Integral):
errorevery = (0, errorevery)
if isinstance(errorevery, tuple):
Expand Down Expand Up @@ -3426,6 +3412,9 @@ def apply_mask(arrays, mask): return [array[mask] for array in arrays]
f"'{dep_axis}err' (shape: {np.shape(err)}) must be a "
f"scalar or a 1D or (2, n) array-like whose shape matches "
f"'{dep_axis}' (shape: {np.shape(dep)})") from None
if np.any(err < -err): # like err<0, but also works for timedelta.
raise ValueError(
f"'{dep_axis}err' must not contain negative values")
# This is like
# elow, ehigh = np.broadcast_to(...)
# return dep - elow * ~lolims, dep + ehigh * ~uplims
Expand Down