{"record":{"id":"e9da0e5fcddab05e","repo":"pola-rs/polars","slug":"datatypegroup-items-must-be-dtypes-found-qualifi","errorCode":null,"errorMessage":"DataTypeGroup items must be dtypes; found {qualified_type_name(it)!r}","messagePattern":"DataTypeGroup items must be dtypes; found (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/datatypes/group.py","lineNumber":70,"sourceCode":"    def __new__(\n        cls, items: Iterable[DataType | DataTypeClass], *, match_base_type: bool = True\n    ) -> Self:\n        \"\"\"\n        Construct a DataTypeGroup.\n\n        Parameters\n        ----------\n        items :\n            iterable of data types\n        match_base_type:\n            match the base type\n        \"\"\"\n        for it in items:\n            if not isinstance(it, (DataType, DataTypeClass)):\n                from polars._utils.various import qualified_type_name\n\n                msg = f\"DataTypeGroup items must be dtypes; found {qualified_type_name(it)!r}\"\n                raise TypeError(msg)\n\n        dtype_group = super().__new__(cls, items)\n        dtype_group._match_base_type = match_base_type\n        return dtype_group\n\n    def __contains__(self, item: Any) -> bool:\n        if self._match_base_type and isinstance(item, (DataType, DataTypeClass)):\n            item = item.base_type()\n        return super().__contains__(item)\n\n\nSIGNED_INTEGER_DTYPES: Final[frozenset[PolarsIntegerType]] = DataTypeGroup(\n    [\n        Int8,\n        Int16,\n        Int32,\n        Int64,\n        Int128,","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/datatypes/group.py#L52-L88","documentation":"DataTypeGroup — the frozenset subclass behind INTEGER_DTYPES, FLOAT_DTYPES, etc. — validates in __new__ that every item is a DataType or DataTypeClass instance. Anything else (strings like 'i64', Python types, arbitrary objects) raises TypeError with the offending item's qualified type name.","triggerScenarios":"Constructing DataTypeGroup with non-dtype items: DataTypeGroup(['i64', 'f64']), DataTypeGroup([int, float]), or building a group from config/YAML-supplied dtype names that were never resolved to actual dtypes.","commonSituations":"Parsing dtype names from configuration files into dtype groups; refactors that replaced dtype classes with their string reprs; copy-pasting short dtype codes ('i64') from polars display output into code.","solutions":["Pass dtype classes or instances: pl.Int64, pl.Float64, pl.Int64()","Resolve strings to dtypes before building the group, e.g. via a name-to-dtype mapping built from polars.datatypes","Validate config-supplied items against polars datatypes at load time"],"exampleFix":"# before\ngroup = DataTypeGroup(['i64', 'f64'])  # TypeError\n\n# after\ngroup = DataTypeGroup([pl.Int64, pl.Float64])","handlingStrategy":"type-guard","validationCode":"from polars.datatypes import DataType, DataTypeClass, DataTypeGroup\n\nitems = ['i64', 'f64']  # e.g. from config\nassert all(isinstance(it, (DataType, DataTypeClass)) for it in items), 'dtype group received non-dtype items'\ngroup = DataTypeGroup(items)","typeGuard":"from polars.datatypes import DataType, DataTypeClass\n\ndef all_items_are_dtypes(items) -> bool:\n    return all(isinstance(it, (DataType, DataTypeClass)) for it in items)","tryCatchPattern":null,"preventionTips":["Resolve config-supplied dtype names to actual dtypes before building collections","Never paste short dtype codes ('i64') from polars display output into source"],"tags":["dtype","type-misuse","api-misuse","validation"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}