{"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":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":1645,"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":1627,"sourceCodeEnd":1663,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/series/series.py#L1627-L1663","documentation":"Raised in Series.__array_ufunc__ during argument collection: every input to the ufunc must be an int, float, numpy ndarray, or another Polars Series. Anything else - lists, strings, complex scalars, pandas objects, None - cannot be handed to the Rust kernel and is rejected with the argument's qualified type name.","triggerScenarios":"`np.add(s, [1, 2, 3])` (python list operand), `np.multiply(s, 'x')`, `np.add(s, 1+2j)` (complex scalar is not int/float), `np.exp(s, out=None)`-style passing a pandas Series. Series operands are converted via to_physical() and rechunked first, so those pass.","commonSituations":"Passing raw python lists where a converted array was intended; mixing pandas and polars objects in one expression; complex-valued operands; leftover None sentinel arguments in generic numeric wrappers.","solutions":["Convert the operand before the call: `np.add(s, np.array([1, 2, 3]))` or `np.add(s, pl.Series([1, 2, 3]))`.","Use scalars directly where possible: `np.add(s, 3)`.","Convert pandas objects: `np.add(s, pd_series.to_numpy())`.","In generic dispatch code, pre-normalize args: lists -> np.asarray, pandas -> .to_numpy()."],"exampleFix":"// before\nnp.add(s, [1, 2, 3])  # TypeError: unsupported type 'list'\n\n// after\nnp.add(s, np.array([1, 2, 3]))\n# or\nnp.add(s, pl.Series([1, 2, 3]))","handlingStrategy":"type-guard","validationCode":"def coerce_ufunc_arg(a):\n    if isinstance(a, (int, float, np.ndarray, pl.Series)):\n        return a\n    return np.asarray(a)\n\nargs = [coerce_ufunc_arg(a) for a in args]","typeGuard":"def is_ufunc_arg_supported(a) -> bool:\n    return isinstance(a, (int, float, np.ndarray, pl.Series))","tryCatchPattern":"try:\n    out = np.add(s, other)\nexcept TypeError as e:\n    if 'unsupported type' not in str(e):\n        raise\n    out = np.add(s, np.asarray(other))","preventionTips":["Convert lists/pandas objects to np.ndarray before mixing them with Series in ufunc calls.","complex scalars are rejected too - pass complex ndarrays or detach to numpy entirely."],"tags":["polars","series","numpy","ufunc","argument-validation","type-error"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}