pola-rs/polars · error · TypeError
`pl.count()` takes at least one argument. If you want to…
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
`pl.count()` was renamed to `pl.len()`; calling the deprecated top-level `count()` with no column arguments now raises TypeError because counting all rows is expressed by `pl.len()`. The library throws this to force migration away from the ambiguous no-argument form. With arguments, `pl.count(col)` still counts non-null values of that column.
Solutions
- Replace `pl.count()` with `pl.len()` when you want the number of rows
- If you want per-column non-null counts, pass column names: `pl.count("col")`
- Search the codebase for `pl.count(` and audit each call site
- Pin or consult the polars migration guide for the count/len rename
Example fix
// before df.select(pl.count()) // after df.select(pl.len())
Defensive patterns
Strategy: validation
Validate before calling
def safe_count(exprs):
if not exprs:
return pl.len()
return pl.count(*exprs) if hasattr(pl, "count") else None Type guard
def is_row_count_call(*columns): return len(columns) == 0
Prevention
- Use pl.len() for row counts in all new code
- Add a lint/grep rule for `pl.count()` with no args
- Run the polars upgrade migration guide when bumping versions
When it happens
Trigger: Calling `pl.count()` with zero arguments in a lazy/select context, e.g. `df.select(pl.count())`, on a polars version where the no-arg form was removed.
Common situations: Upgrading polars across the deprecation of `pl.count()`; old tutorials or LLM-generated code using `pl.count()` for row counts; automated migration missed no-argument call sites.
Understand the failure class
Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.
Related errors
- accessing ` ` from the top-level `polars` module was…
- expected at least one Series in 'corr' inputs if…
- expected at least one Series in 'cov' inputs if 'eager=True'
- method must be one of
- ` ` was deprecated in version 1.0.0. Define your own data…
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/95b60e052fcfdae7.
Report an issue: GitHub.
Appendix: 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 fe841f959e)