Skip to content

Commit 6ff8434

Browse files
authored
TST: cleanup warnings on mpl 2.1 (#17835)
1 parent 390f36e commit 6ff8434

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

pandas/plotting/_compat.py

+8
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,11 @@ def _mpl_ge_2_0_1():
6565
return matplotlib.__version__ >= LooseVersion('2.0.1')
6666
except ImportError:
6767
return False
68+
69+
70+
def _mpl_ge_2_1_0():
71+
try:
72+
import matplotlib
73+
return matplotlib.__version__ >= LooseVersion('2.1')
74+
except ImportError:
75+
return False

pandas/plotting/_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ def maybe_color_bp(bp):
20002000

20012001
def plot_group(keys, values, ax):
20022002
keys = [pprint_thing(x) for x in keys]
2003-
values = [remove_na_arraylike(v) for v in values]
2003+
values = [np.asarray(remove_na_arraylike(v)) for v in values]
20042004
bp = ax.boxplot(values, **kwds)
20052005
if fontsize is not None:
20062006
ax.tick_params(axis='both', labelsize=fontsize)

pandas/tests/plotting/test_boxplot_method.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import numpy as np
1313
from numpy import random
14-
from numpy.random import randn
1514

1615
import pandas.plotting as plotting
1716

@@ -35,8 +34,8 @@ def _skip_if_mpl_14_or_dev_boxplot():
3534
class TestDataFramePlots(TestPlotBase):
3635

3736
@pytest.mark.slow
38-
def test_boxplot_legacy(self):
39-
df = DataFrame(randn(6, 4),
37+
def test_boxplot_legacy1(self):
38+
df = DataFrame(np.random.randn(6, 4),
4039
index=list(string.ascii_letters[:6]),
4140
columns=['one', 'two', 'three', 'four'])
4241
df['indic'] = ['foo', 'bar'] * 3
@@ -60,6 +59,8 @@ def test_boxplot_legacy(self):
6059
with tm.assert_produces_warning(UserWarning):
6160
_check_plot_works(df.boxplot, by='indic', notch=1)
6261

62+
@pytest.mark.slow
63+
def test_boxplot_legacy2(self):
6364
df = DataFrame(np.random.rand(10, 2), columns=['Col1', 'Col2'])
6465
df['X'] = Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B'])
6566
df['Y'] = Series(['A'] * 10)
@@ -103,7 +104,7 @@ def test_boxplot_return_type_legacy(self):
103104
# API change in https://github.com/pandas-dev/pandas/pull/7096
104105
import matplotlib as mpl # noqa
105106

106-
df = DataFrame(randn(6, 4),
107+
df = DataFrame(np.random.randn(6, 4),
107108
index=list(string.ascii_letters[:6]),
108109
columns=['one', 'two', 'three', 'four'])
109110
with pytest.raises(ValueError):
@@ -176,18 +177,20 @@ def test_fontsize(self):
176177
class TestDataFrameGroupByPlots(TestPlotBase):
177178

178179
@pytest.mark.slow
179-
def test_boxplot_legacy(self):
180+
def test_boxplot_legacy1(self):
180181
grouped = self.hist_df.groupby(by='gender')
181182
with tm.assert_produces_warning(UserWarning):
182183
axes = _check_plot_works(grouped.boxplot, return_type='axes')
183184
self._check_axes_shape(list(axes.values), axes_num=2, layout=(1, 2))
184185
axes = _check_plot_works(grouped.boxplot, subplots=False,
185186
return_type='axes')
186187
self._check_axes_shape(axes, axes_num=1, layout=(1, 1))
188+
189+
@pytest.mark.slow
190+
def test_boxplot_legacy2(self):
187191
tuples = lzip(string.ascii_letters[:10], range(10))
188192
df = DataFrame(np.random.rand(10, 3),
189193
index=MultiIndex.from_tuples(tuples))
190-
191194
grouped = df.groupby(level=1)
192195
with tm.assert_produces_warning(UserWarning):
193196
axes = _check_plot_works(grouped.boxplot, return_type='axes')
@@ -197,6 +200,11 @@ def test_boxplot_legacy(self):
197200
return_type='axes')
198201
self._check_axes_shape(axes, axes_num=1, layout=(1, 1))
199202

203+
@pytest.mark.slow
204+
def test_boxplot_legacy3(self):
205+
tuples = lzip(string.ascii_letters[:10], range(10))
206+
df = DataFrame(np.random.rand(10, 3),
207+
index=MultiIndex.from_tuples(tuples))
200208
grouped = df.unstack(level=1).groupby(level=0, axis=1)
201209
with tm.assert_produces_warning(UserWarning):
202210
axes = _check_plot_works(grouped.boxplot, return_type='axes')

0 commit comments

Comments
 (0)