Skip to content

Commit

Permalink
test: add some basic cast tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCrews committed Jun 27, 2024
1 parent b150635 commit 2958d5c
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ibis/backends/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,55 @@ def hash_256(col):
backend.assert_series_equal(h1, h2)


@pytest.mark.parametrize(
("from_val", "from_type", "to_type", "expected"),
[
param(0, "int", "float", 0.0),
param(0.0, "float", "int", 0),
param("0", "string", "int", 0),
param("0.0", "string", "float", 0.0),
param(
datetime.datetime(2023, 1, 1),
"timestamp",
"string",
"2023-01-01 00:00:00",
marks=[
pytest.mark.broken(
["datafusion"], reason="casts to 1672531200000000 (microseconds)"
),
pytest.mark.broken(
["druid"], reason="casts to 1672531200000 (millisecond)"
),
pytest.mark.broken(["mysql"], reason="returns 20230101000000"),
pytest.mark.broken(
["polars"], reason="casts to 1672531200000000000 (nanoseconds)"
),
],
),
param(
[0, 1, 2],
"array<int>",
"array<string>",
["0", "1", "2"],
marks=[
pytest.mark.notyet(["pandas"], reason="casts to ['0']"),
],
),
param(
{"a": 0, "b": "1"},
"struct<a: int, b: string>",
"struct<a: string, b: int>",
{"a": "0", "b": 1},
),
],
ids=str,
)
def test_cast(con, from_val, from_type, to_type, 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 2958d5c

Please sign in to comment.