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

Code before:
                continue  # alchemy session.execute() doesn't support positional params
            if parse_version(sqlalchemy.__version__) < (2, 0) and param == ":n":
                continue  # skip for older sqlalchemy versions

            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"),
    [
        (":n", {"n": 0}),
        ("?", (0,)),
        ("?", [0]),
    ],
)
@pytest.mark.skipif(
    sys.platform == "win32", reason="adbc_driver_sqlite not available on Windows"
)
def test_read_database_parameterised_uri(
    param: str, param_value: Any, tmp_sqlite_db: Path
) -> None:
    alchemy_engine = create_engine(f"sqlite:///{tmp_sqlite_db}")
    uri = alchemy_engine.url.render_as_string(hide_password=False)
    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]})

    for param, param_value in (
        (":n", pa.Table.from_pydict({"n": [0]})),
        ("?", (0,)),
        ("?", [0]),
    ):
        # test URI read method (adbc only)
        assert_frame_equal(
            expected_frame,
            pl.read_database_uri(
                query.format(n=param),
                uri=uri,
                engine="adbc",
                execute_options={"parameters": param_value},
            ),

Review comment (suggestion):
test renamed to `test_read_database_uri_parameterised` and is further below

Code after:
    expected_frame = pl.DataFrame({"year": [2021], "name": ["other"], "value": [-99.5]})

    for conn in (alchemy_session, alchemy_engine, alchemy_conn, raw_conn):
        if conn is alchemy_session and param == "?":
            continue  # alchemy session.execute() doesn't support positional params
        if parse_version(sqlalchemy.__version__) < (2, 0) and param == ":n":
            continue  # skip for older sqlalchemy versions

        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. 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