Skip to content

Commit a8b5798

Browse files
s-cellesjreback
authored andcommitted
BUG: Series.hist raises with a one-row Series #110214
1 parent 38876df commit a8b5798

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/whatsnew/v0.16.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Performance Improvements
116116
Bug Fixes
117117
~~~~~~~~~
118118

119+
- Bug in ``Series.hist`` raises an error when a one row ``Series`` was given (:issue:`10214`)
119120
- Bug where read_hdf store.select modifies the passed columns list when
120121
multi-indexed (:issue:`7212`)
121122
- Bug in ``Categorical`` repr with ``display.width`` of ``None`` in Python 3 (:issue:`10087`)

pandas/tests/test_graphics.py

+8
Original file line numberDiff line numberDiff line change
@@ -3896,6 +3896,14 @@ def test_plotting_with_float_index_works(self):
38963896
df.groupby('def')['val'].apply(lambda x: x.plot())
38973897
tm.close()
38983898

3899+
def test_hist_single_row(self):
3900+
# GH10214
3901+
bins = np.arange(80, 100 + 2, 1)
3902+
df = DataFrame({"Name": ["AAA", "BBB"], "ByCol": [1, 2], "Mark": [85, 89]})
3903+
df["Mark"].hist(by=df["ByCol"], bins=bins)
3904+
df = DataFrame({"Name": ["AAA"], "ByCol": [1], "Mark": [85]})
3905+
df["Mark"].hist(by=df["ByCol"], bins=bins)
3906+
38993907

39003908
def assert_is_valid_plot_return_object(objs):
39013909
import matplotlib.pyplot as plt

pandas/tools/plotting.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2846,8 +2846,9 @@ def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
28462846
xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot,
28472847
**kwds)
28482848

2849-
if axes.ndim == 1 and len(axes) == 1:
2850-
return axes[0]
2849+
if hasattr(axes, 'ndim'):
2850+
if axes.ndim == 1 and len(axes) == 1:
2851+
return axes[0]
28512852
return axes
28522853

28532854

0 commit comments

Comments
 (0)