pola-rs/polars · error
unexpected input for `strategy`: {strategy!r} Choose one of
Error message
unexpected input for `strategy`: {strategy!r}
Choose one of {'first', 'all'} What it means
DataFrame.n_chunks(strategy=...) reports chunk counts of the frame's columns. strategy must be exactly 'first' (return the chunk count of the first column only, as an int) or 'all' (return a list with one count per column). Any other value raises ValueError listing the two allowed options. The comparison is exact and case-sensitive.
Source
Thrown at py-polars/src/polars/dataframe/frame.py:10793
... "b": [0.5, 4, 10, 13],
... "c": [True, True, False, True],
... }
... )
>>> df.n_chunks()
1
>>> df.n_chunks(strategy="all")
[1, 1, 1]
"""
if strategy == "first":
return self._df.n_chunks()
elif strategy == "all":
return [s.n_chunks() for s in self.__iter__()]
else:
msg = (
f"unexpected input for `strategy`: {strategy!r}"
f"\n\nChoose one of {{'first', 'all'}}"
)
raise ValueError(msg)
def max(self) -> DataFrame:
"""
Aggregate the columns of this DataFrame to their maximum value.
Examples
--------
>>> df = pl.DataFrame(
... {
... "foo": [1, 2, 3],
... "bar": [6, 7, 8],
... "ham": ["a", "b", "c"],
... }
... )
>>> df.max()
shape: (1, 3)
┌─────┬─────┬─────┐
│ foo ┆ bar ┆ ham │View on GitHub (pinned to df599052da)
Solutions
- Use strategy='first' for a single int, or strategy='all' for a list of per-column counts
- Check spelling and case — the allowed set is exactly {'first', 'all'}
- Validate dynamic values against {'first', 'all'} before calling, defaulting to 'first'
Example fix
# before chunks = df.n_chunks(strategy='columns') # after chunks = df.n_chunks(strategy='all') # or strategy='first' for the first column only
Defensive patterns
Strategy: validation
Validate before calling
strategy = strategy if strategy in {'first', 'all'} else 'first'
n = df.n_chunks(strategy=strategy) Type guard
def is_n_chunks_strategy(v: object) -> bool:
return isinstance(v, str) and v in {'first', 'all'} Prevention
- Pin the literal in one constant; the set is exactly {'first', 'all'}
- Validate dynamic/option-sourced values before the call and default to 'first'
- When upgrading polars, re-check n_chunks usage — its signature changed across versions
When it happens
Trigger: df.n_chunks(strategy='columns'), strategy='per_column', strategy='min', or a variable holding a stray string; passing strategy=None expecting a default; code written against an older polars where n_chunks took no strategy argument.
Common situations: Version drift: older releases returned a per-column list by default, so old call sites guess a parameter name; forwarding display/diagnostic options from user configuration; misspelled literals in monitoring code.
Related errors
- invalid `return_type`; found {return_type!r}, expected one o
- `offset` input for `with_row_index` cannot be {issue}, got {
- cannot use `partition_by` with `maintain_order=False, includ
- cannot specify both `n` and `fraction`
- can only call `.row()` without "index" or "by_predicate" val
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/37e770b6b7ceb160.
Report an issue: GitHub.