From 75ecf038d917b968dcc493c69429abe1e8549dd2 Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Thu, 31 Oct 2024 06:23:13 -0800 Subject: [PATCH] test: add test that `/` performs true division, not floor division (#10359) Co-authored-by: Phillip Cloud <417981+cpcloud@users.noreply.github.com> --- ibis/backends/sql/compilers/flink.py | 4 +++ ibis/backends/tests/test_numeric.py | 46 ++++------------------------ 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/ibis/backends/sql/compilers/flink.py b/ibis/backends/sql/compilers/flink.py index 7dcab84d2952..586b3a429990 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)) diff --git a/ibis/backends/tests/test_numeric.py b/ibis/backends/tests/test_numeric.py index 9deeb4e9a8fc..70721ba17113 100644 --- a/ibis/backends/tests/test_numeric.py +++ b/ibis/backends/tests/test_numeric.py @@ -1099,6 +1099,12 @@ def test_binary_arithmetic_operations(backend, alltypes, df, op): backend.assert_series_equal(result, expected, check_exact=False) +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") @@ -1142,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( @@ -1158,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( @@ -1174,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( @@ -1190,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), @@ -1209,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( @@ -1226,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( @@ -1243,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( @@ -1260,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(