[SPARK-58445][PS] Fix NumPy isfinite and isinf mappings - #57586
Closed
zhengruifeng wants to merge 2 commits into
Closed
[SPARK-58445][PS] Fix NumPy isfinite and isinf mappings#57586zhengruifeng wants to merge 2 commits into
zhengruifeng wants to merge 2 commits into
Conversation
zhengruifeng
force-pushed
the
pandas-numpy-finite-ufuncs
branch
from
July 30, 2026 08:40
3f5c91a to
fb84164
Compare
zhengruifeng
marked this pull request as ready for review
July 30, 2026 10:15
uros-b
approved these changes
Jul 30, 2026
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>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Correct the pandas-on-Spark mappings for NumPy
isfiniteandisinf. Both predicates now check positive and negative infinity, andisfinitealso excludesNaN. Add pandas-on-Spark parity coverage for finite values, both infinities, signed zero, andNaN.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.isfiniteincorrectly returned true for negative infinity andNaN, whilenp.isinfincorrectly returned false for negative infinity.Does this PR introduce any user-facing change?
Yes.
np.isfiniteandnp.isinfon pandas-on-Spark objects now return NumPy-compatible results for negative infinity andNaN.How was this patch tested?
NaN.build/sbt -java-home /usr/lib/jvm/java-17-openjdk-amd64 -Phive package.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.git diff --check.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)