{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/algorithms.py#L1877-L1913","documentation":"The map_array() function (which powers Series.map and similar) accepts an na_action parameter that controls how NaN values are handled: either None (pass NaN to the mapping function) or 'ignore' (propagate NaN without calling the function). Any other value for na_action is rejected with a ValueError. This is a strict API contract — there is no third option.","triggerScenarios":"Calling s.map(func, na_action='skip') or s.map(func, na_action=True) — misspelling the valid value or passing a boolean. Passing na_action from a variable or config that was not validated. Using 'drop' or 'omit' instead of the correct 'ignore'.","commonSituations":"Confusing pandas' na_action='ignore' with other libraries' NaN-handling parameters (e.g., skipna=True). Copying code from a different API that uses different sentinel values. Passing a dynamically-sourced parameter without validating it.","solutions":["Use na_action='ignore' to skip NaN, or na_action=None to pass NaN to the function.","Validate the na_action value before calling map: assert na_action in (None, 'ignore').","If building a configurable wrapper, map user-friendly names to the valid values."],"exampleFix":"# before\ns.map(my_func, na_action='skip')\n\n# after\ns.map(my_func, na_action='ignore')","handlingStrategy":"validation","validationCode":"VALID_NA_ACTIONS = (None, 'ignore')\n\ndef safe_map(series, mapper, na_action=None):\n    if na_action not in VALID_NA_ACTIONS:\n        raise ValueError(f\"na_action must be one of {VALID_NA_ACTIONS}, got {na_action!r}\")\n    return series.map(mapper, na_action=na_action)","typeGuard":"def is_valid_na_action(na_action) -> bool:\n    return na_action in (None, 'ignore')","tryCatchPattern":"try:\n    result = s.map(func, na_action=na_action)\nexcept ValueError as e:\n    if \"na_action\" in str(e):\n        result = s.map(func, na_action=None)  # default\n    else:\n        raise","preventionTips":["Only use na_action='ignore' or na_action=None with Series.map.","Do not confuse pandas' na_action with skipna parameters from other APIs.","Validate na_action against the allowed set before passing it to map."],"tags":["pandas","map","na-action","parameter-validation","valueerror"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}