Skip to content

Commit fb977d7

Browse files
onesandzeroesTomAugspurger
authored and
TomAugspurger
committed
BUG: boxplot fails when one column is all NaNs
Add test case for empty column Replace empty arrays with [np.nan] Add fix to the release notes Add issue numbers
1 parent ef1fb2d commit fb977d7

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/v0.15.0.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ Enhancements
616616

617617
.. code-block:: python
618618

619-
df.to_sql('table', engine, schema='other_schema')
620-
pd.read_sql_table('table', engine, schema='other_schema')
619+
df.to_sql('table', engine, schema='other_schema')
620+
pd.read_sql_table('table', engine, schema='other_schema')
621621

622622
- Added support for writing ``NaN`` values with ``to_sql`` (:issue:`2754`).
623623
- Added support for writing datetime64 columns with ``to_sql`` for all database flavors (:issue:`7103`).
@@ -919,3 +919,4 @@ Bug Fixes
919919
- Bug with ``DatetimeIndex.asof`` incorrectly matching partial strings and returning the wrong date (:issue:`8245`).
920920
- Bug in plotting methods modifying the global matplotlib rcParams (:issue:`8242`).
921921
- Bug in ``DataFrame.__setitem__`` that caused errors when setting a dataframe column to a sparse array (:issue:`8131`)
922+
- Bug where ``Dataframe.boxplot()`` failed when entire column was empty (:issue:`8181`).

pandas/tests/test_graphics.py

+5
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,11 @@ def _check_ax_limits(col, ax):
19151915
self.assertEqual(age_ax._sharey, height_ax)
19161916
self.assertIsNone(dummy_ax._sharey)
19171917

1918+
@slow
1919+
def test_boxplot_empty_column(self):
1920+
df = DataFrame(np.random.randn(20, 4))
1921+
df.loc[:, 0] = np.nan
1922+
_check_plot_works(df.boxplot, return_type='axes')
19181923

19191924
@slow
19201925
def test_kde_df(self):

pandas/tools/plotting.py

+4
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,10 @@ def _get_plot_function(self):
20812081
def plotf(ax, y, column_num=None, **kwds):
20822082
if y.ndim == 2:
20832083
y = [remove_na(v) for v in y]
2084+
# Boxplot fails with empty arrays, so need to add a NaN
2085+
# if any cols are empty
2086+
# GH 8181
2087+
y = [v if v.size > 0 else np.array([np.nan]) for v in y]
20842088
else:
20852089
y = remove_na(y)
20862090
bp = ax.boxplot(y, **kwds)

0 commit comments

Comments
 (0)