Skip to content

Commit

Permalink
Fixes wrong overlapping check in _can_fast_union.
Browse files Browse the repository at this point in the history
To use the fast_union method it is not enough to find an overlap, the
indices also have to be aligned.
  • Loading branch information
filmor committed Sep 25, 2013
1 parent a11e143 commit 3584e50
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ Bug Fixes
- Fixed ``copy()`` to shallow copy axes/indices as well and thereby keep
separate metadata. (:issue:`4202`, :issue:`4830`)
- Fixed skiprows option in Python parser for read_csv (:issue:`4382`)
- Fixed wrong check for overlapping in ``DatetimeIndex.union`` (:issue:`4564`)

pandas 0.12.0
-------------
Expand Down
4 changes: 2 additions & 2 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,11 +986,11 @@ def _can_fast_union(self, other):
else:
left, right = other, self

left_end = left[-1]
right_start = right[0]
left_end = left[-1]

# Only need to "adjoin", not overlap
return (left_end + offset) >= right_start
return (right_start == left_end + offset) or right_start in left

def _fast_union(self, other):
if len(other) == 0:
Expand Down
9 changes: 9 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,15 @@ def test_union_bug_1745(self):
exp = DatetimeIndex(sorted(set(list(left)) | set(list(right))))
self.assert_(result.equals(exp))

def test_union_bug_4564(self):
from pandas import DateOffset
left = date_range("2013-01-01", "2013-02-01")
right = left + DateOffset(minutes=15)

result = left.union(right)
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')
Expand Down

0 comments on commit 3584e50

Please sign in to comment.