{"record":{"id":"1adcd6b541890744","repo":"pandas-dev/pandas","slug":"operation-func-does-not-support-axis-1","errorCode":null,"errorMessage":"Operation {func} does not support axis=1","messagePattern":"Operation (.+?) does not support axis=1","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/apply.py","lineNumber":737,"sourceCode":"\n        obj = self.obj\n\n        from pandas.core.groupby.generic import (\n            DataFrameGroupBy,\n            SeriesGroupBy,\n        )\n\n        # Support for `frame.transform('method')`\n        # Some methods (shift, etc.) require the axis argument, others\n        # don't, so inspect and insert if necessary.\n        method = getattr(obj, func, None)\n        if callable(method):\n            sig = inspect.getfullargspec(method)\n            arg_names = (*sig.args, *sig.kwonlyargs)\n            if self.axis != 0 and (\n                \"axis\" not in arg_names or func in (\"corrwith\", \"skew\")\n            ):\n                raise ValueError(f\"Operation {func} does not support axis=1\")\n            if \"axis\" in arg_names and not isinstance(\n                obj, (SeriesGroupBy, DataFrameGroupBy)\n            ):\n                self.kwargs[\"axis\"] = self.axis\n        return self._apply_str(obj, func, *self.args, **self.kwargs)\n\n    def apply_list_or_dict_like(self) -> DataFrame | Series:\n        \"\"\"\n        Compute apply in case of a list-like or dict-like.\n\n        Returns\n        -------\n        result: Series, DataFrame, or None\n            Result when self.func is a list-like or dict-like, None otherwise.\n        \"\"\"\n\n        if self.engine == \"numba\":\n            raise NotImplementedError(","sourceCodeStart":719,"sourceCodeEnd":755,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/apply.py#L719-L755","documentation":"Raised inside `apply_str` when the user calls a string-named method on axis=1 but that method does not accept an `axis` argument (or is one of the excluded methods like 'corrwith'/'skew'). Most DataFrame methods are column-oriented (axis=0); applying them across rows is unsupported for these specific names.","triggerScenarios":"`df.apply('corrwith', axis=1)`, `df.apply('skew', axis=1)` (excluded explicitly), or `df.apply('<method_without_axis_param>', axis=1)` where the method signature lacks an `axis` parameter.","commonSituations":"Auto-dispatching a list of method names against axis=1 generically; misremembering which methods support row-wise operation; version changes that removed axis support from a method.","solutions":["Call the method directly without axis, or operate on `df.T` and translate back: `getattr(df.T, func)().T`.","Drop axis=1 for methods that are inherently column-oriented.","For 'corrwith'/'skew', use the dedicated method with axis=0 or transpose the frame."],"exampleFix":"# before\ndf.apply('corrwith', axis=1, other=other)\n# after\ndf.T.corrwith(other.T).T  # or restructure to axis=0","handlingStrategy":"validation","validationCode":"import inspect\n\ndef supports_axis1_str(df, func_name):\n    method = getattr(df, func_name, None)\n    if not callable(method):\n        return False\n    spec = inspect.getfullargspec(method)\n    return 'axis' in (*spec.args, *spec.kwonlyargs) and func_name not in ('corrwith', 'skew')\n\nif supports_axis1_str(df, 'sum'):\n    df.apply('sum', axis=1)","typeGuard":"def is_axis1_supported(df, func_name) -> bool:\n    return supports_axis1_str(df, func_name)","tryCatchPattern":"try:\n    df.apply(func_name, axis=1)\nexcept ValueError as e:\n    if 'does not support axis=1' in str(e):\n        getattr(df.T, func_name)().T\n    else:\n        raise","preventionTips":["Do not assume all string method names support axis=1; check the method signature.","Operate on df.T and transpose the result for row-wise reductions."],"tags":["pandas","apply","axis","valueerror","string-dispatch"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}