Skip to content

Commit 8cd25ba

Browse files
committed
BUG: fixed boolean comparison of indices resulting in unwanted wrapping
1 parent f58749e commit 8cd25ba

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pandas/core/index.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515

1616
def _indexOp(opname):
1717
"""
18-
Wrapper function for Series arithmetic operations, to avoid
18+
Wrapper function for index comparison operations, to avoid
1919
code duplication.
2020
"""
2121
def wrapper(self, other):
2222
func = getattr(self.view(np.ndarray), opname)
23-
return func(other)
23+
result = func(other)
24+
try:
25+
return result.view(np.ndarray)
26+
except:
27+
return result
2428
return wrapper
2529

2630

pandas/tests/test_index.py

+10
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@ def test_isin(self):
417417
self.assert_(len(result) == 0)
418418
self.assert_(result.dtype == np.bool_)
419419

420+
def test_boolean_cmp(self):
421+
values = [1,2,3,4]
422+
423+
idx = Index(values)
424+
res = (idx == values)
425+
426+
self.assert_( res.all() )
427+
self.assert_( res.dtype == 'bool' )
428+
self.assert_( not isinstance(res, Index) )
429+
420430
class TestInt64Index(unittest.TestCase):
421431

422432
def setUp(self):

0 commit comments

Comments
 (0)