2025, Nov 13 09:00

Fixing Polars 1.31 concat_arr DuplicateError: Array construction bug, causes, and quick fixes

Upgrading to Polars 1.31 may trigger concat_arr DuplicateError during lazy collect. Learn the cause and fix: safe Array construction patterns, List fallback.

Upgrading to Polars 1.31.0 can unexpectedly break array construction code that previously worked without issues. If you concatenate several columns into an Array and assign a name with alias, you may now encounter a DuplicateError during lazy collect, even though your pipeline hasn’t changed.

Reproducing the symptom

Consider an expression that builds a 3D position vector from three numeric columns, then names the result:

pl.concat_arr( 
    pl.col("x_m", "y_m", "z_m") 
).alias("antenna_pos_m")

On Polars 1.31.0 this can fail at collect time with a duplicate-name error similar to the following:

polars.exceptions.DuplicateError: the name 'Antenna_position[m]' is duplicate

What’s actually going on

This is not a feature removal. It’s a known bug in Polars 1.31 that was fixed on the main branch after the release. There simply hasn’t been a new release including the fix yet. Details are tracked here: https://github.com/pola-rs/polars/issues/23267. Polars also marks Array concat_arr as unstable in the docs, which explains why a minor change could surface a regression: https://docs.pola.rs/api/python/dev/reference/expressions/api/polars.concat_arr.html. The behavior is not tied to your alias specifically; the issue is in how the expression resolves names in this version.

How to fix it right now

The cleanest workaround is to pass column names directly to concat_arr instead of wrapping them in a single pl.col call. This avoids the duplicate-name path in 1.31 and keeps you on the Array data type:

pl.concat_arr( 
    "x_m", 
    "y_m", 
    "z_m" 
).alias("antenna_pos_m")

If you prefer to keep the pl.col expressions, you can pass them as separate arguments to concat_arr while staying on 1.31:

pl.concat_arr( 
    pl.col("x_m"), 
    pl.col("y_m") 
)

Another viable path is to switch to a List instead of an Array:

pl.concat_list( 
    pl.col("x_m", "y_m", "z_m") 
).alias("antenna_pos_m")

Polars’ user guide recommends Array over List for performance, so the first workaround is usually preferable if you care about speed: https://docs.pola.rs/user-guide/expressions/lists-and-arrays/#the-data-type-array. Alternatively, you can pin Polars to 1.30 until 1.32 is available, where the fix is expected to land.

Why this matters

Even small library upgrades can change expression resolution in ways that surface as runtime errors in lazy pipelines. concat_arr is marked unstable, and this incident shows why reading release notes, pinning versions, and knowing quick workarounds are essential for keeping production data code resilient. If you rely on Array for performance, knowing how to call concat_arr safely on 1.31 will save you from refactors or regressions.

Takeaways

If your array concatenation started failing after moving to Polars 1.31, treat it as a version-specific bug rather than a breaking API change. Pass column names directly to concat_arr, or supply separate pl.col calls, or temporarily fall back to concat_list. If possible, stick to Polars 1.30 until 1.32 is released, and follow the upstream issue for status updates: https://github.com/pola-rs/polars/issues/23267.