{"record":{"id":"5707681d90e771e4","repo":"pola-rs/polars","slug":"series-constructor-called-with-unsupported-type-t","errorCode":null,"errorMessage":"Series constructor called with unsupported type {type(values).__name__!r} for the `values` parameter","messagePattern":"Series constructor called with unsupported type (.+?) for the `values` parameter","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":400,"sourceCode":"            )\n\n        elif isinstance(values, pl.DataFrame):\n            self._s = dataframe_to_pyseries(\n                original_name, values, dtype=dtype, strict=strict\n            )\n\n        elif hasattr(values, \"__arrow_c_array__\"):\n            self._s = PySeries.from_arrow_c_array(values)\n\n        elif hasattr(values, \"__arrow_c_stream__\"):\n            self._s = PySeries.from_arrow_c_stream(values)\n\n        else:\n            msg = (\n                f\"Series constructor called with unsupported type {type(values).__name__!r}\"\n                \" for the `values` parameter\"\n            )\n            raise TypeError(msg)\n\n    @property\n    def bin(self) -> BinaryNameSpace:\n        \"\"\"Create an object namespace of all binary related methods.\"\"\"\n        return BinaryNameSpace(self)\n\n    @property\n    def cat(self) -> CatNameSpace:\n        \"\"\"Create an object namespace of all categorical related methods.\"\"\"\n        return CatNameSpace(self)\n\n    @property\n    def dt(self) -> DateTimeNameSpace:\n        \"\"\"Create an object namespace of all datetime related methods.\"\"\"\n        return DateTimeNameSpace(self)\n\n    @property\n    def list(self) -> ListNameSpace:","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/series/series.py#L382-L418","documentation":"The Series constructor accepts only Sequences, mappings (for structs), Series, numpy arrays, pandas/pyarrow objects, etc. Any other type for `values` falls through all supported branches and raises this TypeError naming the offending type.","triggerScenarios":"pl.Series({'a': 1}) (plain dict without struct expectations), pl.Series(generator_object) unwrapped? — actually generators unsupported, pl.Series(42), pl.Series(some_set), pl.Series(custom_object), or passing a non-iterable scalar.","commonSituations":"Passing a set or generator instead of a list; passing a scalar where a list was intended; passing a torch/tensorflow tensor which polars doesn't recognize (convert via .numpy() or tolist()); dict intended as struct but type not recognized in this polars version.","solutions":["Convert to a list: pl.Series(list(values))","For numpy: pl.Series(values) works; for torch: pl.Series(values.numpy())","For a set: pl.Series(sorted(values))","For scalars use pl.Series(\"name\", [value]) or pl.repeat","Upgrade polars if you're passing a type newly supported (e.g. newer Arrow objects)"],"exampleFix":"// before\npl.Series({7, 8, 9})\n// after\npl.Series(sorted({7, 8, 9}))  # or list(...)","handlingStrategy":"validation","validationCode":"SUPPORTED = (list, tuple, range, dict, pl.Series)\nif not isinstance(values, SUPPORTED):\n    values = list(values)  # converts sets, generators, etc.\npl.Series(\"name\", values)","typeGuard":"def is_series_values(x) -> bool:\n    return isinstance(x, (Sequence, dict, pl.Series)) or hasattr(x, '__array__') or hasattr(x, 'to_numpy')","tryCatchPattern":"try:\n    s = pl.Series(values)\nexcept TypeError as e:\n    if \"unsupported type\" in str(e):\n        s = pl.Series(list(values)) if hasattr(values, '__iter__') else pl.Series([values])","preventionTips":["Convert sets/generators to list before constructing","Convert torch/tf tensors with .numpy() or .tolist()","Pass scalars wrapped in a list: pl.Series([x])","Check the polars version's supported input types for exotic Arrow/pandas objects"],"tags":["polars","series","constructor","type-error","unsupported-type"],"backgroundTag":"invalid-constructor-argument","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"}