{"record":{"id":"5116e22c2d103844","repo":"pola-rs/polars","slug":"expected-polars-expression-or-object-convertible-t-5116e2","errorCode":null,"errorMessage":"Expected Polars expression or object convertible to one, got {type(value)}.\\n\\nHint: if you tried\\n    group_by(by={value!r})\\nthen you probably want to use this instead:\\n    group_by({value!r})","messagePattern":"Expected Polars expression or object convertible to one, got (.+?)\\.\\\\n\\\\nHint: if you tried\\\\n    group_by\\(by=(.+?)\\)\\\\nthen you probably want to use this instead:\\\\n    group_by\\((.+?)\\)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/lazyframe/frame.py","lineNumber":5295,"sourceCode":"        │ a   ┆ b   ┆ c   │\n        │ --- ┆ --- ┆ --- │\n        │ str ┆ i64 ┆ f64 │\n        ╞═════╪═════╪═════╡\n        │ a   ┆ 0   ┆ 4.0 │\n        │ b   ┆ 1   ┆ 3.0 │\n        │ c   ┆ 1   ┆ 1.0 │\n        └─────┴─────┴─────┘\n        \"\"\"\n        for value in named_by.values():\n            if not isinstance(value, (str, pl.Expr, pl.Series)):\n                msg = (\n                    f\"Expected Polars expression or object convertible to one, got {type(value)}.\\n\\n\"\n                    \"Hint: if you tried\\n\"\n                    f\"    group_by(by={value!r})\\n\"\n                    \"then you probably want to use this instead:\\n\"\n                    f\"    group_by({value!r})\"\n                )\n                raise TypeError(msg)\n        exprs = parse_into_list_of_expressions(*by, **named_by)\n        lgb = self._ldf.group_by(exprs, maintain_order)\n        return LazyGroupBy(lgb)\n\n    @deprecate_renamed_parameter(\"by\", \"group_by\", version=\"0.20.14\")\n    def rolling(\n        self,\n        index_column: IntoExpr,\n        *,\n        period: str | timedelta,\n        offset: str | timedelta | None = None,\n        closed: ClosedInterval = \"right\",\n        group_by: IntoExpr | Iterable[IntoExpr] | None = None,\n    ) -> LazyGroupBy:\n        \"\"\"\n        Create rolling groups based on a temporal or integer column.\n\n        Different from a `group_by_dynamic` the windows are now determined by the","sourceCodeStart":5277,"sourceCodeEnd":5313,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/lazyframe/frame.py#L5277-L5313","documentation":"In LazyFrame.group_by(), keyword arguments define named grouping columns, so each keyword value must be a str, pl.Expr, or pl.Series. Passing another type — most commonly a dict via group_by(by={'a': 1}) or a list — raises TypeError, and the message hints at the classic mistake of wrapping the by argument in by=.","triggerScenarios":"lf.group_by(by=['a','b']) — the parameter is positional-or-keyword named by, but by= becomes a single kwarg named 'by' whose value is a list, which is not a valid named-column value; also group_by(**some_dict) where values are ints/bools.","commonSituations":"Copy-paste from older code or other APIs where by= keyword was standard; programmatically expanding dicts into kwargs.","solutions":["Call group_by(['a','b']) or group_by('a','b') directly without by=","Use named kwargs only for renaming/aliasing with expression values: group_by(short=pl.col('long_name'))","If expanding a dict programmatically, ensure values are column names, Exprs, or Series, and don't use the literal key 'by' unless its value is a column spec"],"exampleFix":"# before\nlf.group_by(by=['a', 'b'])\n\n# after\nlf.group_by(['a', 'b'])","handlingStrategy":"type-guard","validationCode":"import polars as pl\nfor v in named_by.values():\n    assert isinstance(v, (str, pl.Expr, pl.Series)), f'invalid group_by key value: {v!r}'\nlf.group_by(*by, **named_by)","typeGuard":"def is_valid_group_by_value(v) -> bool:\n    import polars as pl\n    return isinstance(v, (str, pl.Expr, pl.Series))","tryCatchPattern":null,"preventionTips":["Never write group_by(by=...); pass the sequence positionally","Lint for the by= pattern in code reviews","When expanding dicts into kwargs, verify value types are column specs"],"tags":["polars","lazyframe","group-by","kwargs","api-usage"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}