{"record":{"id":"9a59d29e4b5b7455","repo":"pola-rs/polars","slug":"expected-one-or-more-str-datatype-or-selector","errorCode":null,"errorMessage":"expected one or more `str`, `DataType` or selector; found {item!r} instead.","messagePattern":"expected one or more `str`, `DataType` or selector; found (.+?) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/selectors.py","lineNumber":307,"sourceCode":"            if isinstance(items, Collection) and not isinstance(items, str)\n            else [items]\n        ),\n        *more_items,\n    ):\n        if is_selector(item):\n            selectors.append(item)\n        elif is_polars_dtype(item):\n            dtypes.append(item)\n        elif isinstance(item, str):\n            if item.startswith(\"^\") and item.endswith(\"$\"):\n                regexes.append(item)\n            else:\n                names.append(item)\n        elif is_column(item):\n            names.append(item.meta.output_name())  # type: ignore[union-attr]\n        else:\n            msg = f\"expected one or more `str`, `DataType` or selector; found {item!r} instead.\"\n            raise TypeError(msg)\n\n    selected = []\n    if names:\n        selected.append(by_name(*names, require_all=False))\n    if dtypes:\n        selected.append(by_dtype(*dtypes))\n    if regexes:\n        selected.append(\n            matches(\n                \"|\".join(f\"({rx})\" for rx in regexes)\n                if len(regexes) > 1\n                else regexes[0]\n            )\n        )\n    if selectors:\n        selected.extend(selectors)\n\n    return reduce(or_, selected)","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/selectors.py#L289-L325","documentation":"_combine_as_selector (the engine behind cs.exclude and similar selector combinators) accepts only: strings (a ^...$ string is treated as regex), polars dtypes, Selectors, column expressions, or collections of those. Any other item type (int, numpy scalar, Series, arbitrary object) raises TypeError.","triggerScenarios":"cs.exclude(0) (pandas-style index); cs.exclude(np.int64(3)); cs.exclude(df['col']) (a Series); tuples mixing valid and invalid items.","commonSituations":"Porting pandas drop-by-index habits; numpy ints arriving from computed index positions; passing a Series instead of its name.","solutions":["Convert indices to names first: cs.exclude(df.columns[0], 'b')","Pass dtypes or selectors instead of raw objects: cs.exclude(cs.string())","For Series pass its name: cs.exclude(df['col'].name)"],"exampleFix":"# before\ndf.select(cs.exclude(0, 'b'))\n\n# after\ndf.select(cs.exclude(df.columns[0], 'b'))","handlingStrategy":"type-guard","validationCode":"from polars.selectors import is_selector\nfrom polars.datatypes import is_polars_dtype\n\ndef _ok(item):\n    return isinstance(item, str) or is_selector(item) or is_polars_dtype(item) or item.meta.is_column() if hasattr(item, 'meta') else isinstance(item, str)\n\nitems = [df.columns[i] if isinstance(i, int) else i for i in items]  # normalize indices","typeGuard":"from polars.selectors import is_selector\nfrom polars.datatypes import is_polars_dtype\n\ndef is_selector_input(item) -> bool:\n    return (\n        isinstance(item, str)\n        or is_selector(item)\n        or is_polars_dtype(item)\n        or (hasattr(item, 'meta') and item.meta.is_column())\n    )","tryCatchPattern":null,"preventionTips":["cs.exclude speaks names/dtypes/selectors, not integer positions; translate indices via df.columns","Never hand numpy scalars or Series objects to selector combinators"],"tags":["polars","selectors","type-error","exclude"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}