Repository: pola-rs/polars
File: py-polars/tests/unit/io/database/test_read.py (Python)

Code before:
            if conn is alchemy_session and param == "?":
                continue
            # skip for older sqlalchemy versions and for ADBC
            # NOTE: remove skip for ADBC once
            # https://github.com/apache/arrow-adbc/issues/3262 is released
            if (
                conn is adbc_conn or parse_version(sqlalchemy.__version__) < (2, 0)
            ) and param == ":n":
                continue
            # only ADBC supports PyArrow / Polars types as parameters
            if conn is not adbc_conn and isinstance(
                param_value, (pa.Table, pl.DataFrame, pl.Series)
            ):
                continue

            assert_frame_equal(
                expected_frame,
                pl.read_database(
                    query.format(n=param),
                    connection=conn,
                    execute_options={"parameters": param_value},
                ),
            )


@pytest.mark.parametrize(
    ("param", "param_value"),
    [
        pytest.param(
            ":n",
            pa.Table.from_pydict({"n": [0]}),
            marks=pytest.mark.skip(
                reason=(
                    "Named binding not currently supported. Test passing is a false positive. "
                    "See https://github.com/apache/arrow-adbc/issues/3262"
                )
            ),
        ),
        pytest.param(
            ":n",
            {"n": 0},
            marks=pytest.mark.xfail(
                reason="Named binding not currently supported. See https://github.com/apache/arrow-adbc/issues/3262",
                strict=True,
            ),
        ),
        ("?", pa.Table.from_pydict({"data": [0]})),
        ("?", pl.DataFrame({"data": [0]})),
        ("?", pl.Series([{"data": 0}])),
        ("?", (0,)),
        ("?", [0]),

Review comment (suggestion):
the declaration of `param` and `param_value` here clobbered the pytest params. They are now params only

Code after:


@pytest.mark.parametrize(
    ("param", "param_value"),
    [
        pytest.param(
            ":n",
            pa.Table.from_pydict({"n": [0]}),
            marks=pytest.mark.skip(
                reason="Named binding not currently supported. See https://github.com/apache/arrow-adbc/issues/3262"
            ),
        ),
        pytest.param(
            ":n",
            {"n": 0},
            marks=pytest.mark.skip(
                reason="Named binding not currently supported. See https://github.com/apache/arrow-adbc/issues/3262",
            ),
        ),
        ("?", pa.Table.from_pydict({"data": [0]})),
        ("?", pl.DataFrame({"data": [0]})),
        ("?", pl.Series([{"data": 0}])),
        ("?", (0,)),
        ("?", [0]),
    ],
)
@pytest.mark.skipif(
    sys.platform == "win32", reason="adbc_driver_sqlite not available on Windows"
)
def test_read_database_parameterised_adbc(
    param: str, param_value: Any, tmp_sqlite_db: Path
) -> None:
    # establish parameterised queries and validate usage
    query = """
        SELECT CAST(STRFTIME('%Y',"date") AS INT) as "year", name, value
        FROM test_data
        WHERE value < {n}
    """
    expected_frame = pl.DataFrame({"year": [2021], "name": ["other"], "value": [-99.5]})

    # ADBC will complain in pytest if the connection isn't closed
    with adbc_driver_sqlite.dbapi.connect(str(tmp_sqlite_db)) as conn:
        assert_frame_equal(
            expected_frame,
            pl.read_database(
                query.format(n=param),
                connection=conn,
                execute_options={"parameters": param_value},
            ),
        )