Repository: pandas-dev/pandas

Issue:
BUG: boxplot does not work when there is a datetime64 column
Making a boxplot of a DataFrame does not seem to skip datetime64 columns, as you get the following error (it tries to calculate the mean of the datetime64 values):

```
In [4]: df = pd.DataFrame({'a': pd.date_range("2012-01-01", periods=100), 'b': np.random.randn(100), 'c': np.random.randn(100)+2})

In [6]: df.plot(kind='box')
...
TypeError: unsupported operand type(s) for +: 'Timestamp' and 'Timestamp'
```

While when this would be a string column, it would be correctly skipped.

This seems to be a regression, as at least in pandas 0.20.3 this worked.


Discussion:

Resolving patch:
diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py
--- a/pandas/plotting/_matplotlib/core.py
+++ b/pandas/plotting/_matplotlib/core.py
@@ -402,12 +402,20 @@ def _compute_plot_data(self):
         # GH16953, _convert is needed as fallback, for ``Series``
         # with ``dtype == object``
         data = data._convert(datetime=True, timedelta=True)
-        select_include_type = [np.number, "datetime", "datetimetz", "timedelta"]
+        include_type = [np.number, "datetime", "datetimetz", "timedelta"]
 
         # GH23719, allow plotting boolean
         if self.include_bool is True:
-            select_include_type.append(np.bool_)
-        numeric_data = data.select_dtypes(include=select_include_type)
+            include_type.append(np.bool_)
+
+        # GH22799, exclude datatime-like type for boxplot
+        exclude_type = None
+        if self._kind == "box":
+            # TODO: change after solving issue 27881
+            include_type = [np.number]
+            exclude_type = ["timedelta"]
+
+        numeric_data = data.select_dtypes(include=include_type, exclude=exclude_type)
 
         try:
             is_empty = numeric_data.empty


Test patch:
diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py
--- a/pandas/tests/plotting/test_boxplot_method.py
+++ b/pandas/tests/plotting/test_boxplot_method.py
@@ -9,7 +9,7 @@
 
 import pandas.util._test_decorators as td
 
-from pandas import DataFrame, MultiIndex, Series
+from pandas import DataFrame, MultiIndex, Series, date_range, timedelta_range
 from pandas.tests.plotting.common import TestPlotBase, _check_plot_works
 import pandas.util.testing as tm
 
@@ -160,6 +160,21 @@ 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),
+                "e": date_range("2012-01-01", periods=100, tz="UTC"),
+                "f": timedelta_range("1 days", periods=100),
+            }
+        )
+        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):