Path: blob/main/py-polars/tests/unit/lazyframe/test_engine_selection.py
6939 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, match="GPU engine does not support streaming or background"35):36got = df.collect(engine=engine, background=True)37assert_frame_equal(expect, got.fetch_blocking())383940def test_engine_selection_eager_quiet(df: pl.LazyFrame, engine: EngineType) -> None:41expect = df.collect()42# _eager collection turns off GPU engine quietly43got = df.collect(engine=engine, optimizations=pl.QueryOptFlags._eager())44assert_frame_equal(expect, got)454647def test_engine_import_error_raises(df: pl.LazyFrame, engine: EngineType) -> None:48with pytest.raises(ImportError, match="GPU engine requested"):49df.collect(engine=engine)505152