Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

BUG: hist raises TypeError when df contains non numeric column #7277

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+14 −14
Split
View
@@ -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`)
+
@@ -1464,22 +1464,21 @@ 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))
_check_plot_works(df.hist)
# 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)
@@ -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')
View
@@ -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)