Skip to content

[SPARK-58445][PS] Fix NumPy isfinite and isinf mappings - #57586

Closed
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:pandas-numpy-finite-ufuncs
Closed

[SPARK-58445][PS] Fix NumPy isfinite and isinf mappings#57586
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:pandas-numpy-finite-ufuncs

Conversation

@zhengruifeng

@zhengruifeng zhengruifeng commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Correct the pandas-on-Spark mappings for NumPy isfinite and isinf. Both predicates now check positive and negative infinity, and isfinite also excludes NaN. Add pandas-on-Spark parity coverage for finite values, both infinities, signed zero, and NaN.

Why are the changes needed?

This is a longstanding pandas-on-Spark bug that has existed since pandas-on-Spark was first introduced. The existing mappings recognize only positive infinity. As a result, np.isfinite incorrectly returned true for negative infinity and NaN, while np.isinf incorrectly returned false for negative infinity.

Does this PR introduce any user-facing change?

Yes. np.isfinite and np.isinf on pandas-on-Spark objects now return NumPy-compatible results for negative infinity and NaN.

How was this patch tested?

  • Added pandas-on-Spark parity coverage for finite values, infinities, signed zero, and NaN.
  • Ran build/sbt -java-home /usr/lib/jvm/java-17-openjdk-amd64 -Phive package.
  • Ran JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 SPARK_TESTING=1 SPARK_PREPEND_CLASSES=1 PYSPARK_PYTHON=.venv/bin/python PYSPARK_DRIVER_PYTHON=.venv/bin/python python/run-tests --testnames pyspark.pandas.tests.test_numpy_compat.
  • Ran git diff --check.

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

Generated-by: Codex (GPT-5)

@zhengruifeng
zhengruifeng force-pushed the pandas-numpy-finite-ufuncs branch from 3f5c91a to fb84164 Compare July 30, 2026 08:40
@zhengruifeng zhengruifeng changed the title [WIP][PS] Fix NumPy isfinite and isinf mappings [SPARK-58445][PS] Fix NumPy isfinite and isinf mappings Jul 30, 2026
@zhengruifeng
zhengruifeng marked this pull request as ready for review July 30, 2026 10:15
@zhengruifeng
zhengruifeng requested a review from HyukjinKwon July 30, 2026 10:18
@uros-b

uros-b commented Jul 30, 2026

Copy link
Copy Markdown
Member

Thank you @zhengruifeng!

zhengruifeng added a commit that referenced this pull request Jul 31, 2026
### What changes were proposed in this pull request?

Correct the pandas-on-Spark mappings for NumPy `isfinite` and `isinf`. Both predicates now check positive and negative infinity, and `isfinite` also excludes `NaN`. Add pandas-on-Spark parity coverage for finite values, both infinities, signed zero, and `NaN`.

### Why are the changes needed?

This is a longstanding pandas-on-Spark bug that has existed since pandas-on-Spark was first introduced. The existing mappings recognize only positive infinity. As a result, `np.isfinite` incorrectly returned true for negative infinity and `NaN`, while `np.isinf` incorrectly returned false for negative infinity.

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

Yes. `np.isfinite` and `np.isinf` on pandas-on-Spark objects now return NumPy-compatible results for negative infinity and `NaN`.

### How was this patch tested?

- Added pandas-on-Spark parity coverage for finite values, infinities, signed zero, and `NaN`.
- Ran `build/sbt -java-home /usr/lib/jvm/java-17-openjdk-amd64 -Phive package`.
- Ran `JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 SPARK_TESTING=1 SPARK_PREPEND_CLASSES=1 PYSPARK_PYTHON=.venv/bin/python PYSPARK_DRIVER_PYTHON=.venv/bin/python python/run-tests --testnames pyspark.pandas.tests.test_numpy_compat`.
- Ran `git diff --check`.

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

Generated-by: Codex (GPT-5)

Closes #57586 from zhengruifeng/pandas-numpy-finite-ufuncs.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
(cherry picked from commit 24d7b0c)
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
@zhengruifeng

Copy link
Copy Markdown
Contributor Author

Merge Summary:

Posted by merge_spark_pr.py

@zhengruifeng
zhengruifeng deleted the pandas-numpy-finite-ufuncs branch July 31, 2026 01:00
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