8000 Properly deprecate non-1D inputs to pie(). by anntzer · Pull Request #13354 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Properly deprecate non-1D inputs to pie(). #13354

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
Feb 7, 2019
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/2018-02-03-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deprecations
````````````

Passing a non-1D (typically, (n, 1)-shaped) input to `Axes.pie` is deprecated.
Pass a 1D array instead.
12 changes: 10 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2809,11 +2809,19 @@ def pie(self, x, explode=None, labels=None, colors=None,
The axes aspect ratio can be controlled with `Axes.set_aspect`.
"""
self.set_aspect('equal')
x = np.array(x, np.float32)
# The use of float32 is "historical", but can't be changed without
# regenerating the test baselines.
x = np.asarray(x, np.float32)
Copy link
Member

Choose a reason for hiding this comment

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

Could be changed to float64, and only patched back in some way to float32 for the tests. But that's beyond this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems not worth the effort, frankly

if x.ndim != 1 and x.squeeze().ndim <= 1:
cbook.warn_deprecated(
"3.1", message="Non-1D inputs to pie() are currently "
"squeeze()d, but this behavior is deprecated since %(since)s "
"and will be removed %(removal)s; pass a 1D array instead.")
x = np.atleast_1d(x.squeeze())

sx = x.sum()
if sx > 1:
x /= sx
x = x / sx

if labels is None:
labels = [''] * len(x)
Expand Down
0