{"record":{"id":"adf08763ac53470d","repo":"pandas-dev/pandas","slug":"by-row-by-row-not-allowed","errorCode":null,"errorMessage":"by_row={by_row} not allowed","messagePattern":"by_row=(.+?) not allowed","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/apply.py","lineNumber":932,"sourceCode":"\nclass FrameApply(NDFrameApply):\n    obj: DataFrame\n\n    def __init__(\n        self,\n        obj: AggObjType,\n        func: AggFuncType,\n        raw: bool,\n        result_type: str | None,\n        *,\n        by_row: Literal[False, \"compat\"] = False,\n        engine: str = \"python\",\n        engine_kwargs: dict[str, bool] | None = None,\n        args,\n        kwargs,\n    ) -> None:\n        if by_row is not False and by_row != \"compat\":\n            raise ValueError(f\"by_row={by_row} not allowed\")\n        super().__init__(\n            obj,\n            func,\n            raw,\n            result_type,\n            by_row=by_row,\n            engine=engine,\n            engine_kwargs=engine_kwargs,\n            args=args,\n            kwargs=kwargs,\n        )\n\n    # ---------------------------------------------------------------\n    # Abstract Methods\n\n    @property\n    @abc.abstractmethod\n    def result_index(self) -> Index:","sourceCodeStart":914,"sourceCodeEnd":950,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/apply.py#L914-L950","documentation":"Raised in the `FrameApply` (DataFrame apply) constructor when `by_row` is set to any value other than `False` or the literal `'compat'`. `by_row` is a Series.apply-specific parameter that pandas forwards internally; on DataFrame.apply only the two sentinel values are meaningful, so anything else (including `True`) is rejected up front.","triggerScenarios":"Calling `df.apply(func, by_row=True)`, `df.apply(func, by_row='rows')`, or any non-sentinel value. The check `by_row is not False and by_row != 'compat'` is strict.","commonSituations":"Users copy a `by_row=...` argument from a Series.apply example into a DataFrame.apply call, or pass `True` assuming it is a boolean toggle.","solutions":["Remove the `by_row` argument from DataFrame.apply calls — it is not a public knob for frames.","If you need row-wise application, use `df.apply(func, axis=1)`.","If you truly need the compat behavior, pass the literal string `by_row='compat'`."],"exampleFix":"// before\ndf.apply(func, by_row=True)\n// after\ndf.apply(func, axis=1)","handlingStrategy":"type-guard","validationCode":"def frame_apply(df, func, by_row=False, **kw):\n    if by_row not in (False, 'compat'):\n        raise ValueError(\"DataFrame.apply only accepts by_row=False or 'compat'; got %r\" % (by_row,))\n    return df.apply(func, by_row=by_row, **kw)","typeGuard":"from typing import Literal\nByRow = Literal[False, 'compat']\ndef is_valid_frame_by_row(by_row) -> bool:\n    return by_row is False or by_row == 'compat'","tryCatchPattern":"try:\n    out = df.apply(func, by_row=by_row)\nexcept ValueError as e:\n    if 'by_row=' in str(e):\n        out = df.apply(func, axis=1)  # use the proper row-wise path\n    else:\n        raise","preventionTips":["Do not forward Series-apply's by_row into DataFrame-apply.","Use axis=1 for row-wise DataFrame.apply.","Type-annotate by_row at API boundaries to surface bad values."],"tags":["pandas","apply","by-row","argument-validation","valueerror"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}