polars icon indicating copy to clipboard operation
polars copied to clipboard

concat_str over something not working anymore

Open Arengard opened this issue 1 year ago • 1 comments

Research

  • [X] I have searched the above polars tags on Stack Overflow for similar questions.

  • [ ] I have asked my usage related question on Stack Overflow.

Link to question on Stack Overflow

No response

Question about Polars

df = pl.DataFrame({
    "a":[1, 2, 3, 3, 2, 1],
    "text":["a", "b", "c", "d", "e", "f"],
}
)

### concat over group in an string
df = df.with_columns(text_x = pl.col("text").implode().over("a").arr.join(","))

##### split the string and concat with prefix - not working anymore use to work on polars < 17.2
(
    df
.with_columns(pl.col("text_x").str.split(",").arr.eval(pl.concat_str([pl.lit("prefix_"), pl.element()], separator=" ")).alias("new_col_Y"))
)

Arengard avatar Apr 23 '23 09:04 Arengard

It seems to be a more general issue and not specific to concat_str

pl.Series(["a,string"]).str.split(",").arr.eval("prefix" + pl.element())
InvalidOperationError: 
   output length of `map` must be equal to that of the input length;
   consider using `apply` instead
Error originated in expression: 
'Utf8(prefix).str.concat_horizontal([col("")])'

You may want to relabel this as a bug (and maybe include the exception being raised as it would help future people searching for the same issue)

cmdlineluser avatar Apr 23 '23 11:04 cmdlineluser

df.select(pl.all(), _.text.implode().over(_.num, mapping_strategy="join").list.get(0).list.sort(descending=True).list.join(", ").alias("x"))

Arengard avatar Feb 26 '24 14:02 Arengard