From bc5c3a4faa20963db9b9366f60eb921e62123eb4 Mon Sep 17 00:00:00 2001 From: sinhrks Date: Sun, 25 May 2014 20:26:41 +0900 Subject: [PATCH] BUG: hist raises TypeError when df contains non numeric column --- doc/source/v0.14.1.txt | 2 ++ pandas/tests/test_graphics.py | 11 +++++------ pandas/tests/test_groupby.py | 14 ++++++-------- pandas/tools/plotting.py | 1 + 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/source/v0.14.1.txt b/doc/source/v0.14.1.txt index 0aa30e536e..f9df328e7f 100644 --- a/doc/source/v0.14.1.txt +++ b/doc/source/v0.14.1.txt @@ -65,3 +65,5 @@ There are no experimental changes in 0.14.1 Bug Fixes ~~~~~~~~~ +- BUG in ``DataFrame.hist`` raises ``TypeError`` when it contains non numeric column (:issue:`7277`) + diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 1b96912573..2aced69bc3 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -1464,14 +1464,12 @@ def test_kde(self): @slow def test_hist(self): - df = DataFrame(randn(100, 4)) - _check_plot_works(df.hist) - _check_plot_works(df.hist, grid=False) + _check_plot_works(self.hist_df.hist) # make sure layout is handled df = DataFrame(randn(100, 3)) - _check_plot_works(df.hist) - axes = df.hist(grid=False) + axes = _check_plot_works(df.hist, grid=False) + self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) self.assertFalse(axes[1, 1].get_visible()) df = DataFrame(randn(100, 1)) @@ -1479,7 +1477,8 @@ def test_hist(self): # make sure layout is handled df = DataFrame(randn(100, 6)) - _check_plot_works(df.hist) + axes = _check_plot_works(df.hist, layout=(4, 2)) + self._check_axes_shape(axes, axes_num=6, layout=(4, 2)) # make sure sharex, sharey is handled _check_plot_works(df.hist, sharex=True, sharey=True) diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index 028334afbd..475f5085d5 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -4086,7 +4086,8 @@ def test_series_groupby_plotting_nominally_works(self): n = 10 weight = Series(np.random.normal(166, 20, size=n)) height = Series(np.random.normal(60, 10, size=n)) - gender = tm.choice(['male', 'female'], size=n) + with tm.RNGContext(42): + gender = tm.choice(['male', 'female'], size=n) weight.groupby(gender).plot() tm.close() @@ -4118,7 +4119,8 @@ def test_frame_groupby_plot_boxplot(self): n = 10 weight = Series(np.random.normal(166, 20, size=n)) height = Series(np.random.normal(60, 10, size=n)) - gender = tm.choice(['male', 'female'], size=n) + with tm.RNGContext(42): + gender = tm.choice(['male', 'female'], size=n) df = DataFrame({'height': height, 'weight': weight, 'gender': gender}) gb = df.groupby('gender') @@ -4136,11 +4138,6 @@ def test_frame_groupby_plot_boxplot(self): res = df.groupby('gender').hist() tm.close() - df2 = df.copy() - df2['gender2'] = df['gender'] - with tm.assertRaisesRegexp(TypeError, '.*str.+float'): - df2.groupby('gender').hist() - @slow def test_frame_groupby_hist(self): _skip_if_mpl_not_installed() @@ -4152,7 +4149,8 @@ def test_frame_groupby_hist(self): n = 10 weight = Series(np.random.normal(166, 20, size=n)) height = Series(np.random.normal(60, 10, size=n)) - gender_int = tm.choice([0, 1], size=n) + with tm.RNGContext(42): + gender_int = tm.choice([0, 1], size=n) df_int = DataFrame({'height': height, 'weight': weight, 'gender': gender_int}) gb = df_int.groupby('gender') diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 00f7a61870..25c7f5a7e6 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -2536,6 +2536,7 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None, if not isinstance(column, (list, np.ndarray)): column = [column] data = data[column] + data = data._get_numeric_data() naxes = len(data.columns) nrows, ncols = _get_layout(naxes, layout=layout)