{"record":{"id":"505f41c9888eca36","repo":"pola-rs/polars","slug":"unsupported-type-qualified-type-name-arg-r-for","errorCode":null,"errorMessage":"unsupported type {qualified_type_name(arg)!r} for {arg!r}","messagePattern":"unsupported type (.+?) for (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":1531,"sourceCode":"        s = self._s\n\n        if method == \"__call__\":\n            if ufunc.nout != 1:\n                msg = \"only ufuncs that return one 1D array are supported\"\n                raise NotImplementedError(msg)\n\n            args: list[int | float | np.ndarray[Any, Any]] = []\n            for arg in inputs:\n                if isinstance(arg, (int, float, np.ndarray)):\n                    args.append(arg)\n                elif isinstance(arg, Series):\n                    phys_arg = arg.to_physical()\n                    if phys_arg._s.n_chunks() > 1:\n                        phys_arg._s.rechunk(in_place=True)\n                    args.append(phys_arg._s.to_numpy_view())  # type: ignore[arg-type]\n                else:\n                    msg = f\"unsupported type {qualified_type_name(arg)!r} for {arg!r}\"\n                    raise TypeError(msg)\n\n            # Get minimum dtype needed to be able to cast all input arguments to the\n            # same dtype.\n            dtype_char_minimum: str = np.result_type(*args).char\n\n            # Get all possible output dtypes for ufunc.\n            # Input dtypes and output dtypes seem to always match for ufunc.types,\n            # so pick all the different output dtypes.\n            dtypes_ufunc = [\n                input_output_type[-1]\n                for input_output_type in ufunc.types\n                if supported_numpy_char_code(input_output_type[-1])\n            ]\n\n            # Get the first ufunc dtype from all possible ufunc dtypes for which\n            # the input arguments can be safely cast to that ufunc dtype.\n            for dtype_ufunc in dtypes_ufunc:\n                if np.can_cast(dtype_char_minimum, dtype_ufunc):","sourceCodeStart":1513,"sourceCodeEnd":1549,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/series/series.py#L1513-L1549","documentation":"Series.__array_ufunc__ (numpy ufunc dispatch on a Series) only supports inputs it can convert to numpy views: Series, expressions, and numpy-compatible arrays. The given argument's type was not recognized, so polars raises TypeError naming the type and the argument.","triggerScenarios":"Calling a numpy ufunc (e.g. np.add, np.exp) or Series-shaped constructor path (dict_to_pydf, _sequence_of_sequence_to_pydf, etc.) with an argument of an unsupported type, e.g. a plain Python list, dict, datetime, or a pandas object passed as an operand to a ufunc alongside a pl.Series.","commonSituations":"Mixing a pl.Series with a pandas Series or list in np.ufunc(...); passing a Python scalar wrapper (np.datetime64 handled, but e.g. Decimal or custom objects not); refactored code that swapped a numpy array for a list.","solutions":["Convert the argument to a supported type before the ufunc: pl.Series(list) or np.asarray(x)","Check the operand types; replace unsupported objects (e.g. pandas Series -> .to_numpy())","Use polars-native expressions (pl.col(...).exp()) instead of numpy ufuncs when mixing types"],"exampleFix":"// before\nnp.exp(my_list + srs)\n// after\nnp.exp(pl.Series(my_list) + srs)","handlingStrategy":"type-guard","validationCode":"supported = (pl.Series, pl.Expr, np.ndarray)\nassert all(isinstance(a, supported) or np.isscalar(a) for a in args)","typeGuard":"def is_ufunc_compatible(a) -> bool:\n    return isinstance(a, (pl.Series, pl.Expr, np.ndarray)) or np.isscalar(a)","tryCatchPattern":"try:\n    out = np.exp(operand)\nexcept TypeError as e:\n    if 'unsupported type' in str(e):\n        operand = pl.Series(operand)\n        out = np.exp(operand)\n    else:\n        raise","preventionTips":["Always wrap plain Python containers in pl.Series/np.asarray before ufuncs","Don't mix pandas objects with polars Series in numpy calls","Prefer polars expressions for elementwise math on Series"],"tags":["numpy","polars","type-error","ufunc"],"backgroundTag":"invalid-argument-value","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"}