{"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":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":1621,"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":1603,"sourceCodeEnd":1639,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/series/series.py#L1603-L1639","documentation":"Series.__array_ufunc__ supports only method='__call__' — i.e. invoking a ufunc directly. NumPy also dispatches other methods like np.reduce, np.accumulate, or np.outer through __array_ufunc__; those are not implemented for Series and raise NotImplementedError.","triggerScenarios":"Calling np.add.reduce(srs), np.multiply.accumulate(srs), np.subtract.outer(srs, other), or any ufunc method other than plain ufunc(...) with a pl.Series argument.","commonSituations":"Porting numpy code to polars without realizing ufunc methods aren't dispatched; using np.sum-style reduction helpers that call .reduce internally.","solutions":["Use the Series built-in methods: srs.sum(), srs.cum_sum(), etc.","Call the ufunc directly: np.add(srs, other) instead of np.add.reduce(...)","Convert to numpy first: np.add.reduce(srs.to_numpy())"],"exampleFix":"// before\nnp.add.reduce(srs)\n// after\nsrs.sum()","handlingStrategy":"fallback","validationCode":"method = getattr(ufunc, 'method', '__call__') if hasattr(ufunc, 'method') else '__call__'\nif method != '__call__':\n    raise TypeError('use Series methods instead of ufunc methods')","typeGuard":null,"tryCatchPattern":"try:\n    out = np.add.reduce(srs)\nexcept NotImplementedError:\n    out = srs.sum()  # polars-native reduction","preventionTips":["Use Series methods (sum, cum_sum, etc.) instead of ufunc methods","Only apply ufuncs by direct call on Series","Convert to numpy (srs.to_numpy()) when ufunc methods are required"],"tags":["numpy","polars","not-implemented","ufunc"],"backgroundTag":"method-not-implemented","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}