Skip to content

API: all offset operations now return Timestamp types (rather than datetime) (GH4069) #6743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ API Changes

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

- all offset operations now return ``Timestamp`` types (rather than datetime), Business/Week frequencies were incorrect (:issue:`4069`)

Deprecations
~~~~~~~~~~~~

Expand Down
20 changes: 10 additions & 10 deletions pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,9 @@ def _set_busdaycalendar(self):
kwargs = {'weekmask':self.weekmask,'holidays':self.holidays}
else:
kwargs = {'weekmask':self.weekmask}
try:
try:
self.busdaycalendar = np.busdaycalendar(**kwargs)
except:
except:
# Check we have the required numpy version
from distutils.version import LooseVersion

Expand All @@ -484,9 +484,9 @@ def _set_busdaycalendar(self):
np.__version__)
else:
raise

def __getstate__(self):
""""Return a pickleable state"""
"""Return a pickleable state"""
state = self.__dict__.copy()
del state['busdaycalendar']
return state
Expand Down Expand Up @@ -520,7 +520,7 @@ def apply(self, other):
if self.offset:
result = result + self.offset

return result
return as_timestamp(result)

elif isinstance(other, np.datetime64):
dtype = other.dtype
Expand All @@ -539,7 +539,7 @@ def apply(self, other):
if self.offset:
result = result + self.offset

return result
return as_timestamp(result)

elif isinstance(other, (timedelta, Tick)):
return BDay(self.n, offset=self.offset + other,
Expand Down Expand Up @@ -639,7 +639,7 @@ def apply(self, other):

if other.weekday() > 4:
other = other - BDay()
return other
return as_timestamp(other)

_prefix = 'BM'

Expand Down Expand Up @@ -706,7 +706,7 @@ def isAnchored(self):

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

if self.n > 0:
k = self.n
Expand Down Expand Up @@ -998,7 +998,7 @@ def apply(self, other):
if other.weekday() > 4:
other = other - BDay()

return other
return as_timestamp(other)

def onOffset(self, dt):
modMonth = (dt.month - self.startingMonth) % 3
Expand Down Expand Up @@ -1188,7 +1188,7 @@ def apply(self, other):
if result.weekday() > 4:
result = result - BDay()

return result
return as_timestamp(result)


class BYearBegin(YearOffset):
Expand Down
13 changes: 12 additions & 1 deletion pandas/tseries/tests/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TestBase(tm.TestCase):

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

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

def test_return_type(self):

# make sure that we are returning a Timestamp
try:
offset = self._offset(1)
except:
raise nose.SkipTest("_offset not defined to test return_type")

result = Timestamp('20080101') + offset
self.assertIsInstance(result, Timestamp)

class TestDateOffset(TestBase):
_multiprocess_can_split_ = True

Expand Down