From eb3c4e60b392f6a01999b5b6102e143abff75970 Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Fri, 10 Aug 2012 12:54:55 -0400 Subject: [PATCH] BUG: DatetimeIndex.intersection issue with equal unanchored offsets close #1708 --- RELEASE.rst | 1 + pandas/tseries/index.py | 1 + pandas/tseries/tests/test_timeseries.py | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/RELEASE.rst b/RELEASE.rst index b25b45caa8af0..407af8cd10b42 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -39,6 +39,7 @@ pandas 0.8.2 **Bug fixes** - Fix critical DatetimeIndex.union bugs (#1730, #1719, #1745, #1702) + - Fix critical DatetimeIndex.intersection bug with unanchored offsets (#1708) - Fix MM-YYYY time series indexing case (#1672) - Fix case where Categorical group key was not being passed into index in GroupBy result (#1701) diff --git a/pandas/tseries/index.py b/pandas/tseries/index.py index f228853ddad6e..37e04d7d4787f 100644 --- a/pandas/tseries/index.py +++ b/pandas/tseries/index.py @@ -834,6 +834,7 @@ def intersection(self, other): elif (other.offset is None or self.offset is None or other.offset != self.offset or + not other.offset.isAnchored() or (not self.is_monotonic or not other.is_monotonic)): result = Index.intersection(self, other) if isinstance(result, DatetimeIndex): diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 30e54f71dd39d..923b14e3b95bb 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -1179,6 +1179,14 @@ def test_union_bug_1745(self): exp = DatetimeIndex(sorted(set(list(left)) | set(list(right)))) self.assert_(result.equals(exp)) + def test_intersection_bug_1708(self): + from pandas import DateOffset + index_1 = date_range('1/1/2012', periods=4, freq='12H') + index_2 = index_1 + DateOffset(hours=1) + + result = index_1 & index_2 + self.assertEqual(len(result), 0) + # def test_add_timedelta64(self): # rng = date_range('1/1/2000', periods=5) # delta = rng.values[3] - rng.values[1]