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

Already on GitHub? Sign in to your account

BUG: offsets.apply may return datetime #7502

Merged
merged 1 commit into from Jun 21, 2014
Jump to file or symbol
Failed to load files and symbols.
+9 −9
Split
View
@@ -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`).
@@ -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
@@ -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):