Skip to content

Commit bdd143a

Browse files
committed
BUG: change default frequency for to_timestamp
1 parent 94a4bbe commit bdd143a

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

pandas/tseries/period.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,15 @@ def start_time(self):
187187
def end_time(self):
188188
return self.to_timestamp('s', how='E')
189189

190-
def to_timestamp(self, freq='s', how='start'):
190+
def to_timestamp(self, freq=None, how='start'):
191191
"""
192192
Return the Timestamp representation of the Period at the target
193-
frequency
193+
frequency at the specified end (how) of the Period
194194
195195
Parameters
196196
----------
197-
freq : string or DateOffset, default is second
197+
freq : string or DateOffset, default is 'D' if self.freq is week or
198+
longer and 'S' otherwise
198199
Target frequency
199200
how: str, default 'S' (start)
200201
'S', 'E'. Can be aliased as case insensitive
@@ -208,10 +209,10 @@ def to_timestamp(self, freq='s', how='start'):
208209

209210
if freq is None:
210211
base, mult = _gfc(self.freq)
211-
val = self
212-
else:
213-
base, mult = _gfc(freq)
214-
val = self.asfreq(freq, how)
212+
freq = _freq_mod.get_to_timestamp_base(base)
213+
214+
base, mult = _gfc(freq)
215+
val = self.asfreq(freq, how)
215216

216217
dt64 = plib.period_ordinal_to_dt64(val.ordinal, base)
217218
return Timestamp(dt64)
@@ -757,13 +758,14 @@ def _mpl_repr(self):
757758
# how to represent ourselves to matplotlib
758759
return self._get_object_array()
759760

760-
def to_timestamp(self, freq='s', how='start'):
761+
def to_timestamp(self, freq=None, how='start'):
761762
"""
762763
Cast to DatetimeIndex
763764
764765
Parameters
765766
----------
766-
freq : string or DateOffset, default 's'
767+
freq : string or DateOffset, default 'D' for week or longer, 'S'
768+
otherwise
767769
Target frequency
768770
how : {'s', 'e', 'start', 'end'}
769771

pandas/tseries/tests/test_period.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ def test_to_timestamp(self):
215215
start_ts = p.to_timestamp(how='S')
216216
aliases = ['s', 'StarT', 'BEGIn']
217217
for a in aliases:
218-
self.assertEquals(start_ts, p.to_timestamp(how=a))
218+
self.assertEquals(start_ts, p.to_timestamp('D', how=a))
219219

220220
end_ts = p.to_timestamp(how='E')
221221
aliases = ['e', 'end', 'FINIsH']
222222
for a in aliases:
223-
self.assertEquals(end_ts, p.to_timestamp(how=a))
223+
self.assertEquals(end_ts, p.to_timestamp('D', how=a))
224224

225225
from_lst = ['A', 'Q', 'M', 'W', 'B',
226226
'D', 'H', 'Min', 'S']
@@ -231,7 +231,7 @@ def test_to_timestamp(self):
231231

232232
self.assertEquals(p.start_time, p.to_timestamp(how='S'))
233233

234-
self.assertEquals(p.end_time, p.to_timestamp(how='E'))
234+
self.assertEquals(p.end_time, p.to_timestamp('s', how='E'))
235235

236236
# Frequency other than daily
237237

@@ -245,8 +245,8 @@ def test_to_timestamp(self):
245245
expected = datetime(1985, 12, 31, 23, 59)
246246
self.assertEquals(result, expected)
247247

248-
result = p.to_timestamp('S', how='end')
249-
expected = datetime(1985, 12, 31, 23, 59, 59)
248+
result = p.to_timestamp(how='end')
249+
expected = datetime(1985, 12, 31)
250250
self.assertEquals(result, expected)
251251

252252
expected = datetime(1985, 1, 1)

0 commit comments

Comments
 (0)