Skip to content

BUG: fixes #12405 by eliding values index by NaT in MPLPlot._get_xticks #14540

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 1 commit into from
May 20, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
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