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

Warn on cuDF failure when POLARS_VERBOSE is true #16308

Merged
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
12 changes: 11 additions & 1 deletion python/cudf_polars/cudf_polars/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
34 changes: 34 additions & 0 deletions python/cudf_polars/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -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)
Loading