Skip to content

Add missing conditional functions#1464

Open
timsaucer wants to merge 3 commits intoapache:mainfrom
timsaucer:add-missing-conditional-functions
Open

Add missing conditional functions#1464
timsaucer wants to merge 3 commits intoapache:mainfrom
timsaucer:add-missing-conditional-functions

Conversation

@timsaucer
Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #1449

Rationale for this change

There are a few methods missing from the Python library, so this exposes them.

What changes are included in this PR?

Exposes python functions.
Adds unit tests.

Are there any user-facing changes?

Addition only.

timsaucer and others added 3 commits March 29, 2026 19:18
…che#1449)

Expose four conditional functions from upstream DataFusion that were
not yet available in the Python bindings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests cover multiple data types (integers, strings), null handling
(all-null, partial-null), multiple arguments, and ifnull/nvl equivalence.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@timsaucer timsaucer marked this pull request as ready for review March 30, 2026 11:14
@timsaucer timsaucer requested a review from Copilot March 30, 2026 16:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Exposes missing conditional scalar functions in datafusion-python to close #1449, adding Python wrappers/bindings and unit tests.

Changes:

  • Add Python API functions: greatest, least, nvl2, and ifnull (alias for nvl).
  • Add Rust PyO3 bindings for greatest, least (variadic) and nvl2.
  • Add unit tests covering numeric/string behavior and null handling.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
python/datafusion/functions.py Adds new public Python wrappers and updates exports (__all__).
crates/core/src/functions.rs Exposes the corresponding DataFusion functions to Python via PyO3 wrappers.
python/tests/test_functions.py Adds unit tests validating the new functions’ behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

assert result.column(0).to_pylist() == ["banana", "cherry"]


def test_least(df):
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df fixture is accepted but never used in this test. Because pytest will still construct the fixture, this adds unnecessary setup cost and can slow the suite. Either remove the df parameter or refactor the test to reuse the provided fixture/context instead of creating a new SessionContext.

Suggested change
def test_least(df):
def test_least():

Copilot uses AI. Check for mistakes.
Comment on lines +1544 to +1547
def test_nvl2(df):
ctx = SessionContext()
batch = pa.RecordBatch.from_arrays(
[
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df fixture is accepted but never used in this test. Because pytest will still construct the fixture, this adds unnecessary setup cost and can slow the suite. Either remove the df parameter or refactor the test to reuse the provided fixture/context instead of creating a new SessionContext.

Copilot uses AI. Check for mistakes.
Comment on lines +1578 to +1580
def test_ifnull(df):
ctx = SessionContext()
batch = pa.RecordBatch.from_arrays(
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df fixture is accepted but never used in this test. Because pytest will still construct the fixture, this adds unnecessary setup cost and can slow the suite. Either remove the df parameter or refactor the test to reuse the provided fixture/context instead of creating a new SessionContext.

Copilot uses AI. Check for mistakes.
)


def test_greatest(df):
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df fixture is accepted but never used in this test. Because pytest will still construct the fixture, this adds unnecessary setup cost and can slow the suite. Either remove the df parameter or refactor the test to reuse the provided fixture/context instead of creating a new SessionContext.

Suggested change
def test_greatest(df):
def test_greatest():

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add missing conditional functions (greatest, least, nvl2, ifnull)

2 participants