{"record":{"id":"95b60e052fcfdae7","repo":"pola-rs/polars","slug":"pl-count-takes-at-least-one-argument-if-you-w","errorCode":null,"errorMessage":"`pl.count()` takes at least one argument. If you want to count the number of rows, please use `pl.len()` instead.","messagePattern":"`pl\\.count\\(\\)` takes at least one argument\\. If you want to count the number of rows, please use `pl\\.len\\(\\)` instead\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/lazy.py","lineNumber":224,"sourceCode":"    │ 1   ┆ 3   │\n    └─────┴─────┘\n\n    Return the number of rows in a context. **This way of using the function is\n    deprecated.** Please use :func:`len` instead.\n\n    >>> df.select(pl.count())  # doctest: +SKIP\n    shape: (1, 1)\n    ┌───────┐\n    │ count │\n    │ ---   │\n    │ u32   │\n    ╞═══════╡\n    │ 3     │\n    └───────┘\n    \"\"\"\n    if not columns:\n        msg = \"`pl.count()` takes at least one argument. If you want to count the number of rows, please use `pl.len()` instead.\"\n        raise TypeError(msg)\n    return F.col(*columns).count()\n\n\ndef cum_count(*columns: str, reverse: bool = False) -> Expr:\n    \"\"\"\n    Return the cumulative count of the non-null values in the column.\n\n    This function is syntactic sugar for `col(columns).cum_count()`.\n\n    Parameters\n    ----------\n    *columns\n        Name(s) of the columns to use.\n    reverse\n        Reverse the operation.\n\n    Examples\n    --------","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/functions/lazy.py#L206-L242","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndf.select(pl.count())\n// after\ndf.select(pl.len())","handlingStrategy":"validation","validationCode":"def safe_count(exprs):\n    if not exprs:\n        return pl.len()\n    return pl.count(*exprs) if hasattr(pl, \"count\") else None","typeGuard":"def is_row_count_call(*columns): return len(columns) == 0","tryCatchPattern":null,"preventionTips":["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"],"tags":["python","polars","deprecation","dataframe"],"backgroundTag":"deprecated-api-usage","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"}