Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: close #811, fix index.intersection where indices are incomparable #830

Merged
merged 1 commit into from
Feb 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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