pola-rs/polars · error · TypeError
invalid name
Error message
invalid name: {nm!r} What it means
cs.by_name validates `names`: top-level strings are accepted, collections are flattened, and any item inside a collection that is not a str triggers this TypeError naming the bad name. It fires when a non-string (e.g. an int column reference) is nested inside the names argument.
Solutions
- Pass a valid string name for the selector/index operation.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at py-polars/src/polars/selectors.py:1291 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pola-rs/polars@68506541d2 (2026-08-19).
Data as JSON: /api/errors/6a5303146bd11ef7.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/selectors.py:1283
shape: (2, 2)
┌─────┬───────┐
│ baz ┆ zap │
│ --- ┆ --- │
│ f64 ┆ bool │
╞═════╪═══════╡
│ 2.0 ┆ false │
│ 5.5 ┆ true │
└─────┴───────┘
"""
all_names = []
for nm in names:
if isinstance(nm, str):
all_names.append(nm)
elif isinstance(nm, Collection):
for n in nm:
if not isinstance(n, str):
msg = f"invalid name: {n!r}"
raise TypeError(msg)
all_names.append(n)
else:
msg = f"invalid name: {nm!r}"
raise TypeError(msg)
return Selector._by_name(all_names, strict=require_all, expand_patterns=False)
def empty() -> Selector:
"""
Select no columns.
This is useful for composition with other selectors.
See Also
--------
all : Select all columns in the current scope.
View on GitHub (pinned to 68506541d2)