Skip to content

Commit

Permalink
BUG: fixes #12405 by eliding values index by NaT in MPLPlot._get_xtic…
Browse files Browse the repository at this point in the history
…ks (#14540)

TST: add test for fix of #12405
DOC: update whatsnew/v0.20.2.txt
  • Loading branch information
tsdlovell authored and TomAugspurger committed May 20, 2017
1 parent 0f55de1 commit a6fcec6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Plotting
^^^^^^^^

- Bug in ``DataFrame.plot`` with a single column and a list-like ``color`` (:issue:`3486`)
- Bug in ``plot`` where ``NaT`` in ``DatetimeIndex`` results in ``Timestamp.min`` (:issue: `12405`)



Expand Down
2 changes: 2 additions & 0 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from pandas.util._decorators import cache_readonly
from pandas.core.base import PandasObject
from pandas.core.dtypes.missing import notnull
from pandas.core.dtypes.common import (
is_list_like,
is_integer,
Expand Down Expand Up @@ -538,6 +539,7 @@ def _get_xticks(self, convert_period=False):
"""
x = index._mpl_repr()
elif is_datetype:
self.data = self.data[notnull(self.data.index)]
self.data = self.data.sort_index()
x = self.data.index._mpl_repr()
else:
Expand Down
16 changes: 15 additions & 1 deletion pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pandas.compat import lrange, zip

import numpy as np
from pandas import Index, Series, DataFrame
from pandas import Index, Series, DataFrame, NaT
from pandas.compat import is_platform_mac
from pandas.core.indexes.datetimes import date_range, bdate_range
from pandas.core.indexes.timedeltas import timedelta_range
Expand Down Expand Up @@ -811,6 +811,20 @@ def test_mixed_freq_shared_ax(self):
# assert (ax1.lines[0].get_xydata()[0, 0] ==
# ax2.lines[0].get_xydata()[0, 0])

def test_nat_handling(self):

fig = self.plt.gcf()
# self.plt.clf()
ax = fig.add_subplot(111)

dti = DatetimeIndex(['2015-01-01', NaT, '2015-01-03'])
s = Series(range(len(dti)), dti)
s.plot(ax=ax)
xdata = ax.get_lines()[0].get_xdata()
# plot x data is bounded by index values
assert s.index.min() <= Series(xdata).min()
assert Series(xdata).max() <= s.index.max()

@slow
def test_to_weekly_resampling(self):
idxh = date_range('1/1/1999', periods=52, freq='W')
Expand Down

0 comments on commit a6fcec6

Please sign in to comment.