Skip to content

Commit

Permalink
test(redo): add some basic cast tests (#9483)
Browse files Browse the repository at this point in the history
redo of #9461
  • Loading branch information
NickCrews authored Jul 13, 2024
1 parent 63b3cac commit 7d2a343
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions ibis/backends/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
OracleDatabaseError,
PolarsSchemaError,
PsycoPg2InternalError,
PsycoPg2SyntaxError,
Py4JJavaError,
PyDruidProgrammingError,
PyODBCDataError,
Expand Down Expand Up @@ -1763,6 +1764,55 @@ def hash_256(col):
backend.assert_series_equal(h1, h2)


@pytest.mark.parametrize(
("from_type", "to_type", "from_val", "expected"),
[
param("int", "float", 0, 0.0, id="int_to_float"),
param("float", "int", 0.0, 0, id="float_to_int"),
param("string", "int", "0", 0, id="string_to_int"),
param("string", "float", "0", 0.0, id="string_to_float"),
param(
"array<int>",
"array<string>",
[0, 1, 2],
["0", "1", "2"],
marks=[
pytest.mark.notimpl(["pandas"], reason="casts to ['0']"),
pytest.mark.notimpl(["druid"], raises=PyDruidProgrammingError),
pytest.mark.notimpl(["oracle"], raises=OracleDatabaseError),
pytest.mark.never(
["exasol", "impala", "mssql", "mysql", "sqlite"],
reason="backend doesn't support arrays",
),
],
id="array",
),
param(
"struct<a: int, b: string>",
"struct<a: string, b: int>",
{"a": 0, "b": "1"},
{"a": "0", "b": 1},
marks=[
pytest.mark.notimpl(["flink"], raises=Py4JJavaError),
pytest.mark.notimpl(["druid"], raises=PyDruidProgrammingError),
pytest.mark.notimpl(["oracle"], raises=OracleDatabaseError),
pytest.mark.notimpl(["postgres"], raises=PsycoPg2SyntaxError),
pytest.mark.notimpl(["risingwave"], raises=PsycoPg2InternalError),
pytest.mark.never(
["datafusion", "exasol", "impala", "mssql", "mysql", "sqlite"],
reason="backend doesn't support structs",
),
],
id="struct",
),
],
)
def test_cast(con, from_type, to_type, from_val, expected):
expr = ibis.literal(from_val, type=from_type).cast(to_type)
result = con.execute(expr)
assert result == expected


@pytest.mark.notimpl(["pandas", "dask", "oracle", "sqlite"])
@pytest.mark.parametrize(
("from_val", "to_type", "expected"),
Expand Down

0 comments on commit 7d2a343

Please sign in to comment.