8000 Properly deprecate non-1D or string inputs to pie(). · matplotlib/matplotlib@5f1b774 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f1b774

Browse files
committed
Properly deprecate non-1D or string 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 5f1b774

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Deprecations
2+
````````````
3+
4+
Passing a non-1D (typically, (n, 1)-shaped) input, or an array of floats in
5+
"string" form (e.g., ``["0.1", "0.2"]``) to `Axes.pie` is deprecated. Pass a
6+
1D array of floats instead.

lib/matplotlib/axes/_axes.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,7 +2725,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
27252725
27262726
Parameters
27272727
----------
2728-
x : array-like
2728+
x : 1D array-like
27292729
The wedge sizes.
27302730
27312731
explode : array-like, optional, default: None
@@ -2809,11 +2809,24 @@ 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+
x = np.asarray(x)
2813+
if x.ndim != 1 and x.squeeze().ndim <= 1:
2814+
cbook.warn_deprecated(
2815+
"3.1", message="Non-1D inputs to pie() are currently "
2816+
"squeeze()d, but this behavior is deprecated since %(since)s "
2817+
"and will be removed %(removal)s; pass a 1D array instead.")
2818+
x = np.atleast_1d(x.squeeze())
2819+
if x.dtype.kind in "SU":
2820+
x = np.asarray(x, float) # Let the ValueError propagate.
2821+
cbook.warn_deprecated(
2822+
"3.1", message="String inputs to pie() are currently "
2823+
"converted to floats, but this behavior is deprecated since "
2824+
"%(since)s and will be removed %(removal)s; pass an array of "
2825+
"floats instead.")
28132826

28142827
sx = x.sum()
28152828
if sx > 1:
2816-
x /= sx
2829+
x = x / sx
28172830

28182831
if labels is None:
28192832
labels = [''] * len(x)

0 commit comments

Comments
 (0)
0