{"record":{"id":"37e770b6b7ceb160","repo":"pola-rs/polars","slug":"unexpected-input-for-strategy-strategy-r-cho","errorCode":null,"errorMessage":"unexpected input for `strategy`: {strategy!r}\n\nChoose one of {'first', 'all'}","messagePattern":"unexpected input for `strategy`: (.+?)\n\nChoose one of (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/dataframe/frame.py","lineNumber":10793,"sourceCode":"        ...         \"b\": [0.5, 4, 10, 13],\n        ...         \"c\": [True, True, False, True],\n        ...     }\n        ... )\n        >>> df.n_chunks()\n        1\n        >>> df.n_chunks(strategy=\"all\")\n        [1, 1, 1]\n        \"\"\"\n        if strategy == \"first\":\n            return self._df.n_chunks()\n        elif strategy == \"all\":\n            return [s.n_chunks() for s in self.__iter__()]\n        else:\n            msg = (\n                f\"unexpected input for `strategy`: {strategy!r}\"\n                f\"\\n\\nChoose one of {{'first', 'all'}}\"\n            )\n            raise ValueError(msg)\n\n    def max(self) -> DataFrame:\n        \"\"\"\n        Aggregate the columns of this DataFrame to their maximum value.\n\n        Examples\n        --------\n        >>> df = pl.DataFrame(\n        ...     {\n        ...         \"foo\": [1, 2, 3],\n        ...         \"bar\": [6, 7, 8],\n        ...         \"ham\": [\"a\", \"b\", \"c\"],\n        ...     }\n        ... )\n        >>> df.max()\n        shape: (1, 3)\n        ┌─────┬─────┬─────┐\n        │ foo ┆ bar ┆ ham │","sourceCodeStart":10775,"sourceCodeEnd":10811,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/dataframe/frame.py#L10775-L10811","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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'"],"exampleFix":"# before\nchunks = df.n_chunks(strategy='columns')\n\n# after\nchunks = df.n_chunks(strategy='all')  # or strategy='first' for the first column only","handlingStrategy":"validation","validationCode":"strategy = strategy if strategy in {'first', 'all'} else 'first'\nn = df.n_chunks(strategy=strategy)","typeGuard":"def is_n_chunks_strategy(v: object) -> bool:\n    return isinstance(v, str) and v in {'first', 'all'}","tryCatchPattern":null,"preventionTips":["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"],"tags":["polars","dataframe","n-chunks","parameter-validation","valueerror","diagnostics"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}