pola-rs/polars · error · TypeError
`pl.count()` takes at least one argument. If you want to cou
Error message
`pl.count()` takes at least one argument. If you want to count the number of rows, please use `pl.len()` instead.
What it means
TypeError raised by pl.count() when called with no column arguments. pl.count() without columns historically returned the row count, which was ambiguous and is now reserved for counting non-null values in specified columns; the message directs users to pl.len() for row counts.
Source
Thrown at py-polars/src/polars/functions/lazy.py:224
│ 1 ┆ 3 │
└─────┴─────┘
Return the number of rows in a context. **This way of using the function is
deprecated.** Please use :func:`len` instead.
>>> df.select(pl.count()) # doctest: +SKIP
shape: (1, 1)
┌───────┐
│ count │
│ --- │
│ u32 │
╞═══════╡
│ 3 │
└───────┘
"""
if not columns:
msg = "`pl.count()` takes at least one argument. If you want to count the number of rows, please use `pl.len()` instead."
raise TypeError(msg)
return F.col(*columns).count()
def cum_count(*columns: str, reverse: bool = False) -> Expr:
"""
Return the cumulative count of the non-null values in the column.
This function is syntactic sugar for `col(columns).cum_count()`.
Parameters
----------
*columns
Name(s) of the columns to use.
reverse
Reverse the operation.
Examples
--------View on GitHub (pinned to 68506541d2)
Solutions
- Replace pl.count() with pl.len() for row counts
- Use pl.count('col') to count non-null values of a specific column
- Grep for pl.count() during upgrades — the fix is mechanical
Example fix
# before
df.group_by('a').agg(pl.count())
# after
df.group_by('a').agg(pl.len()) Defensive patterns
Strategy: validation
Validate before calling
if not columns:
raise TypeError('use pl.len() for row counts') Prevention
- Prefer pl.len() everywhere for row counts
- Reserve pl.count('col') for non-null counts
- Grep and replace bare pl.count() on upgrades
When it happens
Trigger: pl.count() with zero arguments, e.g. df.group_by('a').agg(pl.count()) or pl.select(pl.count()) on older-style code.
Common situations: Tutorial/legacy code predating the pl.len() introduction; SQL-transliteration habits where COUNT(*) means row count; group_by aggregations copied from old docs.
Related errors
- `{name}` was removed in version {version}
- {func_name!r} received both {param.name!r} and {param.new_na
- the argument {param.name!r} for {func_name!r}{was_deprecated
- the argument {param.name!r} for {func_name!r}{was_deprecated
- `strict=False` is no longer supported for `how='horizontal'`
AI-assisted analysis of pola-rs/polars@68506541d2 (2026-08-28).
Data as JSON: /api/errors/95b60e052fcfdae7.
Report an issue: GitHub.