Skip to content

BUG: boxplot does not work when data has datetime column #27846

New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Plotting

-
-

- Bug in :meth:`DataFrame.plot` when ``kind='box'`` and data contains datatime column (:issue:`22799`)
Groupby/resample/rolling
^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
4 changes: 3 additions & 1 deletion pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,10 @@ def _compute_plot_data(self):
# GH16953, _convert is needed as fallback, for ``Series``
# with ``dtype == object``
data = data._convert(datetime=True, timedelta=True)

# GH22799, skip datetime type data for computation
numeric_data = data.select_dtypes(
include=[np.number, "datetime", "datetimetz", "timedelta"]
include=[np.number, "datetimetz", "timedelta"]
)

try:
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/plotting/test_boxplot_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pandas.util._test_decorators as td

from pandas import DataFrame, MultiIndex, Series
from pandas import date_range
from pandas.tests.plotting.common import TestPlotBase, _check_plot_works
import pandas.util.testing as tm

Expand Down Expand Up @@ -160,6 +161,19 @@ def test_fontsize(self):
df.boxplot("a", fontsize=16), xlabelsize=16, ylabelsize=16
)

def test_boxplot_numeric_data(self):
# GH 22799
df = DataFrame(
{
"a": date_range("2012-01-01", periods=100),
"b": np.random.randn(100),
"c": np.random.randn(100) + 2,
"d": date_range("2012-01-01", periods=100).astype(str),
}
)
ax = df.plot(kind="box")
assert [x.get_text() for x in ax.get_xticklabels()] == ["b", "c"]


@td.skip_if_no_mpl
class TestDataFrameGroupByPlots(TestPlotBase):
Expand Down