{"record":{"id":"023174e69e1ce57b","repo":"pola-rs/polars","slug":"only-call-is-implemented-for-numpy-ufuncs-on","errorCode":null,"errorMessage":"only `__call__` is implemented for numpy ufuncs on a Series, got `{method!r}`","messagePattern":"only `__call__` is implemented for numpy ufuncs on a Series, got `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":1735,"sourceCode":"                return result\n\n            # We're using a regular ufunc, that operates value by value. That\n            # means we allowed missing data in the input, so filter it out:\n            validity_mask = self.is_not_null() if self.has_nulls() else F.lit(True)\n            for arg in inputs:\n                if isinstance(arg, Series) and arg.has_nulls():\n                    validity_mask &= arg.is_not_null()\n            return (\n                result.to_frame()\n                .select(F.when(validity_mask).then(F.col(self.name)))\n                .to_series(0)\n            )\n        else:\n            msg = (\n                \"only `__call__` is implemented for numpy ufuncs on a Series, got \"\n                f\"`{method!r}`\"\n            )\n            raise NotImplementedError(msg)\n\n    def __arrow_c_stream__(self, requested_schema: object | None = None) -> object:\n        \"\"\"\n        Export a Series via the Arrow PyCapsule Interface.\n\n        https://arrow.apache.org/docs/dev/format/CDataInterface/PyCapsuleInterface.html\n        \"\"\"\n        return self._s.__arrow_c_stream__(requested_schema)\n\n    def _repr_html_(self) -> str_:\n        \"\"\"Format output data in HTML for display in Jupyter Notebooks.\"\"\"\n        return self.to_frame()._repr_html_(_from_series=True)\n\n    def item(self, index: int | None = None) -> Any:\n        \"\"\"\n        Return the Series as a scalar, or return the element at the given index.\n\n        If no index is provided, this is equivalent to `s[0]`, with a check","sourceCodeStart":1717,"sourceCodeEnd":1753,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/series/series.py#L1717-L1753","documentation":"Raised in Series.__array_ufunc__ when numpy invokes a ufunc method other than plain '__call__' - e.g. 'reduce', 'outer', 'accumulate', 'at', or 'reduceat'. Polars only implements the elementwise call path through its Rust kernels; reductions and outer products have no Series-dispatch implementation.","triggerScenarios":"`np.add.reduce(s)` (sum), `np.maximum.reduce(s)` (max), `np.add.accumulate(s)` (cumsum), `np.add.outer(s, s)`, `np.subtract.at(...)`. The else-branch of `if method == '__call__'` catches all of these.","commonSituations":"Aggregation code using np.<ufunc>.reduce instead of native sums; cumsum via np.add.accumulate ported from numpy pipelines; outer-product construction for pairwise features.","solutions":["Use Polars' native equivalents: `s.sum()`, `s.min()`, `s.max()`, `s.cum_sum()`, `s.cum_max()`.","For reduce over axes on 2D data, convert first: `np.add.reduce(s.to_numpy())`.","For outer products: `np.add.outer(s.to_numpy(), s.to_numpy())` and rewrap with pl.Series if needed.","In generic code, route on method: only pass '__call__' through the Series protocol; send other methods to the numpy array path."],"exampleFix":"// before\nnp.add.reduce(s)  # NotImplementedError\n\n// after\ns.sum()\n# or\nnp.add.reduce(s.to_numpy())","handlingStrategy":"fallback","validationCode":"if method != '__call__':\n    result = getattr(ufunc, method)(s.to_numpy(), **kwargs)\nelse:\n    result = ufunc(s, **kwargs)","typeGuard":"def is_call_method(method: str) -> bool:\n    return method == '__call__'","tryCatchPattern":"try:\n    out = np.add.reduce(s)\nexcept NotImplementedError:\n    out = s.sum()  # or np.add.reduce(s.to_numpy())","preventionTips":["Use native reductions: s.sum/min/max/cum_sum instead of np.<ufunc>.reduce/accumulate.","Only the '__call__' method is wired to Series; route reduce/outer/at through to_numpy()."],"tags":["polars","series","numpy","ufunc","reduce","accumulate","not-implemented"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}