Skip to content

Commit 0e73689

Browse files
committed
Merge pull request #6743 from jreback/freq
API: all offset operations now return Timestamp types (rather than datetime) (GH4069)
2 parents 540c1ab + a4599a7 commit 0e73689

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ API Changes
150150

151151
- ``DataFrame.sort`` now places NaNs at the beginning or end of the sort according to the ``na_position`` parameter. (:issue:`3917`)
152152

153+
- all offset operations now return ``Timestamp`` types (rather than datetime), Business/Week frequencies were incorrect (:issue:`4069`)
154+
153155
Deprecations
154156
~~~~~~~~~~~~
155157

pandas/tseries/offsets.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ def _set_busdaycalendar(self):
472472
kwargs = {'weekmask':self.weekmask,'holidays':self.holidays}
473473
else:
474474
kwargs = {'weekmask':self.weekmask}
475-
try:
475+
try:
476476
self.busdaycalendar = np.busdaycalendar(**kwargs)
477-
except:
477+
except:
478478
# Check we have the required numpy version
479479
from distutils.version import LooseVersion
480480

@@ -484,9 +484,9 @@ def _set_busdaycalendar(self):
484484
np.__version__)
485485
else:
486486
raise
487-
487+
488488
def __getstate__(self):
489-
""""Return a pickleable state"""
489+
"""Return a pickleable state"""
490490
state = self.__dict__.copy()
491491
del state['busdaycalendar']
492492
return state
@@ -520,7 +520,7 @@ def apply(self, other):
520520
if self.offset:
521521
result = result + self.offset
522522

523-
return result
523+
return as_timestamp(result)
524524

525525
elif isinstance(other, np.datetime64):
526526
dtype = other.dtype
@@ -539,7 +539,7 @@ def apply(self, other):
539539
if self.offset:
540540
result = result + self.offset
541541

542-
return result
542+
return as_timestamp(result)
543543

544544
elif isinstance(other, (timedelta, Tick)):
545545
return BDay(self.n, offset=self.offset + other,
@@ -639,7 +639,7 @@ def apply(self, other):
639639

640640
if other.weekday() > 4:
641641
other = other - BDay()
642-
return other
642+
return as_timestamp(other)
643643

644644
_prefix = 'BM'
645645

@@ -706,7 +706,7 @@ def isAnchored(self):
706706

707707
def apply(self, other):
708708
if self.weekday is None:
709-
return as_datetime(other) + self.n * self._inc
709+
return as_timestamp(as_datetime(other) + self.n * self._inc)
710710

711711
if self.n > 0:
712712
k = self.n
@@ -998,7 +998,7 @@ def apply(self, other):
998998
if other.weekday() > 4:
999999
other = other - BDay()
10001000

1001-
return other
1001+
return as_timestamp(other)
10021002

10031003
def onOffset(self, dt):
10041004
modMonth = (dt.month - self.startingMonth) % 3
@@ -1188,7 +1188,7 @@ def apply(self, other):
11881188
if result.weekday() > 4:
11891189
result = result - BDay()
11901190

1191-
return result
1191+
return as_timestamp(result)
11921192

11931193

11941194
class BYearBegin(YearOffset):

pandas/tseries/tests/test_offsets.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class TestBase(tm.TestCase):
9999

100100
def test_apply_out_of_range(self):
101101
if self._offset is None:
102-
raise nose.SkipTest("_offset not defined")
102+
raise nose.SkipTest("_offset not defined to test out-of-range")
103103

104104
# try to create an out-of-bounds result timestamp; if we can't create the offset
105105
# skip
@@ -113,6 +113,17 @@ def test_apply_out_of_range(self):
113113
except (ValueError, KeyError):
114114
raise nose.SkipTest("cannot create out_of_range offset")
115115

116+
def test_return_type(self):
117+
118+
# make sure that we are returning a Timestamp
119+
try:
120+
offset = self._offset(1)
121+
except:
122+
raise nose.SkipTest("_offset not defined to test return_type")
123+
124+
result = Timestamp('20080101') + offset
125+
self.assertIsInstance(result, Timestamp)
126+
116127
class TestDateOffset(TestBase):
117128
_multiprocess_can_split_ = True
118129

0 commit comments

Comments
 (0)