diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 8c1ce1195369d..5a10c01e36608 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -415,6 +415,7 @@ Other - Fix corrupted error message when calling ``pandas.libs._json.encode()`` on a 0d array (:issue:`18878`) - Fix :class:`AbstractHolidayCalendar` to return correct results for years after 2030 (now goes up to 2200) (:issue:`27790`) +- :meth:`IndexOpsMixin._map_values` ABCSeries mapper maps unmapped categories to "" instead of NaN .. _whatsnew_1000.contributors: diff --git a/pandas/core/base.py b/pandas/core/base.py index 5ae3926952a67..ede0c6cfc5a62 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1267,7 +1267,7 @@ def _map_values(self, mapper, na_action=None): values = self.values indexer = mapper.index.get_indexer(values) - new_values = algorithms.take_1d(mapper._values, indexer) + new_values = algorithms.take_1d(mapper._values, indexer, fill_value="") return new_values diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 0dc6d24202c34..fe01436b83d8a 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1129,7 +1129,7 @@ def test_map_dictlike(self, indices, mapper): ) def test_map_with_non_function_missing_values(self, mapper): # GH 12756 - expected = Index([2.0, np.nan, "foo"]) + expected = Index([2.0, "", "foo"]) result = Index([2, 1, 0]).map(mapper) tm.assert_index_equal(expected, result)