Skip to content

Commit 5b40dd5

Browse files
Chang Shewesm
Chang She
authored andcommitted
BUG: do not convert bday freq in ts plots #1482
1 parent 61d2fb7 commit 5b40dd5

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

pandas/tseries/frequencies.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ def _get_freq_str(base, mult=1):
239239
_offset_to_period_map = {
240240
'WEEKDAY' : 'D',
241241
'EOM' : 'M',
242-
'B' : 'D',
243242
'BM' : 'M',
244243
'BQS' : 'Q',
245244
'QS' : 'Q',
@@ -258,7 +257,7 @@ def _get_freq_str(base, mult=1):
258257
_offset_to_period_map['%s-%s' % (prefix, m)] = \
259258
_offset_to_period_map[prefix]
260259

261-
def to_calendar_freq(offset_str):
260+
def get_period_alias(offset_str):
262261
""" alias to closest period strings BQ->Q etc"""
263262
return _offset_to_period_map.get(offset_str, offset_str)
264263

pandas/tseries/plotting.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ def tsplot(series, plotf, *args, **kwargs):
8181
else:
8282
freq = frequencies.get_base_alias(freq)
8383

84-
freq = frequencies.to_calendar_freq(freq)
84+
freq = frequencies.get_period_alias(freq)
8585
# Convert DatetimeIndex to PeriodIndex
8686
if isinstance(series.index, DatetimeIndex):
87-
idx = series.index.to_period(freq=freq)
88-
series = Series(series.values, idx, name=series.name)
87+
series = series.to_period(freq=freq)
8988

9089
if not isinstance(series.index, PeriodIndex):
9190
#try to get it to DatetimeIndex then to period
@@ -99,8 +98,6 @@ def tsplot(series, plotf, *args, **kwargs):
9998
if freq != series.index.freq:
10099
series = series.asfreq(freq)
101100

102-
103-
104101
style = kwargs.pop('style', None)
105102

106103
if 'ax' in kwargs:

pandas/tseries/tests/test_plotting.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ def test_plot_multiple_inferred_freq(self):
110110

111111
@slow
112112
def test_irregular_datetime64_repr_bug(self):
113+
import matplotlib.pyplot as plt
113114
ser = tm.makeTimeSeries()
114115
ser = ser[[0,1,2,7]]
115-
import matplotlib.pyplot as plt
116116

117117
fig = plt.gcf()
118118
plt.clf()
@@ -125,21 +125,34 @@ def test_irregular_datetime64_repr_bug(self):
125125

126126
@slow
127127
def test_business_freq(self):
128+
import matplotlib.pyplot as plt
129+
plt.close('all')
128130
bts = tm.makePeriodSeries()
129-
ts = bts.asfreq('D')
131+
ax = bts.plot()
132+
self.assert_(ax.get_lines()[0].get_xydata()[0, 0],
133+
bts.index[0].ordinal)
134+
idx = ax.get_lines()[0].get_xdata()
135+
self.assert_(idx.freqstr == 'B')
136+
137+
@slow
138+
def test_business_freq_convert(self):
139+
import matplotlib.pyplot as plt
140+
plt.close('all')
141+
n = tm.N
142+
tm.N = 300
143+
bts = tm.makeTimeSeries().asfreq('BM')
144+
tm.N = n
145+
ts = bts.to_period('M')
130146
ax = bts.plot()
131147
self.assert_(ax.get_lines()[0].get_xydata()[0, 0], ts.index[0].ordinal)
132148
idx = ax.get_lines()[0].get_xdata()
133-
self.assert_(idx.freqstr == 'D')
149+
self.assert_(idx.freqstr == 'M')
134150

135151
@slow
136152
def test_dataframe(self):
137-
bts = DataFrame({'a': tm.makePeriodSeries()})
138-
ts = bts.asfreq('D')
153+
bts = DataFrame({'a': tm.makeTimeSeries()})
139154
ax = bts.plot()
140-
self.assert_(ax.get_lines()[0].get_xydata()[0, 0], ts.index[0].ordinal)
141155
idx = ax.get_lines()[0].get_xdata()
142-
self.assert_(idx.freqstr == 'D')
143156

144157
@slow
145158
def test_set_xlim(self):

0 commit comments

Comments
 (0)