{"record":{"id":"8d0a9f79d3a7f329","repo":"pola-rs/polars","slug":"cannot-construct-pyseries-for-type-dtype-r","errorCode":null,"errorMessage":"cannot construct PySeries for type {dtype!r}","messagePattern":"cannot construct PySeries for type (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/datatypes/constructor.py","lineNumber":75,"sourceCode":"        bytes: PySeries.new_binary,\n        PyDecimal: PySeries.new_decimal,\n    }\n\n\ndef polars_type_to_constructor(\n    dtype: PolarsDataType,\n) -> Callable[[str, Sequence[Any], bool], PySeries]:\n    \"\"\"Get the right PySeries constructor for the given Polars dtype.\"\"\"\n    # Special case for Array as it needs to pass the dtype argument on construction\n    if isinstance(dtype, dt.Array):\n        return functools.partial(PySeries.new_array, dtype=dtype)\n\n    try:\n        base_type = dtype.base_type()\n        return _POLARS_TYPE_TO_CONSTRUCTOR[base_type]\n    except KeyError:  # pragma: no cover\n        msg = f\"cannot construct PySeries for type {dtype!r}\"\n        raise ValueError(msg) from None\n\n\n_NUMPY_TYPE_TO_CONSTRUCTOR = None\n\n\ndef _set_numpy_to_constructor() -> None:\n    global _NUMPY_TYPE_TO_CONSTRUCTOR\n    _NUMPY_TYPE_TO_CONSTRUCTOR = {\n        np.float16: PySeries.new_f16,\n        np.float32: PySeries.new_f32,\n        np.float64: PySeries.new_f64,\n        np.int8: PySeries.new_i8,\n        np.int16: PySeries.new_i16,\n        np.int32: PySeries.new_i32,\n        np.int64: PySeries.new_i64,\n        np.uint8: PySeries.new_u8,\n        np.uint16: PySeries.new_u16,\n        np.uint32: PySeries.new_u32,","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/datatypes/constructor.py#L57-L93","documentation":"Error \"cannot construct PySeries for type {dtype!r}\" thrown in pola-rs/polars.","triggerScenarios":"Thrown at py-polars/src/polars/datatypes/constructor.py:75 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}