pola-rs/polars · warning · DeprecationWarning
using 'agg_list=True' is deprecated and will be removed in 2
Error message
using 'agg_list=True' is deprecated and will be removed in 2.0
Consider using {self}.implode() instead What it means
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.
Source
Thrown at py-polars/src/polars/expr/expr.py:5242
... )
... )
shape: (4, 3)
┌─────┬─────┬───────────┐
│ a ┆ b ┆ a_times_b │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═══════════╡
│ 5 ┆ 4 ┆ 20 │
│ 1 ┆ 2 ┆ 2 │
│ 0 ┆ 3 ┆ 0 │
│ 3 ┆ 4 ┆ 12 │
└─────┴─────┴───────────┘
"""
if agg_list:
msg = f"""using 'agg_list=True' is deprecated and will be removed in 2.0
Consider using {self}.implode() instead"""
raise DeprecationWarning(msg)
self = self.implode()
def _wrap(sl: Sequence[pl.Series], *args: Any, **kwargs: Any) -> pl.Series:
return function(sl[0], *args, **kwargs)
return F.map_batches(
[self],
_wrap,
return_dtype,
is_elementwise=is_elementwise,
returns_scalar=returns_scalar,
)
def map_elements(
self,
function: Callable[[Any], Any],
return_dtype: PolarsDataType | pl.DataTypeExpr | None = None,
*,View on GitHub (pinned to df599052da)
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().
Example fix
# before
(pl.DataFrame({'g': ['a', 'a'], 'v': [1, 2]})
.group_by('g').agg(pl.col('v').map_elements(lambda s: s.sum(), agg_list=True)))
# after
(pl.DataFrame({'g': ['a', 'a'], 'v': [1, 2]})
.group_by('g').agg(pl.col('v').implode().map_elements(lambda s: s.sum()))) Defensive patterns
Strategy: try-catch
Try / catch
try:
out = expr.map_elements(f, agg_list=True)
except DeprecationWarning:
out = expr.implode().map_elements(f) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- strategy {strategy!r} is not supported
- cannot turn {qualified_type_name(input)!r} into selector
- Cannot pass a dictionary as a single positional argument.\nI
- unexpected or unrecognised op name ({opname})\n\nPlease repo
- expressions should be passed to the `by_predicate` parameter
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/ca49619d94f005c5.
Report an issue: GitHub.