Skip to content

Commit 3f4eff2

Browse files
committed
BUG: offsets.apply may return datetime
1 parent 4afc08e commit 3f4eff2

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

doc/source/v0.14.1.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,15 @@ Bug Fixes
244244
- Bug in ``DatetimeIndex.to_period``, ``PeriodIndex.asobject``, ``PeriodIndex.to_timestamp`` doesn't preserve ``name`` (:issue:`7485`)
245245
- Bug in ``DatetimeIndex.to_period`` and ``PeriodIndex.to_timestanp`` handle ``NaT`` incorrectly (:issue:`7228`)
246246

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

248249

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

251252
- Bug in ``Timestamp.tz_localize`` resets ``nanosecond`` info (:issue:`7534`)
252253

254+
255+
253256
- Bug in ``Index.astype(float)`` where it would return an ``object`` dtype
254257
``Index`` (:issue:`7464`).
255258

pandas/tseries/offsets.py

Lines changed: 3 additions & 6 deletions
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected,
209209
func = getattr(offset_s, funcname)
210210

211211
result = func(dt)
212-
self.assert_(isinstance(result, datetime))
212+
self.assert_(isinstance(result, Timestamp))
213213
self.assertEqual(result, expected)
214214

215215
result = func(Timestamp(dt))
@@ -227,11 +227,11 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected,
227227

228228
dt_tz = pytz.timezone(tz).localize(dt)
229229
result = func(dt_tz)
230-
self.assert_(isinstance(result, datetime))
230+
self.assert_(isinstance(result, Timestamp))
231231
self.assertEqual(result, expected_localize)
232232

233233
result = func(Timestamp(dt, tz=tz))
234-
self.assert_(isinstance(result, datetime))
234+
self.assert_(isinstance(result, Timestamp))
235235
self.assertEqual(result, expected_localize)
236236

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

0 commit comments

Comments
 (0)