Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7b80f6c

Browse filesBrowse files
committed
Properly deprecate non-1D inputs to pie().
This PR also restores (... for the duration of the deprecation) the support for non-1D inputs that can be squeezed to a 1D array that was broken with numpy 1.16.
1 parent 8d62769 commit 7b80f6c
Copy full SHA for 7b80f6c

File tree

Expand file treeCollapse file tree

2 files changed

+15
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-2
lines changed
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecations
2+
````````````
3+
4+
Passing a non-1D (typically, (n, 1)-shaped) input to `Axes.pie` is deprecated.
5+
Pass a 1D array instead.

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,11 +2809,19 @@ def pie(self, x, explode=None, labels=None, colors=None,
28092809
The axes aspect ratio can be controlled with `Axes.set_aspect`.
28102810
"""
28112811
self.set_aspect('equal')
2812-
x = np.array(x, np.float32)
2812+
# The use of float32 is "historical", but can't be changed without
2813+
# regenerating the test baselines.
2814+
x = np.asarray(x, np.float32)
2815+
if x.ndim != 1 and x.squeeze().ndim <= 1:
2816+
cbook.warn_deprecated(
2817+
"3.1", message="Non-1D inputs to pie() are currently "
2818+
"squeeze()d, but this behavior is deprecated since %(since)s "
2819+
"and will be removed %(removal)s; pass a 1D array instead.")
2820+
x = np.atleast_1d(x.squeeze())
28132821

28142822
sx = x.sum()
28152823
if sx > 1:
2816-
x /= sx
2824+
x = x / sx
28172825

28182826
if labels is None:
28192827
labels = [''] * len(x)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.