Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
barak1412 committed Sep 27, 2024
1 parent b6c3491 commit 54e87a5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions py-polars/tests/unit/functions/test_when_then.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,35 @@ def test_when_then_parametric(
assert ref["if_true"].to_list() == ans["if_true"].to_list()


def test_when_then_else_struct_18961() -> None:
v1 = [None, {"foo": 0, "bar": "1"}]
v2 = [{"foo": 0, "bar": "1"}, {"foo": 0, "bar": "1"}]

df = pl.DataFrame({"left": v1, "right": v2, "mask": [False, True]})

expected = [{"foo": 0, "bar": "1"}, {"foo": 0, "bar": "1"}]
ans = (
df.select(
pl.when(pl.col.mask).then(pl.col.left).otherwise(pl.col.right.first())
)
.get_column("left")
.to_list()
)
assert expected == ans

df = pl.DataFrame({"left": v2, "right": v1, "mask": [True, False]})

expected = [{"foo": 0, "bar": "1"}, {"foo": 0, "bar": "1"}]
ans = (
df.select(
pl.when(pl.col.mask).then(pl.col.left.first()).otherwise(pl.col.right)
)
.get_column("left")
.to_list()
)
assert expected == ans


def test_when_then_supertype_15975() -> None:
df = pl.DataFrame({"a": [1, 2, 3]})

Expand Down

0 comments on commit 54e87a5

Please sign in to comment.