pola-rs/polars · error · ValueError
cannot construct PySeries for type {dtype!r}
Error message
cannot construct PySeries for type {dtype!r} What it means
Error "cannot construct PySeries for type {dtype!r}" thrown in pola-rs/polars.
Source
Thrown at py-polars/src/polars/datatypes/constructor.py:75
bytes: PySeries.new_binary,
PyDecimal: PySeries.new_decimal,
}
def polars_type_to_constructor(
dtype: PolarsDataType,
) -> Callable[[str, Sequence[Any], bool], PySeries]:
"""Get the right PySeries constructor for the given Polars dtype."""
# Special case for Array as it needs to pass the dtype argument on construction
if isinstance(dtype, dt.Array):
return functools.partial(PySeries.new_array, dtype=dtype)
try:
base_type = dtype.base_type()
return _POLARS_TYPE_TO_CONSTRUCTOR[base_type]
except KeyError: # pragma: no cover
msg = f"cannot construct PySeries for type {dtype!r}"
raise ValueError(msg) from None
_NUMPY_TYPE_TO_CONSTRUCTOR = None
def _set_numpy_to_constructor() -> None:
global _NUMPY_TYPE_TO_CONSTRUCTOR
_NUMPY_TYPE_TO_CONSTRUCTOR = {
np.float16: PySeries.new_f16,
np.float32: PySeries.new_f32,
np.float64: PySeries.new_f64,
np.int8: PySeries.new_i8,
np.int16: PySeries.new_i16,
np.int32: PySeries.new_i32,
np.int64: PySeries.new_i64,
np.uint8: PySeries.new_u8,
np.uint16: PySeries.new_u16,
np.uint32: PySeries.new_u32,View on GitHub (pinned to df599052da)
When it happens
Trigger: Thrown at py-polars/src/polars/datatypes/constructor.py:75 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/8d0a9f79d3a7f329.
Report an issue: GitHub.