From cb01cb6a245097be03cb3902bad1fea3c008ffa4 Mon Sep 17 00:00:00 2001 From: ritchie Date: Fri, 19 Jul 2024 17:24:32 +0200 Subject: [PATCH] fix --- py-polars/polars/functions/as_datatype.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/py-polars/polars/functions/as_datatype.py b/py-polars/polars/functions/as_datatype.py index d09a8cead6dc..a3ed5bb86414 100644 --- a/py-polars/polars/functions/as_datatype.py +++ b/py-polars/polars/functions/as_datatype.py @@ -596,7 +596,6 @@ def struct( Schema({'my_struct': Struct({'p': Int64, 'q': Boolean})}) """ pyexprs = parse_into_list_of_expressions(*exprs, **named_exprs) - expr = wrap_expr(plr.as_struct(pyexprs)) if schema: if not exprs: @@ -604,7 +603,11 @@ def struct( expr = wrap_expr( plr.as_struct(parse_into_list_of_expressions(list(schema.keys()))) ) + else: + expr = wrap_expr(plr.as_struct(pyexprs)) expr = expr.cast(Struct(schema), strict=False) + else: + expr = wrap_expr(plr.as_struct(pyexprs)) if eager: return F.select(expr).to_series()