Skip to content

Commit fa0f78f

Browse files
sinhrksTomAugspurger
authored and
TomAugspurger
committed
BUG: hist raises TypeError when df contains non numeric column
1 parent 4adc6fa commit fa0f78f

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

doc/source/v0.14.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ Bug Fixes
6969
- Bug in ``TimeGrouper`` doesn't exclude column specified by ``key`` (:issue:`7227`)
7070
- Bug in ``DataFrame`` and ``Series`` bar and barh plot raises ``TypeError`` when ``bottom``
7171
and ``left`` keyword is specified (:issue:`7226`)
72+
- BUG in ``DataFrame.hist`` raises ``TypeError`` when it contains non numeric column (:issue:`7277`)

pandas/tests/test_graphics.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1493,22 +1493,21 @@ def test_kde(self):
14931493

14941494
@slow
14951495
def test_hist(self):
1496-
df = DataFrame(randn(100, 4))
1497-
_check_plot_works(df.hist)
1498-
_check_plot_works(df.hist, grid=False)
1496+
_check_plot_works(self.hist_df.hist)
14991497

15001498
# make sure layout is handled
15011499
df = DataFrame(randn(100, 3))
1502-
_check_plot_works(df.hist)
1503-
axes = df.hist(grid=False)
1500+
axes = _check_plot_works(df.hist, grid=False)
1501+
self._check_axes_shape(axes, axes_num=3, layout=(2, 2))
15041502
self.assertFalse(axes[1, 1].get_visible())
15051503

15061504
df = DataFrame(randn(100, 1))
15071505
_check_plot_works(df.hist)
15081506

15091507
# make sure layout is handled
15101508
df = DataFrame(randn(100, 6))
1511-
_check_plot_works(df.hist)
1509+
axes = _check_plot_works(df.hist, layout=(4, 2))
1510+
self._check_axes_shape(axes, axes_num=6, layout=(4, 2))
15121511

15131512
# make sure sharex, sharey is handled
15141513
_check_plot_works(df.hist, sharex=True, sharey=True)

pandas/tests/test_groupby.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -4086,7 +4086,8 @@ def test_series_groupby_plotting_nominally_works(self):
40864086
n = 10
40874087
weight = Series(np.random.normal(166, 20, size=n))
40884088
height = Series(np.random.normal(60, 10, size=n))
4089-
gender = tm.choice(['male', 'female'], size=n)
4089+
with tm.RNGContext(42):
4090+
gender = tm.choice(['male', 'female'], size=n)
40904091

40914092
weight.groupby(gender).plot()
40924093
tm.close()
@@ -4118,7 +4119,8 @@ def test_frame_groupby_plot_boxplot(self):
41184119
n = 10
41194120
weight = Series(np.random.normal(166, 20, size=n))
41204121
height = Series(np.random.normal(60, 10, size=n))
4121-
gender = tm.choice(['male', 'female'], size=n)
4122+
with tm.RNGContext(42):
4123+
gender = tm.choice(['male', 'female'], size=n)
41224124
df = DataFrame({'height': height, 'weight': weight, 'gender': gender})
41234125
gb = df.groupby('gender')
41244126

@@ -4136,11 +4138,6 @@ def test_frame_groupby_plot_boxplot(self):
41364138
res = df.groupby('gender').hist()
41374139
tm.close()
41384140

4139-
df2 = df.copy()
4140-
df2['gender2'] = df['gender']
4141-
with tm.assertRaisesRegexp(TypeError, '.*str.+float'):
4142-
df2.groupby('gender').hist()
4143-
41444141
@slow
41454142
def test_frame_groupby_hist(self):
41464143
_skip_if_mpl_not_installed()
@@ -4152,7 +4149,8 @@ def test_frame_groupby_hist(self):
41524149
n = 10
41534150
weight = Series(np.random.normal(166, 20, size=n))
41544151
height = Series(np.random.normal(60, 10, size=n))
4155-
gender_int = tm.choice([0, 1], size=n)
4152+
with tm.RNGContext(42):
4153+
gender_int = tm.choice([0, 1], size=n)
41564154
df_int = DataFrame({'height': height, 'weight': weight,
41574155
'gender': gender_int})
41584156
gb = df_int.groupby('gender')

pandas/tools/plotting.py

+1
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,7 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
25452545
if not isinstance(column, (list, np.ndarray)):
25462546
column = [column]
25472547
data = data[column]
2548+
data = data._get_numeric_data()
25482549
naxes = len(data.columns)
25492550

25502551
nrows, ncols = _get_layout(naxes, layout=layout)

0 commit comments

Comments
 (0)