Skip to content

Commit

Permalink
Warn on cuDF failure when POLARS_VERBOSE is true (#16308)
Browse files Browse the repository at this point in the history
Just something quick to get us started here

Closes #16256

Authors:
  - https://github.com/brandon-b-miller
  - Lawrence Mitchell (https://github.com/wence-)

Approvers:
  - Lawrence Mitchell (https://github.com/wence-)

URL: #16308
  • Loading branch information
brandon-b-miller authored Jul 24, 2024
1 parent 62625f1 commit 743264f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
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)

0 comments on commit 743264f

Please sign in to comment.