{"record":{"id":"b6b4291b4dd48b76","repo":"pandas-dev/pandas","slug":"na-action-must-either-be-ignore-or-none-na-act","errorCode":null,"errorMessage":"na_action must either be 'ignore' or None, {na_action} was passed","messagePattern":"na_action must either be 'ignore' or None, (.+?) was passed","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/algorithms.py","lineNumber":1895,"sourceCode":"    ----------\n    mapper : function, dict, or Series\n        Mapping correspondence.\n    na_action : {None, 'ignore'}, default None\n        If 'ignore', propagate NA values, without passing them to the\n        mapping correspondence.\n\n    Returns\n    -------\n    Union[ndarray, Index, ExtensionArray]\n        The output of the mapping function applied to the array.\n        If the function returns a tuple with more than one element\n        a MultiIndex will be returned.\n    \"\"\"\n    from pandas import Index\n\n    if na_action not in (None, \"ignore\"):\n        msg = f\"na_action must either be 'ignore' or None, {na_action} was passed\"\n        raise ValueError(msg)\n\n    # we can fastpath dict/Series to an efficient map\n    # as we know that we are not going to have to yield\n    # python types\n    if is_dict_like(mapper):\n        if isinstance(mapper, dict) and hasattr(mapper, \"__missing__\"):\n            # If a dictionary subclass defines a default value method,\n            # convert mapper to a lookup function (GH #15999).\n            dict_with_default = mapper\n            mapper = lambda x: dict_with_default[\n                np.nan if isinstance(x, float) and np.isnan(x) else x\n            ]\n        else:\n            # Dictionary does not have a default. Thus it's safe to\n            # convert to a Series for efficiency.\n            # we specify the keys here to handle the\n            # possibility that they are tuples\n","sourceCodeStart":1877,"sourceCodeEnd":1913,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/algorithms.py#L1877-L1913","documentation":"Raised by pandas.core.algorithms.map_values (used by Series.map/Index.map) when na_action is neither None nor the string 'ignore'. map only supports two NA-handling modes: propagate NaN (None) or skip NaN ('ignore'); any other value is rejected.","triggerScenarios":"s.map(func, na_action='skip'), s.map(func, na_action=True), s.map(func, na_action=False), or any value other than None/'ignore'.","commonSituations":"Users coming from fillna/dropna APIs who assume na_action='skip'; passing booleans; typos like na_action='Ignor'; copy-pasting kwargs from a different function.","solutions":["Use na_action='ignore' to skip NaN, or na_action=None to propagate them.","If you need custom NA handling, filter/handle NaN before calling map.","Validate na_action against {None, 'ignore'} at your boundary."],"exampleFix":"# before\ns.map(func, na_action='skip')\n# after\ns.map(func, na_action='ignore')","handlingStrategy":"validation","validationCode":"def safe_map(s, mapper, na_action=None):\n    if na_action not in (None, 'ignore'):\n        raise ValueError(\"na_action must be None or 'ignore'\")\n    return s.map(mapper, na_action=na_action)","typeGuard":"def valid_na_action(na) -> bool:\n    return na in (None, 'ignore')","tryCatchPattern":null,"preventionTips":["Use only na_action=None or na_action='ignore' with map.","Handle custom NA logic before calling map.","Validate na_action at your boundary against the two legal values."],"tags":["map","na-action","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}