From 59096357bcf43cfd3243498a1ae5761585b3ce16 Mon Sep 17 00:00:00 2001 From: Aleksey Bilogur Date: Sun, 26 Feb 2017 19:28:10 -0500 Subject: [PATCH 1/4] Add unit test for #9351 --- pandas/tests/plotting/test_hist_method.py | 14 ++++++++++++++ pandas/util/testing.py | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 4f64f66bd3c4d..54538ba358812 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -238,6 +238,20 @@ def test_hist_layout(self): with tm.assertRaises(ValueError): df.hist(layout=(-1, -1)) + @slow + def test_tight_layout(self): + tm._skip_if_mpl_1() + + df = DataFrame(randn(100, 2)) + df.plot.hist() + + try: + self.plt.tight_layout() + except AttributeError: + raise + + tm.close() + @tm.mplskip class TestDataFrameGroupByPlots(TestPlotBase): diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 1bd539469dbe3..cf0ddf184dcf6 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -286,6 +286,14 @@ def _skip_if_mpl_1_5(): pytest.skip("matplotlib 1.5") +def _skip_if_mpl_1(): + import matplotlib + v = matplotlib.__version__ + if v < LooseVersion('2.0.0') or v[0] == '0' or v[0] == '1': + import pytest + pytest.skip("matplotlib 1.5") + + def _skip_if_no_scipy(): try: import scipy.stats # noqa From fc0c17789b832c51fadcf32392742fedfb4d1309 Mon Sep 17 00:00:00 2001 From: Aleksey Bilogur Date: Sun, 26 Feb 2017 19:42:49 -0500 Subject: [PATCH 2/4] Tweaks. --- pandas/tests/plotting/test_hist_method.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 54538ba358812..fd02ceed88bae 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -239,18 +239,14 @@ def test_hist_layout(self): df.hist(layout=(-1, -1)) @slow + # GH 9351 def test_tight_layout(self): - tm._skip_if_mpl_1() - - df = DataFrame(randn(100, 2)) - df.plot.hist() - - try: + if self.mpl_ge_2_0_0: + df = DataFrame(randn(100, 2)) + df.plot.hist() self.plt.tight_layout() - except AttributeError: - raise - tm.close() + tm.close() @tm.mplskip From 02a8eff68a06aa6aaa74a79975dd94227028546a Mon Sep 17 00:00:00 2001 From: Aleksey Bilogur Date: Mon, 27 Feb 2017 11:06:21 -0500 Subject: [PATCH 3/4] add _check_plot_works; rm aux method --- pandas/tests/plotting/test_hist_method.py | 2 +- pandas/util/testing.py | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index fd02ceed88bae..22de7055e3cea 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -243,7 +243,7 @@ def test_hist_layout(self): def test_tight_layout(self): if self.mpl_ge_2_0_0: df = DataFrame(randn(100, 2)) - df.plot.hist() + _check_plot_works(df.hist) self.plt.tight_layout() tm.close() diff --git a/pandas/util/testing.py b/pandas/util/testing.py index cf0ddf184dcf6..1bd539469dbe3 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -286,14 +286,6 @@ def _skip_if_mpl_1_5(): pytest.skip("matplotlib 1.5") -def _skip_if_mpl_1(): - import matplotlib - v = matplotlib.__version__ - if v < LooseVersion('2.0.0') or v[0] == '0' or v[0] == '1': - import pytest - pytest.skip("matplotlib 1.5") - - def _skip_if_no_scipy(): try: import scipy.stats # noqa From 809d8473677bce11dd780ecb332b130c3b523c9a Mon Sep 17 00:00:00 2001 From: Aleksey Bilogur Date: Mon, 27 Feb 2017 11:14:18 -0500 Subject: [PATCH 4/4] Add whatsnew entry. --- doc/source/whatsnew/v0.20.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index c94429b469641..f601e0558740f 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -626,7 +626,7 @@ Bug Fixes - +- Bug in ``DataFrame.hist`` where ``plt.tight_layout`` caused an ``AttributeError`` (use ``matplotlib >= 0.2.0``) (:issue:`9351`) - Bug in ``DataFrame.boxplot`` where ``fontsize`` was not applied to the tick labels on both axes (:issue:`15108`) - Bug in ``Series.replace`` and ``DataFrame.replace`` which failed on empty replacement dicts (:issue:`15289`) - Bug in ``pd.melt()`` where passing a tuple value for ``value_vars`` caused a ``TypeError`` (:issue:`15348`)