@@ -822,60 +822,32 @@ def test_map_tseries_indices_return_index(self):
822822 tm .assert_index_equal (exp , date_index .map (lambda x : x .hour ))
823823
824824 def test_map_with_dict_and_series (self ):
825+ # GH 12756
825826 expected = Index (['foo' , 'bar' , 'baz' ])
826827 mapper = Series (expected .values , index = [0 , 1 , 2 ])
827- tm .assert_index_equal (tm .makeIntIndex (3 ).map (mapper ), expected )
828-
829- # GH 12766
830- # special = []
831- special = ['catIndex' ]
832-
833- for name in special :
834- orig_values = ['a' , 'B' , 1 , 'a' ]
835- new_values = ['one' , 2 , 3.0 , 'one' ]
836- cur_index = CategoricalIndex (orig_values , name = 'XXX' )
837- expected = CategoricalIndex (new_values ,
838- name = 'XXX' , categories = [3.0 , 2 , 'one' ])
839-
840- mapper = pd .Series (new_values [:- 1 ], index = orig_values [:- 1 ])
841- output = cur_index .map (mapper )
842- # Order of categories in output can be different
843- tm .assert_index_equal (expected , output )
828+ result = tm .makeIntIndex (3 ).map (mapper )
829+ tm .assert_index_equal (result , expected )
844830
845- mapper = {o : n for o , n in
846- zip (orig_values [:- 1 ], new_values [:- 1 ])}
847- output = cur_index .map (mapper )
848- # Order of categories in output can be different
849- tm .assert_index_equal (expected , output )
831+ for name in self .indices .keys ():
832+ if name == 'catIndex' :
833+ # Tested in test_categorical
834+ continue
850835
851- for name in list (set (self .indices .keys ()) - set (special )):
852836 cur_index = self .indices [name ]
853837 expected = Index (np .arange (len (cur_index ), 0 , - 1 ))
854838 mapper = pd .Series (expected , index = cur_index )
855839 tm .assert_index_equal (expected , cur_index .map (mapper ))
856840
857841 mapper = {o : n for o , n in
858842 zip (cur_index , expected )}
843+ # If the mapper is empty the expected index type is Int64Index
844+ # but the output defaults to Float64 so I treat it independently
859845 if mapper :
860846 tm .assert_index_equal (expected , cur_index .map (mapper ))
861847 else :
862- # The expected index type is Int64Index
863- # but the output defaults to Float64
864848 tm .assert_index_equal (Float64Index ([]),
865849 cur_index .map (mapper ))
866850
867- def test_map_with_categorical_series (self ):
868- # GH 12756
869- a = Index ([1 , 2 , 3 , 4 ])
870- b = Series (["even" , "odd" , "even" , "odd" ],
871- dtype = "category" )
872- c = Series (["even" , "odd" , "even" , "odd" ])
873-
874- exp = CategoricalIndex (["odd" , "even" , "odd" , np .nan ])
875- tm .assert_index_equal (a .map (b ), exp )
876- exp = Index (["odd" , "even" , "odd" , np .nan ])
877- tm .assert_index_equal (a .map (c ), exp )
878-
879851 def test_map_with_non_function_missing_values (self ):
880852 # GH 12756
881853 expected = Index ([2. , np .nan , 'foo' ])
0 commit comments