Skip to content

Commit e430ac4

Browse files
author
Chang She
committed
BUG: plotting bug when base is nonzero #2571
1 parent 7c6e30a commit e430ac4

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

pandas/tools/plotting.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pandas.core.index import MultiIndex
1414
from pandas.core.series import Series, remove_na
1515
from pandas.tseries.index import DatetimeIndex
16-
from pandas.tseries.period import PeriodIndex
16+
from pandas.tseries.period import PeriodIndex, Period
1717
from pandas.tseries.frequencies import get_period_alias, get_base_alias
1818
from pandas.tseries.offsets import DateOffset
1919

@@ -1027,7 +1027,21 @@ def _is_dynamic_freq(self, freq):
10271027
else:
10281028
freq = get_base_alias(freq)
10291029
freq = get_period_alias(freq)
1030-
return freq is not None
1030+
return freq is not None and self._no_base(freq)
1031+
1032+
def _no_base(self, freq):
1033+
# hack this for 0.10.1, creating more technical debt...sigh
1034+
from pandas.core.frame import DataFrame
1035+
if (isinstance(self.data, (Series, DataFrame))
1036+
and isinstance(self.data.index, DatetimeIndex)):
1037+
import pandas.tseries.frequencies as freqmod
1038+
base = freqmod.get_freq(freq)
1039+
x = self.data.index
1040+
if (base <= freqmod.FreqGroup.FR_DAY):
1041+
return x[:1].is_normalized
1042+
1043+
return Period(x[0], freq).to_timestamp() == x[0]
1044+
return True
10311045

10321046
def _use_dynamic_x(self):
10331047
freq = self._index_freq()

pandas/tseries/tests/test_plotting.py

+12
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ def test_business_freq_convert(self):
272272
idx = ax.get_lines()[0].get_xdata()
273273
self.assert_(PeriodIndex(data=idx).freqstr == 'M')
274274

275+
@slow
276+
def test_nonzero_base(self):
277+
import matplotlib.pyplot as plt
278+
plt.close('all')
279+
#GH2571
280+
idx = (date_range('2012-12-20', periods=24, freq='H') +
281+
timedelta(minutes=30))
282+
df = DataFrame(np.arange(24), index=idx)
283+
ax = df.plot()
284+
rs = ax.get_lines()[0].get_xdata()
285+
self.assert_(not Index(rs).is_normalized)
286+
275287
@slow
276288
def test_dataframe(self):
277289
bts = DataFrame({'a': tm.makeTimeSeries()})

0 commit comments

Comments
 (0)