{"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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/apply.py#L275-L311","documentation":"Raised by the Apply constructor when the `result_type` argument is not one of the four permitted values. `result_type` controls how `DataFrame.apply` shapes row-wise results, and only a fixed enum is meaningful. Any other string (including typos like 'Reduce' or 'broadcasted') is rejected at construction time. This guards downstream shape-handling code from undefined behavior.","triggerScenarios":"Calling `df.apply(func, axis=1, result_type='reduce')` (or 'broadcast'/'expand') with a misspelled value, e.g. `result_type='broadcasted'`, `result_type='Reduce'`, or `result_type='wide'`. Also triggered by passing an arbitrary string variable that was not validated before being forwarded into `apply`.","commonSituations":"Developers passing `result_type` from a config dict or CLI argument without validation; copy-paste from docs with a typo; version upgrades where the set of accepted values was tightened and previously-tolerated values now raise.","solutions":["Use one of the four accepted values exactly as written: None, 'reduce', 'broadcast', or 'expand' (case-sensitive, lowercase).","If the value comes from user/config input, validate it against the allowed set before passing to `apply`.","Omit `result_type` entirely if you want the default shape inference behavior."],"exampleFix":"# before\ndf.apply(split_col, axis=1, result_type='broadcasted')\n# after\ndf.apply(split_col, axis=1, result_type='broadcast')","handlingStrategy":"validation","validationCode":"import pandas as pd\n_VALID_RESULT_TYPES = {None, 'reduce', 'broadcast', 'expand'}\n\ndef safe_apply(df, func, result_type=None, **kw):\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, result_type=result_type, **kw)","typeGuard":"def is_valid_result_type(v) -> bool:\n    return v in {None, 'reduce', 'broadcast', 'expand'}","tryCatchPattern":"try:\n    df.apply(f, result_type=rt)\nexcept ValueError as e:\n    if 'invalid value for result_type' in str(e):\n        # log / fall back to default\n        df.apply(f)\n    else:\n        raise","preventionTips":["Centralize result_type values as constants or an enum instead of passing strings inline.","Validate externally-sourced config values before forwarding to apply."],"tags":["pandas","apply","result-type","validation","valueerror"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}