Skip to content

Commit

Permalink
Merge pull request #830 from adamklein/IS811
Browse files Browse the repository at this point in the history
BUG: close #811, fix index.intersection where indices are incomparable
  • Loading branch information
wesm committed Feb 24, 2012
2 parents ee95ec1 + 75bf87b commit 575a852
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pandas 0.7.1
- Fixed bug whereby bool array sometimes had object dtype (#820)
- Fix exception thrown on np.diff (#816)
- Fix to_records where columns are non-strings (#822)
- Fix Index.intersection where indices have incomparable types (#811)

pandas 0.7.0
============
Expand Down
15 changes: 9 additions & 6 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,15 @@ def intersection(self, other):
return this.intersection(other)

if self.is_monotonic and other.is_monotonic:
result = self._inner_indexer(self, other.values)[0]
return self._wrap_union_result(other, result)
else:
indexer = self.get_indexer(other.values)
indexer = indexer.take((indexer != -1).nonzero()[0])
return self.take(indexer)
try:
result = self._inner_indexer(self, other.values)[0]
return self._wrap_union_result(other, result)
except TypeError:
pass

indexer = self.get_indexer(other.values)
indexer = indexer.take((indexer != -1).nonzero()[0])
return self.take(indexer)

def diff(self, other):
"""
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,17 @@ def test_to_records_floats(self):
df = DataFrame(np.random.rand(10,10))
df.to_records()

def test_join_str_datetime(self):
str_dates = ['20120209' , '20120222']
dt_dates = [datetime(2012,2,9), datetime(2012,2,22)]

A = DataFrame(str_dates, index=range(2), columns=['aa'])
C = DataFrame([[1,2],[3,4]], index=str_dates, columns=dt_dates)

tst = A.join(C, on = 'aa')

self.assert_(len(tst.columns) == 3)

def test_from_records_sequencelike(self):
df = DataFrame({'A' : np.random.randn(6),
'B' : np.arange(6),
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,15 @@ def test_intersection(self):
other.values)))
self.assert_(np.array_equal(result, expected))

def test_intersect_str_dates(self):
dt_dates = [datetime(2012,2,9) , datetime(2012,2,22)]

i1 = Index(dt_dates, dtype=object)
i2 = Index(['aa'], dtype=object)
res = i2.intersection(i1)

self.assert_(len(res) == 0)

def test_union_noncomparable(self):
from datetime import datetime, timedelta
# corner case, non-Int64Index
Expand Down

0 comments on commit 575a852

Please sign in to comment.