{"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":71,"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":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/datatypes/group.py#L53-L89","documentation":"polars DataTypeGroup (used for set-like dtype collections) validates that every item is a DataType instance or DataTypeClass. __new__ raises TypeError for any element that is not a dtype, e.g. raw strings like 'Int64' or None.","triggerScenarios":"Calling DataTypeGroup([...]) or passing a collection to a dtype-group parameter where a list element is a plain string, None, a Python type alias, or any non-dtype object.","commonSituations":"Migrating from string dtype names to polars DataType objects; typos like passing 'Int64' instead of pl.Int64; accidentally passing a numpy dtype or built-in type; building groups programmatically from config values that are strings.","solutions":["Replace string dtype names with polars DataType objects, e.g. 'Int64' -> pl.Int64","Wrap strings with pl.DataType if constructing from config: getattr(pl, name)","Filter/validate the list before constructing the group, dropping or converting non-dtype items","Check for None or nested lists that leaked into the items iterable"],"exampleFix":"// before\npl.datatypes.group.DataTypeGroup(['Int64', 'Utf8'])\n// after\npl.datatypes.group.DataTypeGroup([pl.Int64, pl.Utf8])","handlingStrategy":"type-guard","validationCode":"def check_dtypes(items):\n    import polars as pl\n    bad = [it for it in items if not isinstance(it, (pl.DataType, type(pl.Int64)))]\n    if bad:\n        raise TypeError(f'non-dtype items: {bad}')","typeGuard":"from polars import DataType\ndef is_dtype(x) -> bool:\n    return isinstance(x, (DataType, type(DataType)))","tryCatchPattern":null,"preventionTips":["Never store dtype names as strings in config; store pl.* DataType references or resolve via getattr(pl, name)","Unit-test group construction with your actual config values","Type-hint lists as list[DataType] so mypy flags string items"],"tags":["python","polars","type-error","datatypes"],"backgroundTag":"invalid-argument-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}