Skip to content

Commit

Permalink
test: add test that / performs true division, not floor division (#…
Browse files Browse the repository at this point in the history
…10359)

Co-authored-by: Phillip Cloud <[email protected]>
  • Loading branch information
NickCrews and cpcloud authored Oct 31, 2024
1 parent 9cbbc49 commit 75ecf03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 40 deletions.
4 changes: 4 additions & 0 deletions ibis/backends/sql/compilers/flink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
46 changes: 6 additions & 40 deletions ibis/backends/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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),
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 75ecf03

Please sign in to comment.