Skip to content

Commit e6b72ed

Browse files
committed
Final bits
1 parent 45cc01e commit e6b72ed

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

python/cudf_polars/cudf_polars/dsl/utils/rolling.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,14 @@ def rewrite_rolling(
7676
if plc.traits.is_integral(index_dtype) and index_dtype.id() != plc.TypeId.INT64:
7777
index_dtype = plc.DataType(plc.TypeId.INT64)
7878
index = expr.NamedExpr(index_name, index_col)
79-
if len(aggs) == 0:
80-
inp = ir.Select(schema, [*keys, index], True, inp) # noqa: FBT003
81-
if options.slice is not None:
82-
offset, length = options.slice
83-
return ir.Slice(schema, offset, length, inp)
84-
return inp
8579
temp_prefix = "_" * max(map(len, schema))
86-
aggs, rolling_schema, apply_post_evaluation = apply_pre_evaluation(
87-
schema, keys, aggs, unique_names(temp_prefix), index
88-
)
80+
if len(aggs) > 0:
81+
aggs, rolling_schema, apply_post_evaluation = apply_pre_evaluation(
82+
schema, keys, aggs, unique_names(temp_prefix), index
83+
)
84+
else:
85+
rolling_schema = schema
86+
apply_post_evaluation = lambda inp: inp # noqa: E731
8987
preceding, following = offsets_to_windows(
9088
index_dtype, options.rolling.offset, options.rolling.period
9189
)

python/cudf_polars/cudf_polars/dsl/utils/windows.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import pyarrow as pa
1111

12+
import polars as pl
13+
1214
import pylibcudf as plc
1315

1416
if TYPE_CHECKING:
@@ -68,6 +70,8 @@ def duration_to_int(
6870
raise NotImplementedError(
6971
"Invalid duration for parsed_int"
7072
) # pragma: no cover; polars raises first
73+
elif not parsed_int and dtype.id() == plc.TypeId.INT64:
74+
raise pl.exceptions.InvalidOperationError("Duration must be a parsed integer")
7175
value = nanoseconds + 24 * 60 * 60 * 10**9 * (days + 7 * weeks)
7276
return -value if negative else value
7377

python/cudf_polars/cudf_polars/testing/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def pytest_configure(config: pytest.Config) -> None:
176176
"tests/unit/operations/test_group_by.py::test_group_by_binary_agg_with_literal": "Incorrect broadcasting of literals in groupby-agg",
177177
"tests/unit/operations/test_group_by.py::test_group_by_lit_series": "Incorrect broadcasting of literals in groupby-agg",
178178
"tests/unit/operations/test_join.py::test_cross_join_slice_pushdown": "Need to implement slice pushdown for cross joins",
179+
"tests/unit/operations/test_rolling.py::test_rolling_group_by_empty_groups_by_take_6330": "Ordering difference, might be polars bug",
179180
"tests/unit/sql/test_cast.py::test_cast_errors[values0-values::uint8-conversion from `f64` to `u64` failed]": "Casting that raises not supported on GPU",
180181
"tests/unit/sql/test_cast.py::test_cast_errors[values1-values::uint4-conversion from `i64` to `u32` failed]": "Casting that raises not supported on GPU",
181182
"tests/unit/sql/test_cast.py::test_cast_errors[values2-values::int1-conversion from `i64` to `i8` failed]": "Casting that raises not supported on GPU",

python/cudf_polars/tests/expressions/test_rolling.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ def test_orderby_nulls_raises_computeerror():
104104
q.collect(engine=pl.GPUEngine(raise_on_fail=True))
105105

106106

107+
def test_invalid_duration_spec_raises_in_translation():
108+
df = pl.LazyFrame({"orderby": [1, 2, 4, 5], "values": [1, 2, 3, 4]})
109+
q = df.select(pl.col("values").sum().rolling("orderby", period="3d"))
110+
assert_ir_translation_raises(q, pl.exceptions.InvalidOperationError)
111+
112+
107113
def test_grouped_rolling():
108114
df = pl.LazyFrame({"a": [1, 2, 3, 4, 5, 6], "b": [1, 2, 1, 3, 1, 2]})
109115

0 commit comments

Comments
 (0)