{"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":"exception","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/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/functions/lazy.py#L206-L242","documentation":"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.","triggerScenarios":"pl.count() with zero arguments, e.g. df.group_by('a').agg(pl.count()) or pl.select(pl.count()) on older-style code.","commonSituations":"Tutorial/legacy code predating the pl.len() introduction; SQL-transliteration habits where COUNT(*) means row count; group_by aggregations copied from old docs.","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"],"exampleFix":"# before\ndf.group_by('a').agg(pl.count())\n# after\ndf.group_by('a').agg(pl.len())","handlingStrategy":"validation","validationCode":"if not columns:\n    raise TypeError('use pl.len() for row counts')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer pl.len() everywhere for row counts","Reserve pl.count('col') for non-null counts","Grep and replace bare pl.count() on upgrades"],"tags":["python","polars","count","len","migration"],"backgroundTag":"api-behavior-change","analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-28T18:02:35.179Z","contentChangedAt":"2026-08-28T18:02:35.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}