Skip to content

Commit 73b052d

Browse files
timsaucerclaude
andcommitted
fix: leave lead and lag null_treatment unset by default
Defaulting to NullTreatment.RESPECT_NULLS passed Some(RespectNulls) to Rust, which adds "RESPECT NULLS" to the generated column name and breaks code that refers to an un-aliased lead/lag output by name. Default to None instead; respecting nulls is already the behavior when unset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6345b17 commit 73b052d

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎python/datafusion/functions/__init__.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7000,7 +7000,7 @@ def lead(
70007000
default_value: Any | None = None,
70017001
partition_by: list[Expr] | Expr | None = None,
70027002
order_by: list[SortKey] | SortKey | None = None,
7003-
null_treatment: NullTreatment = NullTreatment.RESPECT_NULLS,
7003+
null_treatment: NullTreatment | None = None,
70047004
) -> Expr:
70057005
"""Create a lead window function.
70067006
@@ -7079,7 +7079,9 @@ def lead(
70797079
default_value,
70807080
partition_by=partition_by_raw,
70817081
order_by=order_by_raw,
7082-
null_treatment=null_treatment.value,
7082+
null_treatment=(
7083+
null_treatment.value if null_treatment is not None else None
7084+
),
70837085
)
70847086
)
70857087

@@ -7090,7 +7092,7 @@ def lag(
70907092
default_value: Any | None = None,
70917093
partition_by: list[Expr] | Expr | None = None,
70927094
order_by: list[SortKey] | SortKey | None = None,
7093-
null_treatment: NullTreatment = NullTreatment.RESPECT_NULLS,
7095+
null_treatment: NullTreatment | None = None,
70947096
) -> Expr:
70957097
"""Create a lag window function.
70967098
@@ -7166,7 +7168,9 @@ def lag(
71667168
default_value,
71677169
partition_by=partition_by_raw,
71687170
order_by=order_by_raw,
7169-
null_treatment=null_treatment.value,
7171+
null_treatment=(
7172+
null_treatment.value if null_treatment is not None else None
7173+
),
71707174
)
71717175
)
71727176

‎python/tests/test_dataframe.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,14 @@ def test_window_partition_by_accepts_string(partitioned_df, partition):
11861186
assert table.column("fv").to_pylist() == [1, 1, 1, 1, 5, 5, 5]
11871187

11881188

1189+
@pytest.mark.parametrize("func", [f.lead, f.lag])
1190+
def test_lead_lag_default_null_treatment_keeps_column_name(partitioned_df, func):
1191+
"""Omitting null_treatment must not add RESPECT NULLS to the output name."""
1192+
df = partitioned_df.select(func(column("b"), order_by=column("a")))
1193+
name = df.schema().names[0]
1194+
assert "RESPECT NULLS" not in name
1195+
1196+
11891197
@pytest.mark.parametrize(
11901198
("units", "start_bound", "end_bound"),
11911199
[

0 commit comments

Comments
 (0)