diff --git a/pandas/plotting/_converter.py b/pandas/plotting/_converter.py index 2a45e20dda4cc..66ee7fa98491f 100644 --- a/pandas/plotting/_converter.py +++ b/pandas/plotting/_converter.py @@ -244,7 +244,7 @@ def _convert_1d(values, units, axis): if not hasattr(axis, 'freq'): raise TypeError('Axis must have `freq` set to convert to Periods') valid_types = (compat.string_types, datetime, - Period, pydt.date, pydt.time) + Period, pydt.date, pydt.time, np.datetime64) if (isinstance(values, valid_types) or is_integer(values) or is_float(values)): return get_datevalue(values, axis.freq) @@ -263,7 +263,7 @@ def get_datevalue(date, freq): if isinstance(date, Period): return date.asfreq(freq).ordinal elif isinstance(date, (compat.string_types, datetime, - pydt.date, pydt.time)): + pydt.date, pydt.time, np.datetime64)): return Period(date, freq).ordinal elif (is_integer(date) or is_float(date) or (isinstance(date, (np.ndarray, Index)) and (date.size == 1))): diff --git a/pandas/tests/plotting/test_converter.py b/pandas/tests/plotting/test_converter.py index cc275282436c8..47cded19f5300 100644 --- a/pandas/tests/plotting/test_converter.py +++ b/pandas/tests/plotting/test_converter.py @@ -327,21 +327,19 @@ def test_conversion(self): rs = self.pc.convert(Timestamp('2012-1-1'), None, self.axis) assert rs == xp - # FIXME - # rs = self.pc.convert( - # np_datetime64_compat('2012-01-01'), None, self.axis) - # assert rs == xp - # - # rs = self.pc.convert( - # np_datetime64_compat('2012-01-01 00:00:00+0000'), - # None, self.axis) - # assert rs == xp - # - # rs = self.pc.convert(np.array([ - # np_datetime64_compat('2012-01-01 00:00:00+0000'), - # np_datetime64_compat('2012-01-02 00:00:00+0000')]), - # None, self.axis) - # assert rs[0] == xp + rs = self.pc.convert( + np_datetime64_compat('2012-01-01'), None, self.axis) + assert rs == xp + + rs = self.pc.convert( + np_datetime64_compat('2012-01-01 00:00:00+0000'), None, self.axis) + assert rs == xp + + rs = self.pc.convert(np.array([ + np_datetime64_compat('2012-01-01 00:00:00+0000'), + np_datetime64_compat('2012-01-02 00:00:00+0000')]), + None, self.axis) + assert rs[0] == xp def test_integer_passthrough(self): # GH9012 diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 935e75ae76e1d..94adf349fe2cd 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -1449,6 +1449,19 @@ def test_overlapping_datetime(self): s2.plot(ax=ax) s1.plot(ax=ax) + @pytest.mark.xfail(reason="GH9053 matplotlib does not use" + " ax.xaxis.converter") + def test_add_matplotlib_datetime64(self): + # GH9053 - ensure that a plot with PeriodConverter still understands + # datetime64 data. This still fails because matplotlib overrides the + # ax.xaxis.converter with a DatetimeConverter + s = Series(np.random.randn(10), + index=date_range('1970-01-02', periods=10)) + ax = s.plot() + ax.plot(s.index, s.values, color='g') + l1, l2 = ax.lines + tm.assert_numpy_array_equal(l1.get_xydata(), l2.get_xydata()) + def _check_plot_works(f, freq=None, series=None, *args, **kwargs): import matplotlib.pyplot as plt