Skip to content

BUG: Reindex data if plotting time/period index (GH3601) #3619

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 17, 2013
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
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pandas 0.11.1
when ``parse_dates`` is specified (GH3062_)
- Fix not consolidating before to_csv (GH3624_)
- Fix alignment issue when setitem in a DataFrame with a piece of a DataFrame (GH3626_)
- Fix plotting of unordered DatetimeIndex (GH3601_)

.. _GH3164: https://github.com/pydata/pandas/issues/3164
.. _GH2786: https://github.com/pydata/pandas/issues/2786
Expand Down Expand Up @@ -180,6 +181,7 @@ pandas 0.11.1
.. _GH3062: https://github.com/pydata/pandas/issues/3062
.. _GH3624: https://github.com/pydata/pandas/issues/3624
.. _GH3626: https://github.com/pydata/pandas/issues/3626
.. _GH3601: https://github.com/pydata/pandas/issues/3601
.. _GH1512: https://github.com/pydata/pandas/issues/1512


Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,16 @@ def test_default_color_cycle(self):

@slow
def test_unordered_ts(self):
df = DataFrame(np.random.randn(3, 1),
df = DataFrame(np.array([3.0, 2.0, 1.0]),
index=[date(2012, 10, 1),
date(2012, 9, 1),
date(2012, 8, 1)],
columns=['test'])
ax = df.plot()
xticks = ax.lines[0].get_xdata()
self.assert_(xticks[0] < xticks[1])
ydata = ax.lines[0].get_ydata()
self.assert_(np.all(ydata == np.array([1.0, 2.0, 3.0])))

class TestDataFrameGroupByPlots(unittest.TestCase):

Expand Down
7 changes: 4 additions & 3 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,8 @@ def _get_xticks(self, convert_period=False):

if self.use_index:
if convert_period and isinstance(index, PeriodIndex):
index = index.to_timestamp().order()
x = index._mpl_repr()
self.data = self.data.reindex(index=index.order())
x = self.data.index.to_timestamp()._mpl_repr()
elif index.is_numeric():
"""
Matplotlib supports numeric values or datetime objects as
Expand All @@ -958,7 +958,8 @@ def _get_xticks(self, convert_period=False):
"""
x = index._mpl_repr()
elif is_datetype:
x = index.order()._mpl_repr()
self.data = self.data.reindex(index=index.order())
x = self.data.index._mpl_repr()
else:
self._need_to_set_index = True
x = range(len(index))
Expand Down