Path: blob/main/py-polars/tests/unit/lazyframe/test_engine_selection.py
8420 views
from __future__ import annotations12from typing import TYPE_CHECKING34import pytest56import polars as pl7from polars.testing import assert_frame_equal89if TYPE_CHECKING:10from polars._typing import EngineType111213@pytest.fixture14def df() -> pl.LazyFrame:15return pl.LazyFrame({"a": [1, 2, 3]})161718@pytest.fixture(params=["gpu", pl.GPUEngine()])19def engine(request: pytest.FixtureRequest) -> EngineType:20value: EngineType = request.param21return value222324def test_engine_selection_invalid_raises(df: pl.LazyFrame) -> None:25with pytest.raises(ValueError):26df.collect(engine="unknown") # type: ignore[call-overload]272829def test_engine_selection_background_warns(30df: pl.LazyFrame, engine: EngineType31) -> None:32expect = df.collect()33with pytest.warns(34UserWarning,35match="GPU engine does not support streaming or background",36):37got = df.collect(engine=engine, background=True)38assert_frame_equal(expect, got.fetch_blocking())394041def test_engine_selection_eager_quiet(df: pl.LazyFrame, engine: EngineType) -> None:42expect = df.collect()43# _eager collection turns off GPU engine quietly44got = df.collect(engine=engine, optimizations=pl.QueryOptFlags._eager())45assert_frame_equal(expect, got)464748def test_engine_import_error_raises(df: pl.LazyFrame, engine: EngineType) -> None:49with pytest.raises(50ImportError,51match="GPU engine requested",52):53df.collect(engine=engine)545556