diff --git a/python/cudf_polars/cudf_polars/callback.py b/python/cudf_polars/cudf_polars/callback.py index 764cdd3b3ca..f31193aa938 100644 --- a/python/cudf_polars/cudf_polars/callback.py +++ b/python/cudf_polars/cudf_polars/callback.py @@ -5,11 +5,15 @@ from __future__ import annotations +import os +import warnings from functools import partial from typing import TYPE_CHECKING import nvtx +from polars.exceptions import PerformanceWarning + from cudf_polars.dsl.translate import translate_ir if TYPE_CHECKING: @@ -61,6 +65,12 @@ def execute_with_cudf( try: with nvtx.annotate(message="ConvertIR", domain="cudf_polars"): nt.set_udf(partial(_callback, translate_ir(nt))) - except exception: + except exception as e: + if bool(int(os.environ.get("POLARS_VERBOSE", 0))): + warnings.warn( + f"Query execution with GPU not supported, reason: {type(e)}: {e}", + PerformanceWarning, + stacklevel=2, + ) if raise_on_fail: raise diff --git a/python/cudf_polars/tests/test_config.py b/python/cudf_polars/tests/test_config.py new file mode 100644 index 00000000000..5b4bba55552 --- /dev/null +++ b/python/cudf_polars/tests/test_config.py @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +# SPDX-License-Identifier: Apache-2.0 + +from __future__ import annotations + +import pytest + +import polars as pl + +from cudf_polars.dsl.ir import IR +from cudf_polars.testing.asserts import ( + assert_gpu_result_equal, + assert_ir_translation_raises, +) + + +def test_polars_verbose_warns(monkeypatch): + def raise_unimplemented(self): + raise NotImplementedError("We don't support this") + + monkeypatch.setattr(IR, "__post_init__", raise_unimplemented) + q = pl.LazyFrame({}) + # Ensure that things raise + assert_ir_translation_raises(q, NotImplementedError) + with ( + pl.Config(verbose=True), + pytest.raises(pl.exceptions.ComputeError), + pytest.warns( + pl.exceptions.PerformanceWarning, + match="Query execution with GPU not supported", + ), + ): + # And ensure that collecting issues the correct warning. + assert_gpu_result_equal(q)