pola-rs/polars · error
Series constructor called with unsupported type {type(values
Error message
Series constructor called with unsupported type {type(values).__name__!r} for the `values` parameter What it means
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.
Source
Thrown at py-polars/src/polars/series/series.py:370
)
elif isinstance(values, pl.DataFrame):
self._s = dataframe_to_pyseries(
original_name, values, dtype=dtype, strict=strict
)
elif hasattr(values, "__arrow_c_array__"):
self._s = PySeries.from_arrow_c_array(values)
elif hasattr(values, "__arrow_c_stream__"):
self._s = PySeries.from_arrow_c_stream(values)
else:
msg = (
f"Series constructor called with unsupported type {type(values).__name__!r}"
" for the `values` parameter"
)
raise TypeError(msg)
@property
def bin(self) -> BinaryNameSpace:
"""Create an object namespace of all binary related methods."""
return BinaryNameSpace(self)
@property
def cat(self) -> CatNameSpace:
"""Create an object namespace of all categorical related methods."""
return CatNameSpace(self)
@property
def dt(self) -> DateTimeNameSpace:
"""Create an object namespace of all datetime related methods."""
return DateTimeNameSpace(self)
@property
def list(self) -> ListNameSpace:View on GitHub (pinned to df599052da)
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
Example fix
# before
s = pl.Series("s", {1, 2, 3}) # set is unsupported
s = pl.Series("s", (x for x in range(3))) # generator unsupported
# after
s = pl.Series("s", [1, 2, 3])
s = pl.Series("s", list({1, 2, 3}))
s = pl.Series("s", list(x for x in range(3))) Defensive patterns
Strategy: type-guard
Validate before calling
from collections.abc import Sequence
def series_from_any(name, values):
if not isinstance(values, Sequence) and not hasattr(values, "__array_interface__") and not hasattr(values, "__arrow_c_array__"):
values = list(values) # sets, dicts' views, generators, iterators
return pl.Series(name, values) Type guard
from collections.abc import Sequence
from typing import TypeGuard
def is_series_input(v: object) -> TypeGuard[Sequence]:
return isinstance(v, Sequence) or hasattr(v, "__array_interface__") or hasattr(v, "__arrow_c_array__") or hasattr(v, "__arrow_c_stream__") Try / catch
try:
s = pl.Series("s", raw)
except TypeError as e:
if "unsupported type" in str(e) and "values" in str(e):
s = pl.Series("s", list(raw))
else:
raise Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Series name must be a string
- cannot treat Series of type {s.dtype} as indices
- {how!r} strategy is not supported for {qualified_type_name(e
- Series only supports 'vertical' concat strategy
- the truth value of a Series is ambiguous Here are some thin
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/5707681d90e771e4.
Report an issue: GitHub.