Skip to content

[SPARK-58553][PS][FOLLOWUP] Do not cast NumPy fmax/fmin results to double - #58366

Closed
Spenserrrr wants to merge 1 commit into
apache:masterfrom
Spenserrrr:numpy-trunc-fmax-fmin-precision
Closed

[SPARK-58553][PS][FOLLOWUP] Do not cast NumPy fmax/fmin results to double#58366
Spenserrrr wants to merge 1 commit into
apache:masterfrom
Spenserrrr:numpy-trunc-fmax-fmin-precision

Conversation

@Spenserrrr

@Spenserrrr Spenserrrr commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

_fmax_func and _fmin_func no longer cast their result to double. Every branch of both expressions returns one of the operands, so the result now keeps the operands' type instead of being widened.

Why are the changes needed?

The cast rounds integral values above 2^53 and returns a dtype NumPy does not use:

np.fmax(psdf.x1, psdf.x2)  # 9007199254740992.0, float64
np.fmax(pdf.x1, pdf.x2)    # 9007199254740993,   int64

Does this PR introduce any user-facing change?

Yes. np.fmax / np.fmin on a non-double column now return the operands' type rather than double, and integral values above 2^53 are exact. Floating-point results, including the signed-zero tie, are unchanged.

How was this patch tested?

Two new tests in test_numpy_compat.py, inherited by the Spark Connect parity suite; both fail without the change. Neither is gated by _skip_if_numpy_differs, since nothing they compare varies by platform or NumPy version (checked on the minimum dependencies and on pandas 3).

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

Generated-by: Claude Code (Claude Opus 5)

…uble

Every branch of _fmax_func and _fmin_func returns one of the operands, so
the trailing cast only widened an already exact answer: an integral column
above 2^53 lost precision and the output dtype did not match NumPy's.
@Spenserrrr
Spenserrrr marked this pull request as ready for review August 28, 2026 00:04
@Spenserrrr

Copy link
Copy Markdown
Contributor Author

Hi @zhengruifeng, this is a follow-up of the integer-precision fixes, similar to fmod (#58319) and floor_divide (#58306). Could you take a look when you have time? Thanks!

zhengruifeng pushed a commit that referenced this pull request Aug 28, 2026
…uble

### What changes were proposed in this pull request?

`_fmax_func` and `_fmin_func` no longer cast their result to double. Every branch of both expressions returns one of the operands, so the result now keeps the operands' type instead of being widened.

### Why are the changes needed?

The cast rounds integral values above 2^53 and returns a dtype NumPy does not use:

```python
np.fmax(psdf.x1, psdf.x2)  # 9007199254740992.0, float64
np.fmax(pdf.x1, pdf.x2)    # 9007199254740993,   int64
```

### Does this PR introduce _any_ user-facing change?

Yes. `np.fmax` / `np.fmin` on a non-double column now return the operands' type rather than double, and integral values above 2^53 are exact. Floating-point results, including the signed-zero tie, are unchanged.

### How was this patch tested?

Two new tests in `test_numpy_compat.py`, inherited by the Spark Connect parity suite; both fail without the change. Neither is gated by `_skip_if_numpy_differs`, since nothing they compare varies by platform or NumPy version (checked on the minimum dependencies and on pandas 3).

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

Generated-by: Claude Code (Claude Opus 5)

Closes #58366 from Spenserrrr/numpy-trunc-fmax-fmin-precision.

Authored-by: Spenser Sun <hsun112358@gmail.com>
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
(cherry picked from commit 77a4781)
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
@zhengruifeng

Copy link
Copy Markdown
Contributor

Merge Summary:

Posted by merge_spark_pr.py

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