{"record":{"id":"c36d1bf2e680aa4f","repo":"pandas-dev/pandas","slug":"invalid-value-for-result-type-must-be-one-of-non","errorCode":null,"errorMessage":"invalid value for result_type, must be one of {None, 'reduce', 'broadcast', 'expand'}","messagePattern":"invalid value for result_type, must be one of (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/apply.py","lineNumber":293,"sourceCode":"        engine: str = \"python\",\n        engine_kwargs: dict[str, bool] | None = None,\n        args,\n        kwargs,\n    ) -> None:\n        self.obj = obj\n        self.raw = raw\n\n        assert by_row is False or by_row in [\"compat\", \"_compat\"]\n        self.by_row = by_row\n\n        self.args = args or ()\n        self.kwargs = kwargs or {}\n\n        self.engine = engine\n        self.engine_kwargs = {} if engine_kwargs is None else engine_kwargs\n\n        if result_type not in [None, \"reduce\", \"broadcast\", \"expand\"]:\n            raise ValueError(\n                \"invalid value for result_type, must be one \"\n                \"of {None, 'reduce', 'broadcast', 'expand'}\"\n            )\n\n        self.result_type = result_type\n\n        self.func = func\n\n    @abc.abstractmethod\n    def apply(self) -> DataFrame | Series:\n        pass\n\n    @abc.abstractmethod\n    def agg_or_apply_list_like(\n        self, op_name: Literal[\"agg\", \"apply\"]\n    ) -> DataFrame | Series:\n        pass\n","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/apply.py#L275-L311","documentation":"DataFrame.apply() accepts a result_type parameter that controls how row-wise (axis=1) results are assembled: None (infer), 'reduce' (return Series), 'broadcast' (return DataFrame with original index), or 'expand' (expand list-like results into columns). Any other string or value raises a ValueError. This validation happens in the Apply constructor before any computation begins.","triggerScenarios":"Calling df.apply(func, axis=1, result_type='expand') with a typo like 'expanded' or 'broadcasting'. Passing result_type from a variable that was set to an invalid string. Using True/False or 0/1 instead of the string sentinels.","commonSituations":"Typos in the result_type string — the valid values are short and easily misspelled. Passing result_type from configuration without validation. Copying code from documentation and introducing a typo.","solutions":["Use one of the exact valid values: None, 'reduce', 'broadcast', or 'expand'.","Validate before calling: assert result_type in (None, 'reduce', 'broadcast', 'expand').","Omit result_type entirely if the default inference behavior is acceptable."],"exampleFix":"# before\ndf.apply(func, axis=1, result_type='expanded')\n\n# after\ndf.apply(func, axis=1, result_type='expand')","handlingStrategy":"validation","validationCode":"VALID_RESULT_TYPES = (None, 'reduce', 'broadcast', 'expand')\n\ndef safe_apply(df, func, axis=0, result_type=None, **kwargs):\n    if result_type not in VALID_RESULT_TYPES:\n        raise ValueError(f\"result_type must be one of {VALID_RESULT_TYPES}, got {result_type!r}\")\n    return df.apply(func, axis=axis, result_type=result_type, **kwargs)","typeGuard":"def is_valid_result_type(rt) -> bool:\n    return rt in (None, 'reduce', 'broadcast', 'expand')","tryCatchPattern":"try:\n    result = df.apply(func, axis=1, result_type=rt)\nexcept ValueError as e:\n    if \"result_type\" in str(e):\n        result = df.apply(func, axis=1)  # default inference\n    else:\n        raise","preventionTips":["Remember the four valid result_type values: None, 'reduce', 'broadcast', 'expand'.","Validate result_type from configuration before passing to apply.","Omit result_type when the default inference behavior is sufficient."],"tags":["pandas","apply","result-type","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"}