Skip to content

Commit

Permalink
test: add tests for Value.cases()
Browse files Browse the repository at this point in the history
This is setup for #9039,
where I change the API of Value.cases(),
so I want to make sure that
this functionality doesn't change, but
the user gets a deprecationwarning
  • Loading branch information
NickCrews committed Jul 12, 2024
1 parent 8862979 commit 3f6cb41
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions ibis/backends/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,53 @@ def test_sample_with_seed(backend):
backend.assert_frame_equal(df1, df2)


@pytest.mark.parametrize(
"inp, exp",
[
pytest.param(
lambda: ibis.literal(1).cases([(1, "one"), (2, "two")], "other"),
"one",
id="basic",
),
pytest.param(
lambda: ibis.literal(1).cases([(1, "one"), (2, "two")], default="other"),
"one",
id="one_kwarg",
),
pytest.param(
lambda: ibis.literal(1).cases(
case_result_pairs=[(1, "one"), (2, "two")], default="other"
),
"one",
id="two_kwargs",
),
pytest.param(
lambda: ibis.literal(1).cases(
default="other", case_result_pairs=[(1, "one"), (2, "two")]
),
"one",
id="two_kwargs_swapped",
),
pytest.param(
lambda: ibis.literal(5).cases([(1, "one"), (2, "two")], "other"),
"other",
id="other",
),
pytest.param(
lambda: ibis.literal(5).cases([(1, "one"), (2, "two")]),
None,
id="fallthrough",
),
],
)
def test_value_cases(con, inp, exp):
result = con.execute(inp())
if exp is None:
assert pd.isna(result)
else:
assert result == exp


def test_substitute(backend):
val = "400"
t = backend.functional_alltypes
Expand Down

0 comments on commit 3f6cb41

Please sign in to comment.