Skip to content

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

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

[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

zhengruifeng added a commit that referenced this pull request Aug 5, 2026
### 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

Closes #57758 from zhengruifeng/pandas-native-fmax-fmin-dev2.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
(cherry picked from commit 1762c91)
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
@zhengruifeng

Copy link
Copy Markdown
Contributor Author

Merge Summary:

Posted by merge_spark_pr.py

@zhengruifeng
zhengruifeng deleted the pandas-native-fmax-fmin-dev2 branch August 5, 2026 01:54
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