{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/apply.py#L719-L755","documentation":"Raised in `apply_str` (the string-dispatch path) when the user passes `axis=1` to a method that either has no `axis` parameter on its signature or is explicitly excluded (`corrwith`, `skew`). Pandas inspects the method's fullargspec; if `axis` is not accepted (or the method is on the exclusion list) it cannot honor `axis=1` and raises immediately rather than silently running along the wrong axis.","triggerScenarios":"Calls like `df.apply('corrwith', axis=1)`, `df.apply('skew', axis=1)`, or `df.apply('<method_without_axis_param>', axis=1)`. Common with frame.transform('method', axis=1) routing through the same path.","commonSituations":"Passing axis=1 globally to a pipeline that calls apply with method-name strings; misremembering which stats methods support row-wise operation; migrating code from axis=0 default to row-wise and assuming all methods comply.","solutions":["Drop the `axis=1` argument for methods that only operate column-wise (corrwith, skew without axis support).","For row-wise skew, call `df.skew(axis=1)` directly on the DataFrame instead of through apply.","If you need a row-wise custom op, pass a callable (not a string) to `df.apply(..., axis=1)`."],"exampleFix":"// before\ndf.apply('skew', axis=1)\n// after\ndf.skew(axis=1)","handlingStrategy":"validation","validationCode":"AXIS1_BLOCKED = {'corrwith', 'skew'}\ndef apply_str_axis1_safe(df, func, axis=0):\n    import inspect\n    if axis == 1 and isinstance(func, str):\n        method = getattr(df, func, None)\n        if method is None:\n            raise ValueError(f'{func} not found on DataFrame')\n        sig = inspect.getfullargspec(method)\n        arg_names = (*sig.args, *sig.kwonlyargs)\n        if 'axis' not in arg_names or func in AXIS1_BLOCKED:\n            raise ValueError(f'{func} does not support axis=1; call directly or drop axis')\n    return df.apply(func, axis=axis)","typeGuard":"def str_method_supports_axis1(df, func) -> bool:\n    import inspect\n    if func in ('corrwith', 'skew'):\n        return False\n    m = getattr(df, func, None)\n    if not callable(m):\n        return False\n    spec = inspect.getfullargspec(m)\n    return 'axis' in (*spec.args, *spec.kwonlyargs)","tryCatchPattern":"try:\n    out = df.apply(func, axis=1)\nexcept ValueError as e:\n    if 'does not support axis=1' in str(e):\n        out = getattr(df, func)()  # fall back to default axis\n    else:\n        raise","preventionTips":["Prefer calling stats methods directly (df.skew()) over apply-with-strings.","Maintain a project-level allowlist of axis=1-compatible string methods.","Avoid passing axis=1 to apply-with-string globally."],"tags":["pandas","apply","axis","string-dispatch","valueerror"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}