diff --git a/pandas/plotting/_compat.py b/pandas/plotting/_compat.py index 7b04b9e1171ec..d527bc08e2f08 100644 --- a/pandas/plotting/_compat.py +++ b/pandas/plotting/_compat.py @@ -65,3 +65,11 @@ def _mpl_ge_2_0_1(): return matplotlib.__version__ >= LooseVersion('2.0.1') except ImportError: return False + + +def _mpl_ge_2_1_0(): + try: + import matplotlib + return matplotlib.__version__ >= LooseVersion('2.1') + except ImportError: + return False diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 211d9777e7515..c4cd562df7eb3 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2000,7 +2000,7 @@ def maybe_color_bp(bp): def plot_group(keys, values, ax): keys = [pprint_thing(x) for x in keys] - values = [remove_na_arraylike(v) for v in values] + values = [np.asarray(remove_na_arraylike(v)) for v in values] bp = ax.boxplot(values, **kwds) if fontsize is not None: ax.tick_params(axis='both', labelsize=fontsize) diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index 8fe119d28644c..4b1cb2ccbd3dd 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -11,7 +11,6 @@ import numpy as np from numpy import random -from numpy.random import randn import pandas.plotting as plotting @@ -35,8 +34,8 @@ def _skip_if_mpl_14_or_dev_boxplot(): class TestDataFramePlots(TestPlotBase): @pytest.mark.slow - def test_boxplot_legacy(self): - df = DataFrame(randn(6, 4), + def test_boxplot_legacy1(self): + df = DataFrame(np.random.randn(6, 4), index=list(string.ascii_letters[:6]), columns=['one', 'two', 'three', 'four']) df['indic'] = ['foo', 'bar'] * 3 @@ -60,6 +59,8 @@ def test_boxplot_legacy(self): with tm.assert_produces_warning(UserWarning): _check_plot_works(df.boxplot, by='indic', notch=1) + @pytest.mark.slow + def test_boxplot_legacy2(self): df = DataFrame(np.random.rand(10, 2), columns=['Col1', 'Col2']) df['X'] = Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B']) df['Y'] = Series(['A'] * 10) @@ -103,7 +104,7 @@ def test_boxplot_return_type_legacy(self): # API change in https://github.com/pandas-dev/pandas/pull/7096 import matplotlib as mpl # noqa - df = DataFrame(randn(6, 4), + df = DataFrame(np.random.randn(6, 4), index=list(string.ascii_letters[:6]), columns=['one', 'two', 'three', 'four']) with pytest.raises(ValueError): @@ -176,7 +177,7 @@ def test_fontsize(self): class TestDataFrameGroupByPlots(TestPlotBase): @pytest.mark.slow - def test_boxplot_legacy(self): + def test_boxplot_legacy1(self): grouped = self.hist_df.groupby(by='gender') with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(grouped.boxplot, return_type='axes') @@ -184,10 +185,12 @@ def test_boxplot_legacy(self): axes = _check_plot_works(grouped.boxplot, subplots=False, return_type='axes') self._check_axes_shape(axes, axes_num=1, layout=(1, 1)) + + @pytest.mark.slow + def test_boxplot_legacy2(self): tuples = lzip(string.ascii_letters[:10], range(10)) df = DataFrame(np.random.rand(10, 3), index=MultiIndex.from_tuples(tuples)) - grouped = df.groupby(level=1) with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(grouped.boxplot, return_type='axes') @@ -197,6 +200,11 @@ def test_boxplot_legacy(self): return_type='axes') self._check_axes_shape(axes, axes_num=1, layout=(1, 1)) + @pytest.mark.slow + def test_boxplot_legacy3(self): + tuples = lzip(string.ascii_letters[:10], range(10)) + df = DataFrame(np.random.rand(10, 3), + index=MultiIndex.from_tuples(tuples)) grouped = df.unstack(level=1).groupby(level=0, axis=1) with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(grouped.boxplot, return_type='axes')