Skip to content

Commit

Permalink
BUG: fixes #12405 by eliding values index by NaT in MPLPlot._get_xticks
Browse files Browse the repository at this point in the history
TST: add test for fix of #12405
DOC: update whatsnew/v0.20.0.txt
  • Loading branch information
dlovell committed Apr 21, 2017
1 parent 1f16ca7 commit 1c2cad6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,7 @@ Plotting
- Bug in ``DataFrame.boxplot`` where ``fontsize`` was not applied to the tick labels on both axes (:issue:`15108`)
- Bug in the date and time converters pandas registers with matplotlib not handling multiple dimensions (:issue:`16026`)
- Bug in ``pd.scatter_matrix()`` could accept either ``color`` or ``c``, but not both (:issue:`14855`)
- Bug in ``plot`` where ``NaT`` in ``DatetimeIndex`` results in ``Timestamp.min`` (:issue: `12405`)

Groupby/Resample/Rolling
^^^^^^^^^^^^^^^^^^^^^^^^
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 @@ -537,6 +538,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
19 changes: 18 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 @@ -815,6 +815,23 @@ def test_mixed_freq_shared_ax(self):
# self.assertEqual(ax1.lines[0].get_xydata()[0, 0],
# ax2.lines[0].get_xydata()[0, 0])

def test_nat_handling(self):

import matplotlib.pyplot as plt # noqa

fig = plt.gcf()
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
self.assertLessEqual(s.index.min(), Series(xdata).min())
self.assertLessEqual(Series(xdata).max(), s.index.max())
_check_plot_works(s.plot)

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

0 comments on commit 1c2cad6

Please sign in to comment.