{"record":{"id":"b01d1921aebc54b7","repo":"pola-rs/polars","slug":"invalid-input-for-exclude-expected-one-or-more-str-or","errorCode":null,"errorMessage":"invalid input for `exclude`\n\nExpected one or more `str` or `DataType`; found {item!r} instead.","messagePattern":"invalid input for `exclude`\n\nExpected one or more `str` or `DataType`; found (.+?) instead\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/selectors.py","lineNumber":578,"sourceCode":"        exclude_dtypes: builtins.list[PolarsDataType] = []\n        for item in (\n            *(\n                columns\n                if isinstance(columns, Collection) and not isinstance(columns, str)\n                else [columns]\n            ),\n            *more_columns,\n        ):\n            if isinstance(item, str):\n                exclude_cols.append(item)\n            elif is_polars_dtype(item):\n                exclude_dtypes.append(item)\n            else:\n                msg = (\n                    \"invalid input for `exclude`\"\n                    f\"\\n\\nExpected one or more `str` or `DataType`; found {item!r} instead.\"\n                )\n                raise TypeError(msg)\n\n        if exclude_cols and exclude_dtypes:\n            msg = \"cannot exclude by both column name and dtype\"\n            raise TypeError(msg)\n\n        excluded = (\n            by_dtype(exclude_dtypes)\n            if exclude_dtypes\n            else Selector._by_name(\n                exclude_cols,\n                strict=False,\n                expand_patterns=True,\n            )\n        )\n        return self - excluded\n\n    def as_expr(self) -> Expr:\n        \"\"\"","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/selectors.py#L560-L596","documentation":"The legacy cs.exclude() accepts only column-name strings, Polars DataTypes (including selectors internally), and iterables thereof. Any other item raises this TypeError with a message stating exactly what was found. Note this older exclude differs from the newer Selector.exclude/_combine_as_selector path.","triggerScenarios":"cs.exclude(123), cs.exclude([pl.col('a')]) — expressions inside the collection, or None / arbitrary objects passed as items to exclude().","commonSituations":"Passing column indices instead of names; passing Exprs (allowed in newer code paths via _combine_as_selector but not here); None leaking from optional config.","solutions":["Pass only strings and/or Polars dtypes: cs.exclude('a', pl.UInt32).","Exclude by expression by switching to the newer API: cs.all().exclude(pl.col('a')) or df.select(cs.all() - cs.by_name('a')).","Convert indices to names: cs.exclude(*[df.columns[i] for i in idx]).","Pre-validate items: all(isinstance(x, (str, ...)) for x in items)."],"exampleFix":"// before\ncs.exclude([pl.col(\"temp\")])\n// after\ncs.exclude(\"temp\")","handlingStrategy":"validation","validationCode":"import polars as pl\nbad = [x for x in items if not isinstance(x, (str, pl.DataType))]\nif bad:\n    raise ValueError(f\"exclude accepts only str/DataType, got: {bad!r}\")","typeGuard":"def is_exclude_item(x) -> bool:\n    import polars as pl\n    if isinstance(x, (str, pl.DataType)):\n        return True\n    return isinstance(x, (list, tuple, set)) and all(isinstance(i, (str, pl.DataType)) for i in x)","tryCatchPattern":"try:\n    sel = cs.exclude(*items)\nexcept TypeError as e:\n    if \"invalid input for `exclude`\" in str(e):\n        sel = cs.exclude(*(x for x in items if isinstance(x, str)))\n    else:\n        raise","preventionTips":["Only strings and Polars dtypes belong in legacy exclude(); expressions do not.","Convert indices to names before excluding.","Prefer the newer Selector.exclude API which accepts more input kinds."],"tags":["polars","selectors","type-error"],"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"}