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()