{"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":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/selectors.py","lineNumber":308,"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":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/selectors.py#L290-L326","documentation":"_combine_as_selector converts heterogeneous inputs (strings, dtypes, selectors, column Exprs) into one selector inside helpers like cs.exclude(). If an item is none of str, Polars DataType, Selector, or a Column, this TypeError is raised telling you what types are accepted.","triggerScenarios":"cs.exclude(123), cs.exclude(['a', None]), cs.exclude(some_dataframe), or passing nested lists / arbitrary Python objects into exclude() or any API that funnels through _combine_as_selector.","commonSituations":"Typos like passing a set of tuples, accidentally passing a DataFrame or Series, passing ints meant to be column indices (exclude takes names, not indices), or None sneaking in from an optional variable.","solutions":["Pass only column-name strings, Polars dtypes, selectors, or pl.col(...) expressions: cs.exclude('a', pl.Int64).","Convert indices to names first: cs.exclude(df.columns[i] for i in idxs).","Filter out None/invalid items before the call: cs.exclude(*(x for x in items if isinstance(x, str))).","Use cs.all().exclude(...) style composition if mixing selectors and names."],"exampleFix":"// before\ncs.exclude([0, 1])\n// after\ncs.exclude(df.columns[0], df.columns[1])","handlingStrategy":"validation","validationCode":"allowed = (str, pl.DataType, type(pl.Int64), pl.Expr)\nbad = [x for x in items if not isinstance(x, allowed) and not hasattr(x, '_pyselector')]\nif bad:\n    raise ValueError(f\"unsupported exclude items: {bad!r}\")","typeGuard":"def is_selector_input(x) -> bool:\n    import polars as pl\n    from polars.selectors import is_selector\n    return isinstance(x, (str, pl.Expr)) or is_selector(x) or getattr(getattr(x, '__module__', ''), 'startswith', lambda *_: False)('polars.datatypes')","tryCatchPattern":"try:\n    sel = cs.exclude(*items)\nexcept TypeError as e:\n    if \"expected one or more\" in str(e):\n        sel = cs.exclude(*filter(lambda x: isinstance(x, str), items))\n    else:\n        raise","preventionTips":["exclude() takes names/dtypes, never indices — convert indices to df.columns[i] first.","Filter None from optional variables before splatting into exclude().","Prefer the modern cs.all().exclude(...) composition for mixed inputs."],"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"}