Skip to content

Commit 22d9141

Browse files
committed
Merge pull request #3619 from dieterv77/FixGH3601
BUG: (GH3601) Reindex data if reordering time/period index
2 parents bae62ea + 3b37088 commit 22d9141

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pandas 0.11.1
127127
when ``parse_dates`` is specified (GH3062_)
128128
- Fix not consolidating before to_csv (GH3624_)
129129
- Fix alignment issue when setitem in a DataFrame with a piece of a DataFrame (GH3626_)
130+
- Fix plotting of unordered DatetimeIndex (GH3601_)
130131

131132
.. _GH3164: https://github.com/pydata/pandas/issues/3164
132133
.. _GH2786: https://github.com/pydata/pandas/issues/2786
@@ -180,6 +181,7 @@ pandas 0.11.1
180181
.. _GH3062: https://github.com/pydata/pandas/issues/3062
181182
.. _GH3624: https://github.com/pydata/pandas/issues/3624
182183
.. _GH3626: https://github.com/pydata/pandas/issues/3626
184+
.. _GH3601: https://github.com/pydata/pandas/issues/3601
183185
.. _GH1512: https://github.com/pydata/pandas/issues/1512
184186

185187

pandas/tests/test_graphics.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,16 @@ def test_default_color_cycle(self):
677677

678678
@slow
679679
def test_unordered_ts(self):
680-
df = DataFrame(np.random.randn(3, 1),
680+
df = DataFrame(np.array([3.0, 2.0, 1.0]),
681681
index=[date(2012, 10, 1),
682682
date(2012, 9, 1),
683683
date(2012, 8, 1)],
684684
columns=['test'])
685685
ax = df.plot()
686686
xticks = ax.lines[0].get_xdata()
687687
self.assert_(xticks[0] < xticks[1])
688+
ydata = ax.lines[0].get_ydata()
689+
self.assert_(np.all(ydata == np.array([1.0, 2.0, 3.0])))
688690

689691
class TestDataFrameGroupByPlots(unittest.TestCase):
690692

pandas/tools/plotting.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,8 @@ def _get_xticks(self, convert_period=False):
947947

948948
if self.use_index:
949949
if convert_period and isinstance(index, PeriodIndex):
950-
index = index.to_timestamp().order()
951-
x = index._mpl_repr()
950+
self.data = self.data.reindex(index=index.order())
951+
x = self.data.index.to_timestamp()._mpl_repr()
952952
elif index.is_numeric():
953953
"""
954954
Matplotlib supports numeric values or datetime objects as
@@ -958,7 +958,8 @@ def _get_xticks(self, convert_period=False):
958958
"""
959959
x = index._mpl_repr()
960960
elif is_datetype:
961-
x = index.order()._mpl_repr()
961+
self.data = self.data.reindex(index=index.order())
962+
x = self.data.index._mpl_repr()
962963
else:
963964
self._need_to_set_index = True
964965
x = range(len(index))

0 commit comments

Comments
 (0)