Skip to content

[SPARK-58553][PS] Use native Spark functions for NumPy fmax and fmin - #57758

Open
zhengruifeng wants to merge 1 commit into
apache:masterfrom
zhengruifeng:pandas-native-fmax-fmin-dev2
Open

[SPARK-58553][PS] Use native Spark functions for NumPy fmax and fmin#57758
zhengruifeng wants to merge 1 commit into
apache:masterfrom
zhengruifeng:pandas-native-fmax-fmin-dev2

Conversation

@zhengruifeng

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR replaces the pandas UDF implementations of np.fmax and np.fmin in pandas API on Spark with native Spark expressions.

fmax explicitly selects the non-NaN operand before using greatest. fmin uses least, whose NaN ordering matches NumPy fmin. Both results are cast to double, matching the existing pandas UDF return type.

Why are the changes needed?

Using native Spark expressions avoids pandas UDF and Arrow overhead while preserving NumPy NaN-handling semantics.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Added NumPyCompatTests.test_np_fmax_fmin, covering integral inputs, NaNs, infinities, and signed zero.

  • ruff check python/pyspark/pandas/numpy_compat.py python/pyspark/pandas/tests/test_numpy_compat.py
  • ruff format --check python/pyspark/pandas/numpy_compat.py python/pyspark/pandas/tests/test_numpy_compat.py
  • python -m unittest pyspark.pandas.tests.test_numpy_compat.NumPyCompatTests.test_np_fmax_fmin

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Codex GPT-5

@zhengruifeng
zhengruifeng force-pushed the pandas-native-fmax-fmin-dev2 branch from c121116 to 2e280ae Compare August 4, 2026 12:21
@uros-b

uros-b commented Aug 4, 2026

Copy link
Copy Markdown
Member

LGTM

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.

2 participants