From 3f4eff2a11e49bb6a418b384e8fa2ec589aa0427 Mon Sep 17 00:00:00 2001 From: sinhrks Date: Wed, 18 Jun 2014 23:13:26 +0900 Subject: [PATCH] BUG: offsets.apply may return datetime --- doc/source/v0.14.1.txt | 3 +++ pandas/tseries/offsets.py | 9 +++------ pandas/tseries/tests/test_offsets.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/source/v0.14.1.txt b/doc/source/v0.14.1.txt index e8c7a6f9ab462..a6ca9e1dfd033 100644 --- a/doc/source/v0.14.1.txt +++ b/doc/source/v0.14.1.txt @@ -244,12 +244,15 @@ Bug Fixes - Bug in ``DatetimeIndex.to_period``, ``PeriodIndex.asobject``, ``PeriodIndex.to_timestamp`` doesn't preserve ``name`` (:issue:`7485`) - Bug in ``DatetimeIndex.to_period`` and ``PeriodIndex.to_timestanp`` handle ``NaT`` incorrectly (:issue:`7228`) +- BUG in ``offsets.apply``, ''rollforward`` and ``rollback`` may return normal ``datetime`` (:issue:`7502`) - BUG in ``resample`` raises ``ValueError`` when target contains ``NaT`` (:issue:`7227`) - Bug in ``Timestamp.tz_localize`` resets ``nanosecond`` info (:issue:`7534`) + + - Bug in ``Index.astype(float)`` where it would return an ``object`` dtype ``Index`` (:issue:`7464`). diff --git a/pandas/tseries/offsets.py b/pandas/tseries/offsets.py index ff4d6a54d51d4..bcb68ded6fda7 100644 --- a/pandas/tseries/offsets.py +++ b/pandas/tseries/offsets.py @@ -45,7 +45,7 @@ def wrapper(self, other): return tslib.NaT if type(other) == date: other = datetime(other.year, other.month, other.day) - elif isinstance(other, np.datetime64): + if isinstance(other, (np.datetime64, datetime)): other = as_timestamp(other) tz = getattr(other, 'tzinfo', None) @@ -57,11 +57,8 @@ def wrapper(self, other): if isinstance(other, Timestamp) and not isinstance(result, Timestamp): result = as_timestamp(result) - if tz is not None: - if isinstance(result, Timestamp) and result.tzinfo is None: - result = result.tz_localize(tz) - elif isinstance(result, datetime) and result.tzinfo is None: - result = tz.localize(result) + if tz is not None and result.tzinfo is None: + result = result.tz_localize(tz) return result return wrapper diff --git a/pandas/tseries/tests/test_offsets.py b/pandas/tseries/tests/test_offsets.py index fddfb3e3b4b56..8c84598e35e1e 100644 --- a/pandas/tseries/tests/test_offsets.py +++ b/pandas/tseries/tests/test_offsets.py @@ -209,7 +209,7 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, func = getattr(offset_s, funcname) result = func(dt) - self.assert_(isinstance(result, datetime)) + self.assert_(isinstance(result, Timestamp)) self.assertEqual(result, expected) result = func(Timestamp(dt)) @@ -227,11 +227,11 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, dt_tz = pytz.timezone(tz).localize(dt) result = func(dt_tz) - self.assert_(isinstance(result, datetime)) + self.assert_(isinstance(result, Timestamp)) self.assertEqual(result, expected_localize) result = func(Timestamp(dt, tz=tz)) - self.assert_(isinstance(result, datetime)) + self.assert_(isinstance(result, Timestamp)) self.assertEqual(result, expected_localize) def _check_nanofunc_works(self, offset, funcname, dt, expected):