Polars cares about schema correctness by default in operations and prefers throwing an error above silently succeeding as it might indicate a bug in your program.
If you want polars
to add the columns, add the kwarg how="diagonal"
to pl.concat
.
df_a = pl.DataFrame({
"a": [1, 2, 3],
"b": [True, None, False],
})
df_b = pl.DataFrame({
"a": [4, 5],
"c": ["bar", "ham"]
})
pl.concat([df_a, df_b], how="diagonal")
shape: (5, 3)
┌─────┬───────┬──────┐
│ a ┆ b ┆ c │
│ --- ┆ --- ┆ --- │
│ i64 ┆ bool ┆ str │
╞═════╪═══════╪══════╡
│ 1 ┆ true ┆ null │
├╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 2 ┆ null ┆ null │
├╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 3 ┆ false ┆ null │
├╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 4 ┆ null ┆ bar │
├╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 5 ┆ null ┆ ham │
└─────┴───────┴──────┘