@@ -812,60 +812,32 @@ def test_map_tseries_indices_return_index(self):
812812 tm.assert_index_equal(exp, date_index.map(lambda x: x.hour))
813813
814814 def test_map_with_dict_and_series(self):
815+ # GH 12756
815816 expected = Index(['foo', 'bar', 'baz'])
816817 mapper = Series(expected.values, index=[0, 1, 2])
817- tm.assert_index_equal(tm.makeIntIndex(3).map(mapper), expected)
818-
819- # GH 12766
820- # special = []
821- special = ['catIndex']
822-
823- for name in special:
824- orig_values = ['a', 'B', 1, 'a']
825- new_values = ['one', 2, 3.0, 'one']
826- cur_index = CategoricalIndex(orig_values, name='XXX')
827- expected = CategoricalIndex(new_values,
828- name='XXX', categories=[3.0, 2, 'one'])
829-
830- mapper = pd.Series(new_values[:-1], index=orig_values[:-1])
831- output = cur_index.map(mapper)
832- # Order of categories in output can be different
833- tm.assert_index_equal(expected, output)
818+ result = tm.makeIntIndex(3).map(mapper)
819+ tm.assert_index_equal(result, expected)
834820
835- mapper = {o: n for o, n in
836- zip(orig_values[:-1], new_values[:-1])}
837- output = cur_index.map(mapper)
838- # Order of categories in output can be different
839- tm.assert_index_equal(expected, output)
821+ for name in self.indices.keys():
822+ if name == 'catIndex':
823+ # Tested in test_categorical
824+ continue
840825
841- for name in list(set(self.indices.keys()) - set(special)):
842826 cur_index = self.indices[name]
843827 expected = Index(np.arange(len(cur_index), 0, -1))
844828 mapper = pd.Series(expected, index=cur_index)
845829 tm.assert_index_equal(expected, cur_index.map(mapper))
846830
847831 mapper = {o: n for o, n in
848832 zip(cur_index, expected)}
833+ # If the mapper is empty the expected index type is Int64Index
834+ # but the output defaults to Float64 so I treat it independently
849835 if mapper:
850836 tm.assert_index_equal(expected, cur_index.map(mapper))
851837 else:
852- # The expected index type is Int64Index
853- # but the output defaults to Float64
854838 tm.assert_index_equal(Float64Index([]),
855839 cur_index.map(mapper))
856840
857- def test_map_with_categorical_series(self):
858- # GH 12756
859- a = Index([1, 2, 3, 4])
860- b = Series(["even", "odd", "even", "odd"],
861- dtype="category")
862- c = Series(["even", "odd", "even", "odd"])
863-
864- exp = CategoricalIndex(["odd", "even", "odd", np.nan])
865- tm.assert_index_equal(a.map(b), exp)
866- exp = Index(["odd", "even", "odd", np.nan])
867- tm.assert_index_equal(a.map(c), exp)
868-
869841 def test_map_with_non_function_missing_values(self):
870842 # GH 12756
871843 expected = Index([2., np.nan, 'foo'])
0 commit comments