Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b80f6c

Browse 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

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed
Lines 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

Lines 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)