pola-rs/polars · error · NotImplementedError
only `__call__` is implemented for numpy ufuncs on a…
Error message
only `__call__` is implemented for numpy ufuncs on a Series, got `{method!r}` What it means
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.
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())
Example fix
// before np.add.reduce(srs) // after srs.sum()
Defensive patterns
Strategy: fallback
Validate before calling
method = getattr(ufunc, 'method', '__call__') if hasattr(ufunc, 'method') else '__call__'
if method != '__call__':
raise TypeError('use Series methods instead of ufunc methods') Try / catch
try:
out = np.add.reduce(srs)
except NotImplementedError:
out = srs.sum() # polars-native reduction Prevention
- 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
When it happens
Trigger: 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.
Common situations: Porting numpy code to polars without realizing ufunc methods aren't dispatched; using np.sum-style reduction helpers that call .reduce internally.
Related errors
- could not find `apply_ufunc_
- only ufuncs that return one 1D array are supported
- can't pass a Series with missing data to a generalized…
- unsupported type for
- arr.dot query vector must be one-dimensional
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/023174e69e1ce57b.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/series/series.py:1621
return result
# We're using a regular ufunc, that operates value by value. That
# means we allowed missing data in the input, so filter it out:
validity_mask = self.is_not_null() if self.has_nulls() else F.lit(True)
for arg in inputs:
if isinstance(arg, Series) and arg.has_nulls():
validity_mask &= arg.is_not_null()
return (
result.to_frame()
.select(F.when(validity_mask).then(F.col(self.name)))
.to_series(0)
)
else:
msg = (
"only `__call__` is implemented for numpy ufuncs on a Series, got "
f"`{method!r}`"
)
raise NotImplementedError(msg)
def __arrow_c_stream__(self, requested_schema: object | None = None) -> object:
"""
Export a Series via the Arrow PyCapsule Interface.
https://arrow.apache.org/docs/dev/format/CDataInterface/PyCapsuleInterface.html
"""
return self._s.__arrow_c_stream__(requested_schema)
def _repr_html_(self) -> str_:
"""Format output data in HTML for display in Jupyter Notebooks."""
return self.to_frame()._repr_html_(_from_series=True)
def item(self, index: int | None = None) -> Any:
"""
Return the Series as a scalar, or return the element at the given index.
If no index is provided, this is equivalent to `s[0]`, with a checkView on GitHub (pinned to fe841f959e)