From 6880375ba9a4e9f48ee2211caa030726e34bc108 Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Wed, 23 Oct 2024 13:32:55 -0800 Subject: [PATCH 1/3] test: add test that `/` performs true division, not floor division --- ibis/backends/tests/test_numeric.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ibis/backends/tests/test_numeric.py b/ibis/backends/tests/test_numeric.py index 9deeb4e9a8fc..d028ea15721b 100644 --- a/ibis/backends/tests/test_numeric.py +++ b/ibis/backends/tests/test_numeric.py @@ -1099,6 +1099,13 @@ def test_binary_arithmetic_operations(backend, alltypes, df, op): backend.assert_series_equal(result, expected, check_exact=False) +@pytest.mark.notimpl("flink", raises=AssertionError, reason="Flink does floor division") +def test_integer_truediv(con): + expr = 1 / ibis.literal(2) + result = con.execute(expr) + assert result == 0.5 + + def test_mod(backend, alltypes, df): expr = operator.mod(alltypes.smallint_col, alltypes.smallint_col + 1).name("tmp") From 8df3d9c3ac33a06434b31e8a3fb16505ae0a90f7 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Thu, 24 Oct 2024 08:50:35 -0400 Subject: [PATCH 2/3] fix(flink): give true division semantics to flink division operation --- ibis/backends/sql/compilers/flink.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ibis/backends/sql/compilers/flink.py b/ibis/backends/sql/compilers/flink.py index 1b313f924932..72fa6fad0dd8 100644 --- a/ibis/backends/sql/compilers/flink.py +++ b/ibis/backends/sql/compilers/flink.py @@ -328,6 +328,10 @@ def visit_TryCast(self, op, *, arg, to): ) return sge.TryCast(this=arg, to=type_mapper.from_ibis(to)) + def visit_Divide(self, op, *, left, right): + dtype = op.dtype + return self.cast(left, dtype) / self.cast(right, dtype) + def visit_FloorDivide(self, op, *, left, right): return self.f.floor(sge.paren(left) / sge.paren(right)) From b461b4cda5950d2d62b24a089f1aeb023e7104ef Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Tue, 29 Oct 2024 12:16:13 -0800 Subject: [PATCH 3/3] chore(flink): remove xfails now that flink passes --- ibis/backends/tests/test_numeric.py | 41 ----------------------------- 1 file changed, 41 deletions(-) diff --git a/ibis/backends/tests/test_numeric.py b/ibis/backends/tests/test_numeric.py index d028ea15721b..70721ba17113 100644 --- a/ibis/backends/tests/test_numeric.py +++ b/ibis/backends/tests/test_numeric.py @@ -1099,7 +1099,6 @@ def test_binary_arithmetic_operations(backend, alltypes, df, op): backend.assert_series_equal(result, expected, check_exact=False) -@pytest.mark.notimpl("flink", raises=AssertionError, reason="Flink does floor division") def test_integer_truediv(con): expr = 1 / ibis.literal(2) result = con.execute(expr) @@ -1149,11 +1148,6 @@ def test_floating_mod(backend, alltypes, df): raises=OracleDatabaseError, reason="Oracle doesn't do integer division by zero", ), - pytest.mark.notyet( - "flink", - raises=Py4JJavaError, - reason="Flink doesn't do integer division by zero", - ), ], ), param( @@ -1165,11 +1159,6 @@ def test_floating_mod(backend, alltypes, df): raises=OracleDatabaseError, reason="Oracle doesn't do integer division by zero", ), - pytest.mark.notyet( - "flink", - raises=Py4JJavaError, - reason="Flink doesn't do integer division by zero", - ), ], ), param( @@ -1181,11 +1170,6 @@ def test_floating_mod(backend, alltypes, df): raises=OracleDatabaseError, reason="Oracle doesn't do integer division by zero", ), - pytest.mark.notyet( - "flink", - raises=Py4JJavaError, - reason="Flink doesn't do integer division by zero", - ), ], ), param( @@ -1197,11 +1181,6 @@ def test_floating_mod(backend, alltypes, df): raises=OracleDatabaseError, reason="Oracle doesn't do integer division by zero", ), - pytest.mark.notyet( - "flink", - raises=Py4JJavaError, - reason="Flink doesn't do integer division by zero", - ), ], ), param("float_col", 0), @@ -1216,11 +1195,6 @@ def test_floating_mod(backend, alltypes, df): reason="Oracle doesn't do integer division by zero", ), pytest.mark.never(["impala"], reason="doesn't allow divide by zero"), - pytest.mark.notyet( - "flink", - raises=Py4JJavaError, - reason="Flink doesn't do integer division by zero", - ), ], ), param( @@ -1233,11 +1207,6 @@ def test_floating_mod(backend, alltypes, df): reason="Oracle doesn't do integer division by zero", ), pytest.mark.never(["impala"], reason="doesn't allow divide by zero"), - pytest.mark.notyet( - "flink", - raises=Py4JJavaError, - reason="Flink doesn't do integer division by zero", - ), ], ), param( @@ -1250,11 +1219,6 @@ def test_floating_mod(backend, alltypes, df): reason="Oracle doesn't do integer division by zero", ), pytest.mark.never(["impala"], reason="doesn't allow divide by zero"), - pytest.mark.notyet( - "flink", - raises=Py4JJavaError, - reason="Flink doesn't do integer division by zero", - ), ], ), param( @@ -1267,11 +1231,6 @@ def test_floating_mod(backend, alltypes, df): reason="Oracle doesn't do integer division by zero", ), pytest.mark.never(["impala"], reason="doesn't allow divide by zero"), - pytest.mark.notyet( - "flink", - raises=Py4JJavaError, - reason="Flink doesn't do integer division by zero", - ), ], ), param(