Skip to content
Browse files

BUG: keep frequency information when adding timedeltas

ENH: allow DatetimeIndex - timedelta
  • Loading branch information...
1 parent 09084bb commit 785537e10e381d3b789f721288226e0fad177d95 Chang She committed Apr 26, 2012
Showing with 10 additions and 4 deletions.
  1. +10 −4 pandas/tseries/index.py
View
14 pandas/tseries/index.py
@@ -150,9 +150,6 @@ class DatetimeIndex(Int64Index):
__le__ = _dt_index_cmp('__le__')
__ge__ = _dt_index_cmp('__ge__')
- __add__ = _dt_index_op('__add__')
- __sub__ = _dt_index_op('__sub__')
-
# structured array cache for datetime fields
_sarr_cache = None
@@ -420,7 +417,16 @@ def __add__(self, other):
return self.union(other)
elif isinstance(other, (datetools.DateOffset, timedelta)):
new_values = self.astype('O') + other
- return DatetimeIndex(new_values, tz=self.tz)
+ return DatetimeIndex(new_values, tz=self.tz, freq=self.freq)
+ else:
+ return Index(self.view(np.ndarray) + other)
+
+ def __sub__(self, other):
+ if isinstance(other, Index):
+ return self.diff(other)
+ elif isinstance(other, (datetools.DateOffset, timedelta)):
+ new_values = self.astype('O') - other
+ return DatetimeIndex(new_values, tz=self.tz, freq=self.freq)
else:
return Index(self.view(np.ndarray) + other)

0 comments on commit 785537e

Please sign in to comment.
Something went wrong with that request. Please try again.