{"record":{"id":"85c5c446cd3e1073","repo":"pola-rs/polars","slug":"could-not-find-apply-ufunc-numpy-char-code-to-dt","errorCode":null,"errorMessage":"could not find `apply_ufunc_{numpy_char_code_to_dtype(dtype_char)}`","messagePattern":"could not find `apply_ufunc_(.+?)`","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":1592,"sourceCode":"                ufunc_input, ufunc_output = ufunc.signature.split(\"->\")\n                if ufunc_output == \"()\":\n                    # If the result a scalar, just let the function do its\n                    # thing, no need for any song and dance involving\n                    # allocation:\n                    return ufunc(*args, dtype=dtype_char, **kwargs)\n                else:\n                    allocate_output = ufunc_input == ufunc_output\n            else:\n                allocate_output = True\n\n            f = get_ffi_func(\"apply_ufunc_<>\", numpy_char_code_to_dtype(dtype_char), s)\n\n            if f is None:\n                msg = (\n                    \"could not find \"\n                    f\"`apply_ufunc_{numpy_char_code_to_dtype(dtype_char)}`\"\n                )\n                raise NotImplementedError(msg)\n\n            series = f(\n                lambda out: ufunc(*args, out=out, dtype=dtype_char, **kwargs),\n                allocate_output,\n            )\n\n            result = self._from_pyseries(series)\n            if is_generalized_ufunc:\n                # In this case we've disallowed passing in missing data, so no\n                # further processing is needed.\n                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()","sourceCodeStart":1574,"sourceCodeEnd":1610,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/series/series.py#L1574-L1610","documentation":"After determining the minimum numpy dtype char for a ufunc, polars looks up a compiled helper named apply_ufunc_<dtype> in its Rust core to run the ufunc with that dtype. If no such helper exists for the resolved dtype char, it raises NotImplementedError.","triggerScenarios":"Calling a numpy ufunc on a Series whose arguments resolve to a dtype char with no registered apply_ufunc_* helper (e.g. exotic result types from np.result_type such as complex/float16 in some builds, or object dtype).","commonSituations":"Using ufuncs that promote to an unusual dtype (e.g. np.float16 result, complex128) not covered by polars' ufunc dispatch table.","solutions":["Cast inputs to a supported dtype first, e.g. srs.cast(pl.Float64)","Avoid dtypes that promote to unsupported result types (use float64/int64/float32)","Perform the ufunc in numpy and rebuild the Series from the result"],"exampleFix":"// before\nnp.exp(srs.cast(pl.Float16))\n// after\nnp.exp(srs.cast(pl.Float64))","handlingStrategy":"type-guard","validationCode":"assert srs.dtype in (pl.Int64, pl.Float64, pl.Float32, pl.Int32), f\"unsupported ufunc dtype {srs.dtype}\"","typeGuard":"def ufunc_safe_dtype(dt: pl.DataType) -> bool:\n    return dt in (pl.Int8, pl.Int16, pl.Int32, pl.Int64, pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64, pl.Float32, pl.Float64)","tryCatchPattern":"try:\n    out = np.exp(srs)\nexcept NotImplementedError:\n    out = np.exp(srs.cast(pl.Float64))","preventionTips":["Stick to common numeric dtypes (float64/int64) before ufuncs","Avoid float16/complex promotions on Series","Cast explicitly rather than relying on np.result_type promotion"],"tags":["numpy","polars","not-implemented","ufunc","dtype"],"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"}