{"record":{"id":"a210d92646e98deb","repo":"pola-rs/polars","slug":"specifying-aggregations-as-a-dictionary-is-not-sup","errorCode":null,"errorMessage":"specifying aggregations as a dictionary is not supported\\n\\nTry unpacking the dictionary to take advantage of the keyword syntax of the `agg` method.","messagePattern":"specifying aggregations as a dictionary is not supported\\\\n\\\\nTry unpacking the dictionary to take advantage of the keyword syntax of the `agg` method\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/lazyframe/group_by.py","lineNumber":193,"sourceCode":"        ... ).collect()  # doctest: +IGNORE_RESULT\n        shape: (3, 3)\n        ┌─────┬───────┬────────────────┐\n        │ a   ┆ b_sum ┆ c_mean_squared │\n        │ --- ┆ ---   ┆ ---            │\n        │ str ┆ i64   ┆ f64            │\n        ╞═════╪═══════╪════════════════╡\n        │ a   ┆ 2     ┆ 17.0           │\n        │ c   ┆ 3     ┆ 1.0            │\n        │ b   ┆ 5     ┆ 10.0           │\n        └─────┴───────┴────────────────┘\n        \"\"\"\n        if aggs and isinstance(aggs[0], dict):\n            msg = (\n                \"specifying aggregations as a dictionary is not supported\"\n                \"\\n\\nTry unpacking the dictionary to take advantage of the keyword syntax\"\n                \" of the `agg` method.\"\n            )\n            raise TypeError(msg)\n\n        pyexprs = parse_into_list_of_expressions(*aggs, **named_aggs)\n        return wrap_ldf(self.lgb.agg(pyexprs))\n\n    def map_groups(\n        self,\n        function: Callable[[DataFrame], DataFrame],\n        schema: SchemaDict | None,\n    ) -> LazyFrame:\n        \"\"\"\n        Apply a custom/user-defined function (UDF) over the groups as a new DataFrame.\n\n        .. warning::\n            This method is much slower than the native expressions API.\n            Only use it if you cannot implement your logic otherwise.\n\n        Using this is considered an anti-pattern as it will be very slow because:\n","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/lazyframe/group_by.py#L175-L211","documentation":"GroupBy.agg does not accept a single dict of name->aggregation (the old/pandas-style API). If the first positional argument is a dict, TypeError is raised with a hint to unpack it into keyword arguments; note the dict VALUES must be polars expressions, not strings like 'sum'.","triggerScenarios":"lf.group_by('a').agg({'b': 'sum'}); .agg({'b': 'sum', 'c': 'max'}) translated from pandas; LLM/snippet-generated dict aggregations.","commonSituations":"Migrating pandas workflows or pre-0.19 polars code; copy-pasted examples using dict syntax.","solutions":["Use expressions: .agg(pl.col('b').sum(), pl.col('c').max())","Use keyword syntax with expression values: .agg(b_sum=pl.col('b').sum())","Unpack a dict of expressions: .agg(**{'b': pl.col('b').sum()})","For many columns: .agg(pl.col(cols).sum().name.prefix('sum_'))"],"exampleFix":"// before\nlf.group_by('a').agg({'b': 'sum', 'c': 'max'})\n\n// after\nlf.group_by('a').agg(pl.col('b').sum(), pl.col('c').max())","handlingStrategy":"type-guard","validationCode":"if aggs and isinstance(aggs[0], dict):\n    aggs = [expr for name, expr in aggs[0].items()]  # values must already be Exprs\n# then .agg(*aggs)","typeGuard":"def is_dict_agg(args) -> bool:\n    return bool(args) and isinstance(args[0], dict)","tryCatchPattern":null,"preventionTips":["Always aggregate with pl.col(...).<method>() expressions in polars; string specs like 'sum' are pandas-only","Keyword form .agg(name=expr) gives named output columns directly"],"tags":["polars","group-by","aggregation","api-migration"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}