-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Fix #21101 Add validator to errorbar method #21266
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
Changes from 7 commits
de1e5ba
ec1da3b
3496ba2
e2381b5
11b1c4b
9b5bbe7
b025271
ced1eb2
8f63438
9d182ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -3180,7 +3180,7 @@ def errorbar(self, x, y, yerr=None, xerr=None, | |||
| errors. | ||||
| - *None*: No errorbar. | ||||
|
|
||||
| Note that all error arrays should have *positive* values. | ||||
| Note that all error arrays should have *non-negative* values. | ||||
|
|
||||
| See :doc:`/gallery/statistics/errorbar_features` | ||||
| for an example on the usage of ``xerr`` and ``yerr``. | ||||
|
|
@@ -3284,6 +3284,22 @@ 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: | ||||
| pass # Don't fail on 'datetime.*' types | ||||
| if np.any(array < 0): | ||||
| return True | ||||
| except TypeError: # Don't fail on 'datetime.*' types | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unclear to me why we wouldn't want to fail with datetime types. After all you can't add datetimes so using them as x/yerr should fail, afaict (you can add a datetime to a timedelta, but timedeltas can be meaningfully compared to zero).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @anntzer! Yeah, I added this line to not fail on matplotlib/lib/matplotlib/tests/test_units.py Line 174 in 6d56592
I've assumed that it's always positive. Let me see if there is a way to check that they are "meaningful compared to zero".
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I was thinking about np.timedelta, not datetime.timedelta, sorry for the careless reading (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @anntzer I've added a check for timedelta types. However, I'm a bit uncomfortable with checking only
Do you mean, that there is a way to convert anything to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree the special-casing is a bit annoying, I don't have any good solution to offer right now though. |
||||
| pass | ||||
|
|
||||
| if has_negative_values(xerr) or has_negative_values(yerr): | ||||
| raise ValueError( | ||||
| "'xerr' and 'yerr' must have non-negative numbers") | ||||
|
|
||||
| if isinstance(errorevery, Integral): | ||||
| errorevery = (0, errorevery) | ||||
| if isinstance(errorevery, tuple): | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.