From a11b23d1669dafada8365919016c33c0e5d09013 Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Mon, 23 Oct 2023 23:39:35 -0600 Subject: [PATCH] test: add more weird join predicate tests As I was exploring https://github.com/ibis-project/ibis/issues/6506, I deiscovered that there were all these join predicate types that currenty work, but only sort of "accidentally", and they aren't actually tested for. This adds tests for those. --- ibis/tests/expr/test_table.py | 42 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/ibis/tests/expr/test_table.py b/ibis/tests/expr/test_table.py index 05350946c20e..58220df7af61 100644 --- a/ibis/tests/expr/test_table.py +++ b/ibis/tests/expr/test_table.py @@ -1102,25 +1102,39 @@ def test_inner_join_overlapping_column_names(): ] -def test_join_key_alternatives(con): +@pytest.mark.parametrize( + "key_maker", + [ + lambda t1, t2: t1.foo_id == t2.foo_id, + lambda t1, t2: [("foo_id", "foo_id")], + lambda t1, t2: [(t1.foo_id, t2.foo_id)], + lambda t1, t2: [(_.foo_id, _.foo_id)], + lambda t1, t2: [(t1.foo_id, _.foo_id)], + lambda t1, t2: [(2, 0)], # foo_id is 2nd in t1, 0th in t2 + lambda t1, t2: [(lambda t: t.foo_id, lambda t: t.foo_id)], + ], +) +def test_join_key_alternatives(con, key_maker): t1 = con.table("star1") t2 = con.table("star2") - - # Join with tuples - joined = t1.inner_join(t2, [("foo_id", "foo_id")]) - joined2 = t1.inner_join(t2, [(t1.foo_id, t2.foo_id)]) - - # Join with single expr - joined3 = t1.inner_join(t2, t1.foo_id == t2.foo_id) - expected = t1.inner_join(t2, [t1.foo_id == t2.foo_id]) - + key = key_maker(t1, t2) + joined = t1.inner_join(t2, key) assert_equal(joined, expected) - assert_equal(joined2, expected) - assert_equal(joined3, expected) - with pytest.raises(com.ExpressionError): - t1.inner_join(t2, [("foo_id", "foo_id", "foo_id")]) + +@pytest.mark.parametrize( + "key,error", + [ + ([("foo_id", "foo_id", "foo_id")], com.ExpressionError), + ([(s.c("foo_id"), s.c("foo_id"))], ValueError), + ], +) +def test_join_key_invalid(con, key, error): + t1 = con.table("star1") + t2 = con.table("star2") + with pytest.raises(error): + t1.inner_join(t2, key) def test_join_invalid_refs(con):