@@ -767,6 +767,26 @@ def test_sub(self):
767767 self .assertRaises (TypeError , lambda : idx - idx .tolist ())
768768 self .assertRaises (TypeError , lambda : idx .tolist () - idx )
769769
770+ def test_map_identity_mapping (self ):
771+ for name , cur_index in self .indices .items ():
772+ if name == 'tuples' :
773+ expected = Index (cur_index .values , tupleize_cols = False )
774+ self .assert_index_equal (expected , cur_index .map (lambda x : x ))
775+ else :
776+ self .assert_index_equal (cur_index , cur_index .map (lambda x : x ))
777+
778+ def test_map_that_returns_tuples_creates_index_not_multi_index (self ):
779+ boolean_index = tm .makeIntIndex (3 ).map (lambda x : (x , x == 1 ))
780+ expected = Index ([(0 , False ), (1 , True ), (2 , False )],
781+ tupleize_cols = False )
782+ self .assert_index_equal (boolean_index , expected )
783+
784+ def test_map_that_reduces_multi_index_to_single_index_returns_index (self ):
785+ first_level = ['foo' , 'bar' , 'baz' ]
786+ multi_index = MultiIndex .from_tuples (lzip (first_level , [1 , 2 , 3 ]))
787+ reduced_index = multi_index .map (lambda x : x [0 ])
788+ self .assert_index_equal (reduced_index , Index (first_level ))
789+
770790 def test_append_multiple (self ):
771791 index = Index (['a' , 'b' , 'c' , 'd' , 'e' , 'f' ])
772792
@@ -1194,16 +1214,16 @@ def check_slice(in_slice, expected):
11941214 self .assert_index_equal (result , expected )
11951215
11961216 for in_slice , expected in [
1197- (SLC [::- 1 ], 'yxdcb' ), (SLC ['b' :'y' :- 1 ], '' ),
1198- (SLC ['b' ::- 1 ], 'b' ), (SLC [:'b' :- 1 ], 'yxdcb' ),
1199- (SLC [:'y' :- 1 ], 'y' ), (SLC ['y' ::- 1 ], 'yxdcb' ),
1200- (SLC ['y' ::- 4 ], 'yb' ),
1201- # absent labels
1202- (SLC [:'a' :- 1 ], 'yxdcb' ), (SLC [:'a' :- 2 ], 'ydb' ),
1203- (SLC ['z' ::- 1 ], 'yxdcb' ), (SLC ['z' ::- 3 ], 'yc' ),
1204- (SLC ['m' ::- 1 ], 'dcb' ), (SLC [:'m' :- 1 ], 'yx' ),
1205- (SLC ['a' :'a' :- 1 ], '' ), (SLC ['z' :'z' :- 1 ], '' ),
1206- (SLC ['m' :'m' :- 1 ], '' )
1217+ (SLC [::- 1 ], 'yxdcb' ), (SLC ['b' :'y' :- 1 ], '' ),
1218+ (SLC ['b' ::- 1 ], 'b' ), (SLC [:'b' :- 1 ], 'yxdcb' ),
1219+ (SLC [:'y' :- 1 ], 'y' ), (SLC ['y' ::- 1 ], 'yxdcb' ),
1220+ (SLC ['y' ::- 4 ], 'yb' ),
1221+ # absent labels
1222+ (SLC [:'a' :- 1 ], 'yxdcb' ), (SLC [:'a' :- 2 ], 'ydb' ),
1223+ (SLC ['z' ::- 1 ], 'yxdcb' ), (SLC ['z' ::- 3 ], 'yc' ),
1224+ (SLC ['m' ::- 1 ], 'dcb' ), (SLC [:'m' :- 1 ], 'yx' ),
1225+ (SLC ['a' :'a' :- 1 ], '' ), (SLC ['z' :'z' :- 1 ], '' ),
1226+ (SLC ['m' :'m' :- 1 ], '' )
12071227 ]:
12081228 check_slice (in_slice , expected )
12091229
0 commit comments