Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jul 21, 2024
1 parent 0ea3719 commit cb01cb6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion py-polars/polars/functions/as_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,18 @@ 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:
# no columns or expressions provided; create one from schema keys
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()
Expand Down

0 comments on commit cb01cb6

Please sign in to comment.