@@ -1320,6 +1320,24 @@ def test_groupby(self):
1320
1320
exp = {1 : [0 , 1 ], 2 : [2 , 3 , 4 ]}
1321
1321
tm .assert_dict_equal (groups , exp )
1322
1322
1323
+ def test_equals_op (self ):
1324
+ # For issue #9785
1325
+ index_a = Index (['foo' , 'bar' , 'baz' ])
1326
+ index_b = Index (['foo' , 'bar' , 'baz' , 'qux' ])
1327
+ # Testing Numpy Results Equivelent
1328
+ assert_array_equal (
1329
+ index_a .equals (index_a ),
1330
+ index_a == index_a
1331
+ )
1332
+ assert_array_equal (
1333
+ index_a .equals (index_b ),
1334
+ index_a == index_b ,
1335
+ )
1336
+ assert_array_equal (
1337
+ index_b .equals (index_a ),
1338
+ index_b == index_a ,
1339
+ )
1340
+
1323
1341
1324
1342
class Numeric (Base ):
1325
1343
@@ -4075,6 +4093,48 @@ def test_groupby(self):
4075
4093
exp = dict ((key , [key ]) for key in self .index )
4076
4094
tm .assert_dict_equal (groups , exp )
4077
4095
4096
+ def test_equals_operator (self ):
4097
+ # For issue #9785
4098
+ self .assertTrue ((self .index == self .index ).all ())
4099
+
4100
+ def test_index_compare (self ):
4101
+ # For issue #9785
4102
+ index_unequal = Index (['foo' , 'bar' , 'baz' ])
4103
+ index_equal = Index ([
4104
+ ('foo' , 'one' ), ('foo' , 'two' ), ('bar' , 'one' ),
4105
+ ('baz' , 'two' ), ('qux' , 'one' ), ('qux' , 'two' )
4106
+ ], tupleize_cols = False )
4107
+ # Testing Numpy Results Equivelent
4108
+ assert_array_equal (
4109
+ index_unequal .equals (self .index ),
4110
+ index_unequal == self .index ,
4111
+ err_msg = 'Index compared with MultiIndex failed' ,
4112
+ )
4113
+ assert_array_equal (
4114
+ self .index .equals (index_unequal ),
4115
+ self .index == index_unequal ,
4116
+ err_msg = 'MultiIndex compared with Index failed' ,
4117
+ )
4118
+ assert_array_equal (
4119
+ self .index .equals (index_equal ),
4120
+ self .index == index_equal ,
4121
+ err_msg = 'MultiIndex compared with Similar Index failed' ,
4122
+ )
4123
+ assert_array_equal (
4124
+ index_equal .equals (self .index ),
4125
+ index_equal == self .index ,
4126
+ err_msg = 'Index compared with Similar MultiIndex failed' ,
4127
+ )
4128
+ # Testing that the result is true for the index_equal case
4129
+ self .assertTrue (
4130
+ (self .index == index_equal ).all (),
4131
+ msg = 'Assert Index compared with Similar MultiIndex match'
4132
+ )
4133
+ self .assertTrue (
4134
+ (index_equal == self .index ).all (),
4135
+ msg = 'Assert MultiIndex compared with Similar Index match'
4136
+ )
4137
+
4078
4138
4079
4139
def test_get_combined_index ():
4080
4140
from pandas .core .index import _get_combined_index
0 commit comments