@@ -830,60 +830,32 @@ def test_map_tseries_indices_return_index(self):
830830 tm .assert_index_equal (exp , date_index .map (lambda x : x .hour ))
831831
832832 def test_map_with_dict_and_series (self ):
833+ # GH 12756
833834 expected = Index (['foo' , 'bar' , 'baz' ])
834835 mapper = Series (expected .values , index = [0 , 1 , 2 ])
835- tm .assert_index_equal (tm .makeIntIndex (3 ).map (mapper ), expected )
836-
837- # GH 12766
838- # special = []
839- special = ['catIndex' ]
840-
841- for name in special :
842- orig_values = ['a' , 'B' , 1 , 'a' ]
843- new_values = ['one' , 2 , 3.0 , 'one' ]
844- cur_index = CategoricalIndex (orig_values , name = 'XXX' )
845- expected = CategoricalIndex (new_values ,
846- name = 'XXX' , categories = [3.0 , 2 , 'one' ])
847-
848- mapper = pd .Series (new_values [:- 1 ], index = orig_values [:- 1 ])
849- output = cur_index .map (mapper )
850- # Order of categories in output can be different
851- tm .assert_index_equal (expected , output )
836+ result = tm .makeIntIndex (3 ).map (mapper )
837+ tm .assert_index_equal (result , expected )
852838
853- mapper = {o : n for o , n in
854- zip (orig_values [:- 1 ], new_values [:- 1 ])}
855- output = cur_index .map (mapper )
856- # Order of categories in output can be different
857- tm .assert_index_equal (expected , output )
839+ for name in self .indices .keys ():
840+ if name == 'catIndex' :
841+ # Tested in test_categorical
842+ continue
858843
859- for name in list (set (self .indices .keys ()) - set (special )):
860844 cur_index = self .indices [name ]
861845 expected = Index (np .arange (len (cur_index ), 0 , - 1 ))
862846 mapper = pd .Series (expected , index = cur_index )
863847 tm .assert_index_equal (expected , cur_index .map (mapper ))
864848
865849 mapper = {o : n for o , n in
866850 zip (cur_index , expected )}
851+ # If the mapper is empty the expected index type is Int64Index
852+ # but the output defaults to Float64 so I treat it independently
867853 if mapper :
868854 tm .assert_index_equal (expected , cur_index .map (mapper ))
869855 else :
870- # The expected index type is Int64Index
871- # but the output defaults to Float64
872856 tm .assert_index_equal (Float64Index ([]),
873857 cur_index .map (mapper ))
874858
875- def test_map_with_categorical_series (self ):
876- # GH 12756
877- a = Index ([1 , 2 , 3 , 4 ])
878- b = Series (["even" , "odd" , "even" , "odd" ],
879- dtype = "category" )
880- c = Series (["even" , "odd" , "even" , "odd" ])
881-
882- exp = CategoricalIndex (["odd" , "even" , "odd" , np .nan ])
883- tm .assert_index_equal (a .map (b ), exp )
884- exp = Index (["odd" , "even" , "odd" , np .nan ])
885- tm .assert_index_equal (a .map (c ), exp )
886-
887859 def test_map_with_non_function_missing_values (self ):
888860 # GH 12756
889861 expected = Index ([2. , np .nan , 'foo' ])
0 commit comments