From 949b645a2edd85b5c348774a0cc9ee04589659b1 Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Wed, 24 Apr 2024 14:18:19 -0800 Subject: [PATCH] test: add tests for Value.cases() This is setup for https://github.com/ibis-project/ibis/pull/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 --- ibis/backends/tests/test_generic.py | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/ibis/backends/tests/test_generic.py b/ibis/backends/tests/test_generic.py index cf68976188510..da69726f1c910 100644 --- a/ibis/backends/tests/test_generic.py +++ b/ibis/backends/tests/test_generic.py @@ -2026,6 +2026,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