FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Raise an ValueError when Axes.pie accepts negative values #15923 by Inception95 · Pull Request #15935 · matplotlib/matplotlib · GitHub

Repository navigation

Raise an ValueError when Axes.pie accepts negative values #15923 - #15935

Merged
anntzer merged 2 commits into
matplotlib:masterfrom
Inception95:pie_takes_negative_values
Dec 14, 2019
Merged

anntzer merged 2 commits into
matplotlib:masterfrom
Inception95:pie_takes_negative_values

Conversation

Inception95 commented Dec 14, 2019 •
edited
Loading

Copy link
Copy Markdown
Contributor

PR Summary

Issue #15923
Axes.pie accepts negative values which outputs the wrong pie chart. This issue is caused by not checking the positive and negative of all input wedge sizes of "x" in Axes.pie.

Now it will raise a ValueError, which indicates wedge sizes should be non-negative when feeding negative values into Axes.pie. It is done by adding an if condition right before calculating the portion of all sizes in the "x" `array.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Comment thread lib/matplotlib/axes/_axes.py Outdated
"and will be removed %(removal)s; pass a 1D array instead.")
x = np.atleast_1d(x.squeeze())

for part in x:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think you can use np.any?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks, np.any(x<0) is neater!

jklymak commented Dec 14, 2019

Copy link
Copy Markdown
Member

Thanks for the PR. This should probably get a test as well...

Copy link
Copy Markdown
Contributor Author

@jklymak Sure, I will add the test.

jklymak added this to the v3.3.0 milestone Dec 14, 2019
jklymak added the API: argument checking Validation of acceptable argument values label Dec 14, 2019

anntzer commented Dec 14, 2019

Copy link
Copy Markdown
Contributor

Thanks for you contribution, hoping to see you around again :)

anntzer merged commit b12c761 into matplotlib:master Dec 14, 2019

Copy link
Copy Markdown
Contributor Author

@anntzer Happy to help! Thanks for this great opportunity.

Inception95 deleted the pie_takes_negative_values branch December 14, 2019 17:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API: argument checking Validation of acceptable argument values

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL