Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test that / performs true division, not floor division #10359

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
)
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)

Check warning on line 333 in ibis/backends/sql/compilers/flink.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/sql/compilers/flink.py#L332-L333

Added lines #L332 - L333 were not covered by tests

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
Loading