{"record":{"id":"ca49619d94f005c5","repo":"pola-rs/polars","slug":"using-agg-list-true-is-deprecated-and-will-be-re","errorCode":null,"errorMessage":"using 'agg_list=True' is deprecated and will be removed in 2.0\n\nConsider using {self}.implode() instead","messagePattern":"using 'agg_list=True' is deprecated and will be removed in 2\\.0\n\nConsider using (.+?)\\.implode\\(\\) instead","errorType":"exception","errorClass":"DeprecationWarning","httpStatus":null,"severity":"warning","filePath":"py-polars/src/polars/expr/expr.py","lineNumber":5242,"sourceCode":"        ...     )\n        ... )\n        shape: (4, 3)\n        ┌─────┬─────┬───────────┐\n        │ a   ┆ b   ┆ a_times_b │\n        │ --- ┆ --- ┆ ---       │\n        │ i64 ┆ i64 ┆ i64       │\n        ╞═════╪═════╪═══════════╡\n        │ 5   ┆ 4   ┆ 20        │\n        │ 1   ┆ 2   ┆ 2         │\n        │ 0   ┆ 3   ┆ 0         │\n        │ 3   ┆ 4   ┆ 12        │\n        └─────┴─────┴───────────┘\n        \"\"\"\n        if agg_list:\n            msg = f\"\"\"using 'agg_list=True' is deprecated and will be removed in 2.0\n\nConsider using {self}.implode() instead\"\"\"\n            raise DeprecationWarning(msg)\n            self = self.implode()\n\n        def _wrap(sl: Sequence[pl.Series], *args: Any, **kwargs: Any) -> pl.Series:\n            return function(sl[0], *args, **kwargs)\n\n        return F.map_batches(\n            [self],\n            _wrap,\n            return_dtype,\n            is_elementwise=is_elementwise,\n            returns_scalar=returns_scalar,\n        )\n\n    def map_elements(\n        self,\n        function: Callable[[Any], Any],\n        return_dtype: PolarsDataType | pl.DataTypeExpr | None = None,\n        *,","sourceCodeStart":5224,"sourceCodeEnd":5260,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/expr/expr.py#L5224-L5260","documentation":"Expr.map_elements(agg_list=True) raises a DeprecationWarning as a hard exception (DeprecationWarning subclasses Exception, so this propagates with a traceback; the self.implode() line after the raise is dead code). The agg_list flag pre-aggregates groups into lists before applying the function, and polars 1.x removed that convenience in favor of calling .implode() yourself. Despite being a warning class, nothing is printed — it must be caught as an exception.","triggerScenarios":"Any call pl.col('a').map_elements(f, agg_list=True) or return_dtype=..., agg_list=True inside group_by/over contexts, typically legacy code from polars 0.x.","commonSituations":"Upgrading a codebase across the polars 1.0 boundary; old StackOverflow answers and tutorials written against 0.19 or earlier; internal libs that shipped agg_list=True for per-group list processing.","solutions":["Replace agg_list=True with an explicit .implode() before mapping: expr.implode().map_elements(f) (inside aggregation contexts) or drop it if you do not want lists.","If the function already receives a Series per group without the flag, simply delete agg_list=True.","For new code needing grouped lists, use expr implode within group_by().agg()."],"exampleFix":"# before\n(pl.DataFrame({'g': ['a', 'a'], 'v': [1, 2]})\n .group_by('g').agg(pl.col('v').map_elements(lambda s: s.sum(), agg_list=True)))\n\n# after\n(pl.DataFrame({'g': ['a', 'a'], 'v': [1, 2]})\n .group_by('g').agg(pl.col('v').implode().map_elements(lambda s: s.sum())))","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = expr.map_elements(f, agg_list=True)\nexcept DeprecationWarning:\n    out = expr.implode().map_elements(f)","preventionTips":["Search the codebase for 'agg_list' before every polars major upgrade.","Prefer native expressions over map_elements; most agg_list use cases now have built-ins (list.sum(), etc.).","Pin polars versions in CI and read the migration guide for 1.0/2.0."],"tags":["deprecation","polars","expression","upgrade","map-elements"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}