{"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":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":370,"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":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/series/series.py#L352-L388","documentation":"Raised by the Series constructor (py-polars/src/polars/series/series.py:370) when the values argument falls through every supported input path: it is not a Python Sequence, not 1D/2D numpy (checked via __array_interface__), not an Arrow table/array (no __arrow_c_array__/__arrow_c_stream__), etc. Unsupported containers like sets, dicts, and generic iterators end here and raise TypeError naming the offending type.","triggerScenarios":"pl.Series(\"s\", {1, 2, 3}) (set), pl.Series(\"s\", {\"a\": 1}) (dict — not a Sequence), pl.Series(\"s\", map(str, xs)) or any generator/iterator (not a Sequence), pl.Series(\"s\", some_custom_object).","commonSituations":"Passing a set or generator because it was convenient upstream; passing a dict expecting keys or values to be used; 2D containers like a set of tuples. Note generators must be materialized first.","solutions":["Materialize non-Sequence iterables: pl.Series(\"s\", list(my_set)), pl.Series(\"s\", list(gen))","For dicts, pick explicitly: pl.Series(\"s\", list(d.values())) or list(d.keys())","For tabular dicts use pl.DataFrame(d) instead of a Series"],"exampleFix":"# before\ns = pl.Series(\"s\", {1, 2, 3})  # set is unsupported\ns = pl.Series(\"s\", (x for x in range(3)))  # generator unsupported\n\n# after\ns = pl.Series(\"s\", [1, 2, 3])\ns = pl.Series(\"s\", list({1, 2, 3}))\ns = pl.Series(\"s\", list(x for x in range(3)))","handlingStrategy":"type-guard","validationCode":"from collections.abc import Sequence\n\ndef series_from_any(name, values):\n    if not isinstance(values, Sequence) and not hasattr(values, \"__array_interface__\") and not hasattr(values, \"__arrow_c_array__\"):\n        values = list(values)  # sets, dicts' views, generators, iterators\n    return pl.Series(name, values)","typeGuard":"from collections.abc import Sequence\nfrom typing import TypeGuard\n\ndef is_series_input(v: object) -> TypeGuard[Sequence]:\n    return isinstance(v, Sequence) or hasattr(v, \"__array_interface__\") or hasattr(v, \"__arrow_c_array__\") or hasattr(v, \"__arrow_c_stream__\")","tryCatchPattern":"try:\n    s = pl.Series(\"s\", raw)\nexcept TypeError as e:\n    if \"unsupported type\" in str(e) and \"values\" in str(e):\n        s = pl.Series(\"s\", list(raw))\n    else:\n        raise","preventionTips":["Materialize generators/sets/dicts into lists before constructing a Series","For tabular dicts use pl.DataFrame(d); for dicts-as-data pick d.values() explicitly"],"tags":["polars","series","typeerror","constructor","input-validation"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}