Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(python): Add/fix version-gating in some SQLAlchemy and Pandas tests #17538

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions py-polars/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ filterwarnings = [
# TODO: Excel tests lead to unclosed file warnings
# https://github.com/pola-rs/polars/issues/14466
"ignore:unclosed file.*:ResourceWarning",
# Ignore invalid warnings when running earlier versions of SQLAlchemy (we
# know they are invalid because our standard tests run the latest version)
"ignore:Deprecated API features detected.*:DeprecationWarning",
]
xfail_strict = true

Expand Down
5 changes: 3 additions & 2 deletions py-polars/tests/unit/interchange/test_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from hypothesis import given

import polars as pl
from polars._utils.various import parse_version
from polars.testing import assert_frame_equal
from polars.testing.parametric import dataframes

Expand Down Expand Up @@ -277,8 +278,8 @@ def test_to_dataframe_pyarrow_boolean_midbyte_slice() -> None:


@pytest.mark.skipif(
sys.version_info < (3, 9),
reason="Older versions of pandas do not implement the required conversions",
parse_version(pd.__version__) < (2, 2),
reason="Pandas versions < 2.2 do not implement the required conversions",
)
def test_from_dataframe_pandas_timestamp_ns() -> None:
df = pl.Series("a", [datetime(2000, 1, 1)], dtype=pl.Datetime("ns")).to_frame()
Expand Down
13 changes: 12 additions & 1 deletion py-polars/tests/unit/io/database/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from typing import TYPE_CHECKING, Any, Iterable, overload

import pytest
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
import sqlalchemy
from sqlalchemy.ext.asyncio import create_async_engine

import polars as pl
from polars._utils.various import parse_version
from polars.testing import assert_frame_equal

if TYPE_CHECKING:
Expand Down Expand Up @@ -66,9 +68,14 @@ async def query(
return [{"result": self._mock_data, "status": "OK", "time": "32.083µs"}]


@pytest.mark.skipif(
parse_version(sqlalchemy.__version__) < (2, 0),
reason="SQLAlchemy 2.0+ required for async tests",
)
def test_read_async(tmp_sqlite_db: Path) -> None:
# confirm that we can load frame data from the core sqlalchemy async
# primitives: AsyncConnection, AsyncEngine, and async_sessionmaker
from sqlalchemy.ext.asyncio import async_sessionmaker

async_engine = create_async_engine(f"sqlite+aiosqlite:///{tmp_sqlite_db}")
async_connection = async_engine.connect()
Expand Down Expand Up @@ -111,6 +118,10 @@ async def _nested_async_test(tmp_sqlite_db: Path) -> pl.DataFrame:
)


@pytest.mark.skipif(
parse_version(sqlalchemy.__version__) < (2, 0),
reason="SQLAlchemy 2.0+ required for async tests",
)
def test_read_async_nested(tmp_sqlite_db: Path) -> None:
# this tests validates that we can handle nested async calls. without
# the nested asyncio handling provided by `nest_asyncio` this test
Expand Down
4 changes: 4 additions & 0 deletions py-polars/tests/unit/io/database/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

import pyarrow as pa
import pytest
import sqlalchemy
from sqlalchemy import Integer, MetaData, Table, create_engine, func, select
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql.expression import cast as alchemy_cast

import polars as pl
from polars._utils.various import parse_version
from polars.exceptions import UnsuitableSQLError
from polars.io.database._arrow_registry import ARROW_DRIVER_REGISTRY
from polars.testing import assert_frame_equal
Expand Down Expand Up @@ -387,6 +389,8 @@ def test_read_database_parameterised(tmp_sqlite_db: Path) -> None:
for conn in (alchemy_session, alchemy_engine, alchemy_conn, raw_conn):
if alchemy_session is conn 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,
Expand Down