Skip to content

Commit 38e4d46

Browse files
committed
BUG: apply Timestamp to resultant datetimes when operating on offsets
1 parent b0cd607 commit 38e4d46

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pandas/tseries/offsets.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# import after tools, dateutil check
99
from dateutil.relativedelta import relativedelta
1010
import pandas.tslib as tslib
11+
from pandas.tslib import Timestamp
1112
import numpy as np
1213
from pandas import _np_version_under1p7
1314

@@ -92,9 +93,9 @@ def apply(self, other):
9293
else:
9394
for i in range(-self.n):
9495
other = other - self._offset
95-
return other
96+
return Timestamp(other)
9697
else:
97-
return other + timedelta(self.n)
98+
return Timestamp(other + timedelta(self.n))
9899

99100
def isAnchored(self):
100101
return (self.n == 1)
@@ -373,7 +374,7 @@ def apply(self, other):
373374
if self.offset:
374375
result = result + self.offset
375376

376-
return result
377+
return Timestamp(result)
377378

378379
elif isinstance(other, (timedelta, Tick)):
379380
return BDay(self.n, offset=self.offset + other,
@@ -516,7 +517,7 @@ def apply(self, other):
516517
if n <= 0:
517518
n = n + 1
518519
other = other + relativedelta(months=n, day=31)
519-
return other
520+
return Timestamp(other)
520521

521522
@classmethod
522523
def onOffset(cls, dt):
@@ -538,7 +539,7 @@ def apply(self, other):
538539
n += 1
539540

540541
other = other + relativedelta(months=n, day=1)
541-
return other
542+
return Timestamp(other)
542543

543544
@classmethod
544545
def onOffset(cls, dt):
@@ -660,7 +661,7 @@ def apply(self, other):
660661
other = other + timedelta((self.weekday - otherDay) % 7)
661662
for i in range(-k):
662663
other = other - self._inc
663-
return other
664+
return Timestamp(other)
664665

665666
def onOffset(self, dt):
666667
return dt.weekday() == self.weekday
@@ -901,7 +902,7 @@ def apply(self, other):
901902

902903
other = other + relativedelta(months=monthsToGo + 3 * n, day=31)
903904

904-
return other
905+
return Timestamp(other)
905906

906907
def onOffset(self, dt):
907908
modMonth = (dt.month - self.startingMonth) % 3
@@ -941,7 +942,7 @@ def apply(self, other):
941942
n = n + 1
942943

943944
other = other + relativedelta(months=3 * n - monthsSince, day=1)
944-
return other
945+
return Timestamp(other)
945946

946947
@property
947948
def rule_code(self):
@@ -1093,7 +1094,7 @@ def _rollf(date):
10931094
# n == 0, roll forward
10941095
result = _rollf(result)
10951096

1096-
return result
1097+
return Timestamp(result)
10971098

10981099
def onOffset(self, dt):
10991100
wkday, days_in_month = tslib.monthrange(dt.year, self.month)
@@ -1151,7 +1152,7 @@ def _rollf(date):
11511152
# n == 0, roll forward
11521153
result = _rollf(result)
11531154

1154-
return result
1155+
return Timestamp(result)
11551156

11561157
def onOffset(self, dt):
11571158
return dt.month == self.month and dt.day == 1

0 commit comments

Comments
 (0)