From c2fcc4eba4c0891f4f312e1937558e5e680294ec Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Mon, 15 Jan 2024 06:11:09 -0500 Subject: [PATCH] test(generic): break out test_generic try_cast null test --- ibis/backends/tests/test_generic.py | 54 +++++++++++++++++++---------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/ibis/backends/tests/test_generic.py b/ibis/backends/tests/test_generic.py index f1eca2021396..6bfefccb1922 100644 --- a/ibis/backends/tests/test_generic.py +++ b/ibis/backends/tests/test_generic.py @@ -1262,20 +1262,12 @@ def test_hash_consistent(backend, alltypes): param(0.0, "int", 0), param("0", "int", 0), param("0.0", "float", 0.0), - param( - "a", - "int", - None, - marks=pytest.mark.notyet(["flink"], reason="casts to nan"), - ), param( datetime.datetime(2023, 1, 1), "int", - None, + 1672531200, marks=[ - pytest.mark.never( - ["clickhouse", "flink"], reason="casts to 1672531200" - ), + pytest.mark.notyet(["duckdb"], reason="casts to None"), pytest.mark.notyet( ["trino"], raises=sa.exc.ProgrammingError, @@ -1284,25 +1276,51 @@ def test_hash_consistent(backend, alltypes): pytest.mark.broken(["polars"], reason="casts to 1672531200000000000"), ], ), + ], + ids=str, +) +def test_try_cast_expected(con, from_val, to_type, expected): + assert con.execute(ibis.literal(from_val).try_cast(to_type)) == expected + + +@pytest.mark.notimpl( + [ + "pandas", + "dask", + "bigquery", + "datafusion", + "druid", + "impala", + "mssql", + "mysql", + "oracle", + "postgres", + "pyspark", + "snowflake", + "sqlite", + "exasol", + ] +) +@pytest.mark.parametrize( + ("from_val", "to_type"), + [ + param("a", "int"), param( datetime.datetime(2023, 1, 1), "int", - 1672531200, marks=[ - pytest.mark.notyet(["duckdb"], reason="casts to None"), - pytest.mark.notyet( - ["trino"], - raises=sa.exc.ProgrammingError, - reason="raises TrinoUserError", + pytest.mark.never( + ["clickhouse", "flink"], reason="casts to 1672531200" ), + pytest.mark.notyet(["trino"], raises=sa.exc.ProgrammingError), pytest.mark.broken(["polars"], reason="casts to 1672531200000000000"), ], ), ], ids=str, ) -def test_try_cast_expected(con, from_val, to_type, expected): - assert con.execute(ibis.literal(from_val).try_cast(to_type)) == expected +def test_try_cast_expected_null(con, from_val, to_type): + assert pd.isna(con.execute(ibis.literal(from_val).try_cast(to_type))) @pytest.mark.notimpl(