← 输入框|github.com|刷新
Skip to content

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

@Inception95 Inception95 commented Dec 14, 2019 •

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.

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.

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

@jklymak

jklymak commented Dec 14, 2019

Copy link
Copy Markdown
Member

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

@Inception95

Copy link
Copy Markdown
Contributor Author

@jklymak Sure, I will add the test.

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

anntzer commented Dec 14, 2019

Copy link
Copy Markdown
Contributor

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

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

Copy link
Copy Markdown
Contributor Author

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

@Inception95
Inception95 deleted the pie_takes_negative_values branch December 14, 2019 17:13
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