Skip to content

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

Merged
merged 10 commits into from
Oct 5, 2021

Conversation

Kislovskiy
Copy link
Contributor

PR Summary

The PR adds a validator for xerr and yerr arguments in errorbar method to fix #21101.

It brings implementation compliant with the documentation:

Note that all error arrays should have positive values.

source: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_axes.py#L3183

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@jklymak jklymak added this to the v3.6.0 milestone Oct 4, 2021
try:
if np.any(array < 0):
return True
except TypeError: # Don't fail on 'datetime.*' types
Copy link
Contributor

Choose a reason for hiding this comment

The 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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @anntzer! Yeah, I added this line to not fail on datetime.timedelta

ax.errorbar(x, y, timedelta(days=0.5))

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".

Copy link
Contributor

Choose a reason for hiding this comment

The 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 (np.timedelta(...) > 0 works). Well, I guess my point remains: it would be nice to have the check also for datetime.timedelta inputs, but I don't know how easy that is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 timedelta type. datetime.datetime handles only positive values -> should not be an issue. What about datetime.date?

you can add a datetime to a timedelta

Do you mean, that there is a way to convert anything to timedelta and check it? If yes, could you elaborate a bit more?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@timhoffm timhoffm merged commit e37902e into matplotlib:master Oct 5, 2021
@timhoffm
Copy link
Member

timhoffm commented Oct 5, 2021

Thanks @Kislovskiy, and congratulations on your first contribution to Matplotlib. We hope to see you again.

@Kislovskiy
Copy link
Contributor Author

Thanks @timhoffm @jklymak @anntzer for the review! Very appreciate your input

@Kislovskiy Kislovskiy deleted the fix-21101 branch October 5, 2021 15:40
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Oct 12, 2021
tacaswell pushed a commit that referenced this pull request Oct 20, 2021
Fix #21101 Add validator to errorbar method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Errorbars separated from markers with negative errors
4 participants