From 251727d4e9f4ea6291821f05a0af441fb1f9a0c4 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 16:47:30 -0500 Subject: [PATCH 01/17] Add test --- pandas/tests/series/test_apply.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index a4c55a80a9f0f..a78121cada666 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -787,3 +787,9 @@ def test_map_float_to_string_precision(self): result = ser.map(lambda val: str(val)).to_dict() expected = {0: "0.3333333333333333"} assert result == expected + + def test_map_with_invalid_na_action_raises(self): + s = pd.Series([1, 2, 3]) + msg = "na_action must either be 'ignore' or None" + with pytest.raises(ValueError, match=msg): + s.map(lambda x: x, na_action="____") From 4df04624fb296bb4f0a2ddc78d16fdbc6655e97a Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 16:47:52 -0500 Subject: [PATCH 02/17] Raise --- pandas/core/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index bf2ed02c57a29..17ac92006adb3 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1167,12 +1167,12 @@ def _map_values(self, mapper, na_action=None): values = self.astype(object) values = getattr(values, "values", values) if na_action == "ignore": - def map_f(values, f): return lib.map_infer_mask(values, f, isna(values).view(np.uint8)) - - else: + elif na_action is None: map_f = lib.map_infer + else: + raise ValueError("na_action must either be 'ignore' or None") # mapper is a function new_values = map_f(values, mapper) From 6c7a41f764080ec47d463b07338dfd8d77816e7d Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 16:50:03 -0500 Subject: [PATCH 03/17] Add note --- doc/source/whatsnew/v1.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 0d3a9a8f969a4..13c139db5e6d9 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -402,6 +402,7 @@ Other - Fixed :func:`pandas.testing.assert_series_equal` to correctly raise if left object is a different subclass with ``check_series_type=True`` (:issue:`32670`). - :meth:`IntegerArray.astype` now supports ``datetime64`` dtype (:issue:32538`) - Fixed bug in :func:`pandas.testing.assert_series_equal` where dtypes were checked for ``Interval`` and ``ExtensionArray`` operands when ``check_dtype`` was ``False`` (:issue:`32747`) +- Bug in :func:`Series.map` not raising on invalid ``na_action`` .. --------------------------------------------------------------------------- From b26e5356a098f6e8350b01b4b5a9057757c1adb7 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 16:54:15 -0500 Subject: [PATCH 04/17] func -> meth --- doc/source/whatsnew/v1.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 13c139db5e6d9..25c94083b8315 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -402,7 +402,7 @@ Other - Fixed :func:`pandas.testing.assert_series_equal` to correctly raise if left object is a different subclass with ``check_series_type=True`` (:issue:`32670`). - :meth:`IntegerArray.astype` now supports ``datetime64`` dtype (:issue:32538`) - Fixed bug in :func:`pandas.testing.assert_series_equal` where dtypes were checked for ``Interval`` and ``ExtensionArray`` operands when ``check_dtype`` was ``False`` (:issue:`32747`) -- Bug in :func:`Series.map` not raising on invalid ``na_action`` +- Bug in :meth:`Series.map` not raising on invalid ``na_action`` .. --------------------------------------------------------------------------- From 0f2cde87a7cfd59a2f38b9dc82083c4bf4e584c4 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 17:32:43 -0500 Subject: [PATCH 05/17] Blacken --- pandas/core/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/base.py b/pandas/core/base.py index 17ac92006adb3..ae949e3d0df55 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1167,8 +1167,10 @@ def _map_values(self, mapper, na_action=None): values = self.astype(object) values = getattr(values, "values", values) if na_action == "ignore": + def map_f(values, f): return lib.map_infer_mask(values, f, isna(values).view(np.uint8)) + elif na_action is None: map_f = lib.map_infer else: From c1a66a028e546ca75bfae59b8af9f7ca2a56867f Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 18:09:07 -0500 Subject: [PATCH 06/17] Add index case --- pandas/tests/series/test_apply.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index a78121cada666..d4305ef30e03c 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -788,8 +788,8 @@ def test_map_float_to_string_precision(self): expected = {0: "0.3333333333333333"} assert result == expected - def test_map_with_invalid_na_action_raises(self): - s = pd.Series([1, 2, 3]) + def test_map_with_invalid_na_action_raises(self, index_or_series): + s = index_or_series([1, 2, 3]) msg = "na_action must either be 'ignore' or None" with pytest.raises(ValueError, match=msg): s.map(lambda x: x, na_action="____") From c6c4edd1d9aefef9125670e8fc14bb1058f04b45 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 18:21:07 -0500 Subject: [PATCH 07/17] Revert --- pandas/tests/series/test_apply.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index d4305ef30e03c..a78121cada666 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -788,8 +788,8 @@ def test_map_float_to_string_precision(self): expected = {0: "0.3333333333333333"} assert result == expected - def test_map_with_invalid_na_action_raises(self, index_or_series): - s = index_or_series([1, 2, 3]) + def test_map_with_invalid_na_action_raises(self): + s = pd.Series([1, 2, 3]) msg = "na_action must either be 'ignore' or None" with pytest.raises(ValueError, match=msg): s.map(lambda x: x, na_action="____") From e30f4876d40679d14e88eadaa8d9d03730c7c193 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 18:21:54 -0500 Subject: [PATCH 08/17] Add index tests --- pandas/tests/indexes/test_any_index.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/tests/indexes/test_any_index.py b/pandas/tests/indexes/test_any_index.py index 86881b8984228..8fbe7c769f48e 100644 --- a/pandas/tests/indexes/test_any_index.py +++ b/pandas/tests/indexes/test_any_index.py @@ -33,3 +33,9 @@ def test_wrong_number_names(indices): def test_tolist_matches_list(indices): assert indices.tolist() == list(indices) + + +def test_map_with_invalid_na_action_raises(indices): + msg = "na_action must either be 'ignore' or None" + with pytest.raises(ValueError, match=msg): + indices.map(lambda x: x, na_action="____") From 17302b34af1c029b9af5456e49e82173d4f98dfd Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 19:30:55 -0500 Subject: [PATCH 09/17] Add na_action --- pandas/core/arrays/categorical.py | 4 ++-- pandas/core/indexes/category.py | 6 ++++-- pandas/core/indexes/extension.py | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 497a9893e6c66..dfe29d7c9a4db 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1127,7 +1127,7 @@ def remove_unused_categories(self, inplace=False): if not inplace: return cat - def map(self, mapper): + def map(self, mapper, na_action=None): """ Map categories using input correspondence (dict, Series, or function). @@ -1196,7 +1196,7 @@ def map(self, mapper): >>> cat.map({'a': 'first', 'b': 'second'}) Index(['first', 'second', nan], dtype='object') """ - new_categories = self.categories.map(mapper) + new_categories = self.categories.map(mapper, na_action=na_action) try: return self.from_codes( self._codes.copy(), categories=new_categories, ordered=self.ordered diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index 52423c4008399..e5020363fc015 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -612,7 +612,7 @@ def _maybe_cast_slice_bound(self, label, side, kind): return super()._maybe_cast_slice_bound(label, side, kind) - def map(self, mapper): + def map(self, mapper, na_action=None): """ Map values using input correspondence (a dict, Series, or function). @@ -679,7 +679,9 @@ def map(self, mapper): >>> idx.map({'a': 'first', 'b': 'second'}) Index(['first', 'second', nan], dtype='object') """ - return self._shallow_copy_with_infer(self._values.map(mapper)) + return self._shallow_copy_with_infer( + self._values.map(mapper, na_action=na_action) + ) def delete(self, loc): """ diff --git a/pandas/core/indexes/extension.py b/pandas/core/indexes/extension.py index 6d5f0dbb830f9..679247675bf27 100644 --- a/pandas/core/indexes/extension.py +++ b/pandas/core/indexes/extension.py @@ -5,6 +5,7 @@ import numpy as np +import pandas._libs.lib as lib from pandas.compat.numpy import function as nv from pandas.errors import AbstractMethodError from pandas.util._decorators import Appender, cache_readonly @@ -15,6 +16,7 @@ is_object_dtype, ) from pandas.core.dtypes.generic import ABCSeries +from pandas.core.dtypes.missing import isna from pandas.core.arrays import ExtensionArray from pandas.core.indexers import deprecate_ndim_indexing @@ -291,8 +293,18 @@ def _get_unique_index(self, dropna=False): def map(self, mapper, na_action=None): # Try to run function on index first, and then on elements of index # Especially important for group-by functionality + if na_action == "ignore": + + def map_f(values, f): + return lib.map_infer_mask(values, f, isna(values).view(np.uint8)) + + elif na_action is None: + map_f = lib.map_infer + else: + raise ValueError("na_action must either be 'ignore' or None") + try: - result = mapper(self) + result = map_f(self, mapper) # Try to use this result if we can if isinstance(result, np.ndarray): @@ -302,7 +314,7 @@ def map(self, mapper, na_action=None): raise TypeError("The map function must return an Index object") return result except Exception: - return self.astype(object).map(mapper) + return self.astype(object).map(mapper, na_action=na_action) @Appender(Index.astype.__doc__) def astype(self, dtype, copy=True): From 8351abf97798ade075d1d01b5994cccf5be3752d Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 19:43:07 -0500 Subject: [PATCH 10/17] Update docstring --- pandas/core/arrays/categorical.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index dfe29d7c9a4db..943ab86e6fb8d 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1145,6 +1145,9 @@ def map(self, mapper, na_action=None): mapper : function, dict, or Series Mapping correspondence. + na_action : 'ignore' or None, default None + Propagate NaN values if 'ignore', otherwise pass to the mapper. + Returns ------- pandas.Categorical or pandas.Index From 7d3ca08da3c39587fbf351daa31001c2ec078384 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 19:43:20 -0500 Subject: [PATCH 11/17] Update release notes --- doc/source/whatsnew/v1.1.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 25c94083b8315..dce2b8abd4fcb 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -240,6 +240,7 @@ Categorical - Bug when passing categorical data to :class:`Index` constructor along with ``dtype=object`` incorrectly returning a :class:`CategoricalIndex` instead of object-dtype :class:`Index` (:issue:`32167`) - Bug where :class:`Categorical` comparison operator ``__ne__`` would incorrectly evaluate to ``False`` when either element was missing (:issue:`32276`) - :meth:`Categorical.fillna` now accepts :class:`Categorical` ``other`` argument (:issue:`32420`) +- Bug in :meth:`Categorical.map` not supporting the ``na_action`` parameter Datetimelike ^^^^^^^^^^^^ @@ -403,6 +404,7 @@ Other - :meth:`IntegerArray.astype` now supports ``datetime64`` dtype (:issue:32538`) - Fixed bug in :func:`pandas.testing.assert_series_equal` where dtypes were checked for ``Interval`` and ``ExtensionArray`` operands when ``check_dtype`` was ``False`` (:issue:`32747`) - Bug in :meth:`Series.map` not raising on invalid ``na_action`` +- Bug in :meth:`ExtensionIndex.map` where the ``na_action`` parameter was ignored .. --------------------------------------------------------------------------- From 3aa2b8e598997da421aec57e7682daccb809e17c Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Tue, 17 Mar 2020 21:00:52 -0500 Subject: [PATCH 12/17] Cast to numpy --- pandas/core/indexes/extension.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/extension.py b/pandas/core/indexes/extension.py index 679247675bf27..5cff520b16443 100644 --- a/pandas/core/indexes/extension.py +++ b/pandas/core/indexes/extension.py @@ -304,7 +304,7 @@ def map_f(values, f): raise ValueError("na_action must either be 'ignore' or None") try: - result = map_f(self, mapper) + result = map_f(self.to_numpy(na_value=np.nan), mapper) # Try to use this result if we can if isinstance(result, np.ndarray): From 84cbea5419f0d681d73d81b364938bccb77e1f7e Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Wed, 18 Mar 2020 18:41:24 -0500 Subject: [PATCH 13/17] Update test --- pandas/tests/groupby/test_grouping.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index efcd22f9c0c82..ee688a930de2c 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -392,8 +392,8 @@ def test_groupby_grouper_f_sanity_checked(self): # when the elements are Timestamp. # the result is Index[0:6], very confusing. - msg = r"Grouper result violates len\(labels\) == len\(data\)" - with pytest.raises(AssertionError, match=msg): + msg = r"'Timestamp' object is not subscriptable" + with pytest.raises(TypeError, match=msg): ts.groupby(lambda key: key[0:6]) def test_grouping_error_on_multidim_input(self, df): From 58c8f1d1c400ecc3837eb72e99335cc1bfd935a5 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Wed, 18 Mar 2020 18:51:05 -0500 Subject: [PATCH 14/17] Undo --- doc/source/whatsnew/v1.1.0.rst | 2 -- pandas/core/arrays/categorical.py | 7 ++----- pandas/core/indexes/category.py | 6 ++---- pandas/core/indexes/extension.py | 16 ++-------------- pandas/tests/groupby/test_grouping.py | 4 ++-- pandas/tests/indexes/test_any_index.py | 6 ------ 6 files changed, 8 insertions(+), 33 deletions(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index dce2b8abd4fcb..25c94083b8315 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -240,7 +240,6 @@ Categorical - Bug when passing categorical data to :class:`Index` constructor along with ``dtype=object`` incorrectly returning a :class:`CategoricalIndex` instead of object-dtype :class:`Index` (:issue:`32167`) - Bug where :class:`Categorical` comparison operator ``__ne__`` would incorrectly evaluate to ``False`` when either element was missing (:issue:`32276`) - :meth:`Categorical.fillna` now accepts :class:`Categorical` ``other`` argument (:issue:`32420`) -- Bug in :meth:`Categorical.map` not supporting the ``na_action`` parameter Datetimelike ^^^^^^^^^^^^ @@ -404,7 +403,6 @@ Other - :meth:`IntegerArray.astype` now supports ``datetime64`` dtype (:issue:32538`) - Fixed bug in :func:`pandas.testing.assert_series_equal` where dtypes were checked for ``Interval`` and ``ExtensionArray`` operands when ``check_dtype`` was ``False`` (:issue:`32747`) - Bug in :meth:`Series.map` not raising on invalid ``na_action`` -- Bug in :meth:`ExtensionIndex.map` where the ``na_action`` parameter was ignored .. --------------------------------------------------------------------------- diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 943ab86e6fb8d..497a9893e6c66 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1127,7 +1127,7 @@ def remove_unused_categories(self, inplace=False): if not inplace: return cat - def map(self, mapper, na_action=None): + def map(self, mapper): """ Map categories using input correspondence (dict, Series, or function). @@ -1145,9 +1145,6 @@ def map(self, mapper, na_action=None): mapper : function, dict, or Series Mapping correspondence. - na_action : 'ignore' or None, default None - Propagate NaN values if 'ignore', otherwise pass to the mapper. - Returns ------- pandas.Categorical or pandas.Index @@ -1199,7 +1196,7 @@ def map(self, mapper, na_action=None): >>> cat.map({'a': 'first', 'b': 'second'}) Index(['first', 'second', nan], dtype='object') """ - new_categories = self.categories.map(mapper, na_action=na_action) + new_categories = self.categories.map(mapper) try: return self.from_codes( self._codes.copy(), categories=new_categories, ordered=self.ordered diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index e5020363fc015..52423c4008399 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -612,7 +612,7 @@ def _maybe_cast_slice_bound(self, label, side, kind): return super()._maybe_cast_slice_bound(label, side, kind) - def map(self, mapper, na_action=None): + def map(self, mapper): """ Map values using input correspondence (a dict, Series, or function). @@ -679,9 +679,7 @@ def map(self, mapper, na_action=None): >>> idx.map({'a': 'first', 'b': 'second'}) Index(['first', 'second', nan], dtype='object') """ - return self._shallow_copy_with_infer( - self._values.map(mapper, na_action=na_action) - ) + return self._shallow_copy_with_infer(self._values.map(mapper)) def delete(self, loc): """ diff --git a/pandas/core/indexes/extension.py b/pandas/core/indexes/extension.py index 5cff520b16443..6d5f0dbb830f9 100644 --- a/pandas/core/indexes/extension.py +++ b/pandas/core/indexes/extension.py @@ -5,7 +5,6 @@ import numpy as np -import pandas._libs.lib as lib from pandas.compat.numpy import function as nv from pandas.errors import AbstractMethodError from pandas.util._decorators import Appender, cache_readonly @@ -16,7 +15,6 @@ is_object_dtype, ) from pandas.core.dtypes.generic import ABCSeries -from pandas.core.dtypes.missing import isna from pandas.core.arrays import ExtensionArray from pandas.core.indexers import deprecate_ndim_indexing @@ -293,18 +291,8 @@ def _get_unique_index(self, dropna=False): def map(self, mapper, na_action=None): # Try to run function on index first, and then on elements of index # Especially important for group-by functionality - if na_action == "ignore": - - def map_f(values, f): - return lib.map_infer_mask(values, f, isna(values).view(np.uint8)) - - elif na_action is None: - map_f = lib.map_infer - else: - raise ValueError("na_action must either be 'ignore' or None") - try: - result = map_f(self.to_numpy(na_value=np.nan), mapper) + result = mapper(self) # Try to use this result if we can if isinstance(result, np.ndarray): @@ -314,7 +302,7 @@ def map_f(values, f): raise TypeError("The map function must return an Index object") return result except Exception: - return self.astype(object).map(mapper, na_action=na_action) + return self.astype(object).map(mapper) @Appender(Index.astype.__doc__) def astype(self, dtype, copy=True): diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index ee688a930de2c..efcd22f9c0c82 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -392,8 +392,8 @@ def test_groupby_grouper_f_sanity_checked(self): # when the elements are Timestamp. # the result is Index[0:6], very confusing. - msg = r"'Timestamp' object is not subscriptable" - with pytest.raises(TypeError, match=msg): + msg = r"Grouper result violates len\(labels\) == len\(data\)" + with pytest.raises(AssertionError, match=msg): ts.groupby(lambda key: key[0:6]) def test_grouping_error_on_multidim_input(self, df): diff --git a/pandas/tests/indexes/test_any_index.py b/pandas/tests/indexes/test_any_index.py index 8fbe7c769f48e..86881b8984228 100644 --- a/pandas/tests/indexes/test_any_index.py +++ b/pandas/tests/indexes/test_any_index.py @@ -33,9 +33,3 @@ def test_wrong_number_names(indices): def test_tolist_matches_list(indices): assert indices.tolist() == list(indices) - - -def test_map_with_invalid_na_action_raises(indices): - msg = "na_action must either be 'ignore' or None" - with pytest.raises(ValueError, match=msg): - indices.map(lambda x: x, na_action="____") From 1b47106da13c33833222addd6fcbd240db29a561 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Wed, 18 Mar 2020 19:37:31 -0500 Subject: [PATCH 15/17] Fix message --- pandas/core/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index ae949e3d0df55..586db14609845 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1174,7 +1174,11 @@ def map_f(values, f): elif na_action is None: map_f = lib.map_infer else: - raise ValueError("na_action must either be 'ignore' or None") + msg = ( + "na_action must either be 'ignore' or None, " + f"{na_action} was passed" + ) + raise ValueError(msg) # mapper is a function new_values = map_f(values, mapper) From 3602f61ac07aac0bd46a24192f38f99deb5652c9 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Wed, 18 Mar 2020 19:37:51 -0500 Subject: [PATCH 16/17] Add issue comment --- pandas/tests/series/test_apply.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index a78121cada666..248b1073add21 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -789,6 +789,7 @@ def test_map_float_to_string_precision(self): assert result == expected def test_map_with_invalid_na_action_raises(self): + # https://github.com/pandas-dev/pandas/issues/32815 s = pd.Series([1, 2, 3]) msg = "na_action must either be 'ignore' or None" with pytest.raises(ValueError, match=msg): From c1d928d21321331b23621f2626b51802c211abae Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Wed, 18 Mar 2020 19:39:30 -0500 Subject: [PATCH 17/17] Note --- doc/source/whatsnew/v1.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 25c94083b8315..233f503f8becd 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -402,7 +402,7 @@ Other - Fixed :func:`pandas.testing.assert_series_equal` to correctly raise if left object is a different subclass with ``check_series_type=True`` (:issue:`32670`). - :meth:`IntegerArray.astype` now supports ``datetime64`` dtype (:issue:32538`) - Fixed bug in :func:`pandas.testing.assert_series_equal` where dtypes were checked for ``Interval`` and ``ExtensionArray`` operands when ``check_dtype`` was ``False`` (:issue:`32747`) -- Bug in :meth:`Series.map` not raising on invalid ``na_action`` +- Bug in :meth:`Series.map` not raising on invalid ``na_action`` (:issue:`32815`) .. ---------------------------------------------------------------------------