Skip to content

Commit fa68e4f

Browse files
committed
Merge pull request #7502 from sinhrks/offsetret
BUG: offsets.apply may return datetime
2 parents db9128d + 3f4eff2 commit fa68e4f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

doc/source/v0.14.1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,15 @@ Bug Fixes
242242
- Bug in ``DatetimeIndex.to_period``, ``PeriodIndex.asobject``, ``PeriodIndex.to_timestamp`` doesn't preserve ``name`` (:issue:`7485`)
243243
- Bug in ``DatetimeIndex.to_period`` and ``PeriodIndex.to_timestanp`` handle ``NaT`` incorrectly (:issue:`7228`)
244244

245+
- BUG in ``offsets.apply``, ''rollforward`` and ``rollback`` may return normal ``datetime`` (:issue:`7502`)
245246

246247

247248
- BUG in ``resample`` raises ``ValueError`` when target contains ``NaT`` (:issue:`7227`)
248249

249250
- Bug in ``Timestamp.tz_localize`` resets ``nanosecond`` info (:issue:`7534`)
250251

252+
253+
251254
- Bug in ``Index.astype(float)`` where it would return an ``object`` dtype
252255
``Index`` (:issue:`7464`).
253256
- Bug in ``DataFrame.reset_index`` loses ``tz`` (:issue:`3950`)

pandas/tseries/offsets.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def wrapper(self, other):
4545
return tslib.NaT
4646
if type(other) == date:
4747
other = datetime(other.year, other.month, other.day)
48-
elif isinstance(other, np.datetime64):
48+
if isinstance(other, (np.datetime64, datetime)):
4949
other = as_timestamp(other)
5050

5151
tz = getattr(other, 'tzinfo', None)
@@ -57,11 +57,8 @@ def wrapper(self, other):
5757
if isinstance(other, Timestamp) and not isinstance(result, Timestamp):
5858
result = as_timestamp(result)
5959

60-
if tz is not None:
61-
if isinstance(result, Timestamp) and result.tzinfo is None:
62-
result = result.tz_localize(tz)
63-
elif isinstance(result, datetime) and result.tzinfo is None:
64-
result = tz.localize(result)
60+
if tz is not None and result.tzinfo is None:
61+
result = result.tz_localize(tz)
6562
return result
6663
return wrapper
6764

pandas/tseries/tests/test_offsets.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected,
204204
func = getattr(offset_s, funcname)
205205

206206
result = func(dt)
207-
self.assert_(isinstance(result, datetime))
207+
self.assert_(isinstance(result, Timestamp))
208208
self.assertEqual(result, expected)
209209

210210
result = func(Timestamp(dt))
@@ -222,11 +222,11 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected,
222222

223223
dt_tz = pytz.timezone(tz).localize(dt)
224224
result = func(dt_tz)
225-
self.assert_(isinstance(result, datetime))
225+
self.assert_(isinstance(result, Timestamp))
226226
self.assertEqual(result, expected_localize)
227227

228228
result = func(Timestamp(dt, tz=tz))
229-
self.assert_(isinstance(result, datetime))
229+
self.assert_(isinstance(result, Timestamp))
230230
self.assertEqual(result, expected_localize)
231231

232232
def _check_nanofunc_works(self, offset, funcname, dt, expected):

0 commit comments

Comments
 (0)