@@ -1018,20 +1018,32 @@ def test_map(self):
1018
1018
1019
1019
tm .assert_index_equal (index .map (lambda x : x ), expected )
1020
1020
1021
- identity_dict = {x : x for x in index }
1022
- tm .assert_index_equal (index .map (identity_dict ), expected )
1021
+ @pytest .mark .parametrize (
1022
+ "mapper" ,
1023
+ [
1024
+ lambda values , index : {i : e for e , i in zip (values , index )},
1025
+ lambda values , index : pd .Series (values , index )])
1026
+ def test_map_dictlike (self , mapper ):
1023
1027
1024
- # Use values to work around MultiIndex instantiation of series
1025
- identity_series = Series ( expected . values , index = index )
1026
- tm . assert_index_equal ( index . map ( identity_series ), expected )
1028
+ index = self . create_index ()
1029
+ if isinstance ( index , pd . CategoricalIndex ):
1030
+ pytest . skip ( "tested in test_categorical" )
1027
1031
1028
- # empty mappable
1029
- nan_index = pd .Index ([np .nan ] * len (index ))
1030
- series_map = pd .Series ()
1031
- tm .assert_index_equal (index .map (series_map ), nan_index )
1032
+ # From output of UInt64Index mapping can't infer that we
1033
+ # shouldn't default to Int64
1034
+ if isinstance (index , UInt64Index ):
1035
+ expected = Index (index .values .tolist ())
1036
+ else :
1037
+ expected = index
1038
+
1039
+ identity = mapper ({x : x for x in index }, index )
1040
+ result = index .map (identity )
1041
+ tm .assert_index_equal (result , expected )
1032
1042
1033
- dict_map = {}
1034
- tm .assert_index_equal (index .map (dict_map ), nan_index )
1043
+ # empty mappable
1044
+ expected = pd .Index ([np .nan ] * len (index ))
1045
+ result = index .map (mapper (expected , index ))
1046
+ tm .assert_index_equal (result , expected )
1035
1047
1036
1048
def test_putmask_with_wrong_mask (self ):
1037
1049
# GH18368
0 commit comments