From af09d3e60e4ac4c86602e4e47e58cdb47a02b22c Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Thu, 13 Jun 2024 08:58:46 +0100 Subject: [PATCH] Raise early on unhandled PythonScan node (#15992) Add test of the behaviour. Authors: - Lawrence Mitchell (https://github.com/wence-) Approvers: - Bradley Dice (https://github.com/bdice) URL: https://github.com/rapidsai/cudf/pull/15992 --- python/cudf_polars/cudf_polars/dsl/ir.py | 4 ++++ python/cudf_polars/tests/test_python_scan.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 python/cudf_polars/tests/test_python_scan.py diff --git a/python/cudf_polars/cudf_polars/dsl/ir.py b/python/cudf_polars/cudf_polars/dsl/ir.py index 46241ab8e71..9fb2468e4e9 100644 --- a/python/cudf_polars/cudf_polars/dsl/ir.py +++ b/python/cudf_polars/cudf_polars/dsl/ir.py @@ -165,6 +165,10 @@ class PythonScan(IR): predicate: expr.NamedExpr | None """Filter to apply to the constructed dataframe before returning it.""" + def __post_init__(self): + """Validate preconditions.""" + raise NotImplementedError("PythonScan not implemented") + @dataclasses.dataclass(slots=True) class Scan(IR): diff --git a/python/cudf_polars/tests/test_python_scan.py b/python/cudf_polars/tests/test_python_scan.py new file mode 100644 index 00000000000..c03474e3dc8 --- /dev/null +++ b/python/cudf_polars/tests/test_python_scan.py @@ -0,0 +1,20 @@ +# 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 import translate_ir + + +def test_python_scan(): + def source(with_columns, predicate, nrows): + return pl.DataFrame({"a": pl.Series([1, 2, 3], dtype=pl.Int8())}) + + q = pl.LazyFrame._scan_python_function({"a": pl.Int8}, source, pyarrow=False) + with pytest.raises(NotImplementedError): + _ = translate_ir(q._ldf.visit()) + + assert q.collect().equals(source(None, None, None))