[SPARK-58249][PS][FOLLOWUP] Use native function for NumPy invert - #57562
Closed
zhengruifeng wants to merge 1 commit into
Closed
[SPARK-58249][PS][FOLLOWUP] Use native function for NumPy invert#57562zhengruifeng wants to merge 1 commit into
zhengruifeng wants to merge 1 commit into
Conversation
uros-b
approved these changes
Jul 27, 2026
Member
|
Thank you @zhengruifeng! |
zhengruifeng
added a commit
that referenced
this pull request
Jul 28, 2026
### What changes were proposed in this pull request? Replace the scalar pandas UDF mapping for NumPy `invert` on pandas-on-Spark objects with the native Spark SQL `bitwise_not` function. Add the `int64` boundary-value coverage to the existing native NumPy ufunc parity test. ### Why are the changes needed? Spark already provides a native, Spark Connect-compatible bitwise-not function. Using it removes the Python worker boundary and preserves NumPy integer results. ### Does this PR introduce _any_ user-facing change? Yes. `np.invert` now preserves its integral result type, matching NumPy, instead of using the scalar pandas UDF mapping declared with a double result type. ### How was this patch tested? - Added pandas-on-Spark parity coverage for `np.invert` using `int64` boundary values. - 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 #57562 from zhengruifeng/pandas-native-invert-ufunc. Authored-by: Ruifeng Zheng <ruifengz@apache.org> Signed-off-by: Ruifeng Zheng <ruifengz@apache.org> (cherry picked from commit f1a7058) 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?
Replace the scalar pandas UDF mapping for NumPy
inverton pandas-on-Spark objects with the native Spark SQLbitwise_notfunction. Add theint64boundary-value coverage to the existing native NumPy ufunc parity test.Why are the changes needed?
Spark already provides a native, Spark Connect-compatible bitwise-not function. Using it removes the Python worker boundary and preserves NumPy integer results.
Does this PR introduce any user-facing change?
Yes.
np.invertnow preserves its integral result type, matching NumPy, instead of using the scalar pandas UDF mapping declared with a double result type.How was this patch tested?
np.invertusingint64boundary values.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)