Skip to content

Commit b4f3f0f

Browse files
committed
BUG: bug in timedelta ops on 32-bit platforms (GH6808)
1 parent dd12965 commit b4f3f0f

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ Bug Fixes
303303
- Bug in unpickling ``NaT (NaTType)`` (:issue:`4606`)
304304
- Bug in ``DataFrame.replace()`` where regex metacharacters were being treated
305305
as regexs even when ``regex=False`` (:issue:`6777`).
306+
- Bug in timedelta ops on 32-bit platforms (:issue:`6808`)
306307

307308
pandas 0.13.1
308309
-------------

pandas/tseries/tests/test_timedeltas.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,40 @@ def test_timedelta_ops(self):
243243
expected = to_timedelta('00:01:21')
244244
tm.assert_almost_equal(result, expected)
245245

246+
def test_timedelta_ops_scalar(self):
247+
_skip_if_numpy_not_friendly()
248+
249+
# GH 6808
250+
base = pd.to_datetime('20130101 09:01:12.123456')
251+
expected_add = pd.to_datetime('20130101 09:01:22.123456')
252+
expected_sub = pd.to_datetime('20130101 09:01:02.123456')
253+
254+
for offset in [pd.to_timedelta(10,unit='s'),
255+
timedelta(seconds=10),
256+
np.timedelta64(10,'s'),
257+
np.timedelta64(10000000000,'ns'),
258+
pd.offsets.Second(10)]:
259+
result = base + offset
260+
self.assertEquals(result, expected_add)
261+
262+
result = base - offset
263+
self.assertEquals(result, expected_sub)
264+
265+
base = pd.to_datetime('20130102 09:01:12.123456')
266+
expected_add = pd.to_datetime('20130103 09:01:22.123456')
267+
expected_sub = pd.to_datetime('20130101 09:01:02.123456')
268+
269+
for offset in [pd.to_timedelta('1 day, 00:00:10'),
270+
pd.to_timedelta('1 days, 00:00:10'),
271+
timedelta(days=1,seconds=10),
272+
np.timedelta64(1,'D')+np.timedelta64(10,'s'),
273+
pd.offsets.Day()+pd.offsets.Second(10)]:
274+
result = base + offset
275+
self.assertEquals(result, expected_add)
276+
277+
result = base - offset
278+
self.assertEquals(result, expected_sub)
279+
246280
def test_to_timedelta_on_missing_values(self):
247281
_skip_if_numpy_not_friendly()
248282

pandas/tseries/timedeltas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _convert_listlike(arg, box, unit):
6868
_short_search = re.compile(
6969
"^\s*(?P<neg>-?)\s*(?P<value>\d*\.?\d*)\s*(?P<unit>d|s|ms|us|ns)?\s*$",re.IGNORECASE)
7070
_full_search = re.compile(
71-
"^\s*(?P<neg>-?)\s*(?P<days>\d+)?\s*(days|d)?,?\s*(?P<time>\d{2}:\d{2}:\d{2})?(?P<frac>\.\d+)?\s*$",re.IGNORECASE)
71+
"^\s*(?P<neg>-?)\s*(?P<days>\d+)?\s*(days|d|day)?,?\s*(?P<time>\d{2}:\d{2}:\d{2})?(?P<frac>\.\d+)?\s*$",re.IGNORECASE)
7272
_nat_search = re.compile(
7373
"^\s*(nat|nan)\s*$",re.IGNORECASE)
7474
_whitespace = re.compile('^\s*$')

pandas/tslib.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,19 +690,19 @@ cdef class _Timestamp(datetime):
690690
dts.us, ts.tzinfo)
691691

692692
def __add__(self, other):
693-
cdef Py_ssize_t other_int
693+
cdef int64_t other_int
694694

695695
if is_timedelta64_object(other):
696-
other_int = other.astype('timedelta64[ns]').astype(int)
696+
other_int = other.astype('timedelta64[ns]').view('i8')
697697
return Timestamp(self.value + other_int, tz=self.tzinfo, offset=self.offset)
698698

699-
if is_integer_object(other):
699+
elif is_integer_object(other):
700700
if self.offset is None:
701701
raise ValueError("Cannot add integral value to Timestamp "
702702
"without offset.")
703703
return Timestamp((self.offset * other).apply(self), offset=self.offset)
704704

705-
if isinstance(other, timedelta) or hasattr(other, 'delta'):
705+
elif isinstance(other, timedelta) or hasattr(other, 'delta'):
706706
nanos = _delta_to_nanoseconds(other)
707707
return Timestamp(self.value + nanos, tz=self.tzinfo, offset=self.offset)
708708

0 commit comments

Comments
 (0)