Skip to content

[SPARK-58249][PS][FOLLOWUP] Use native function for NumPy invert - #57562

Closed
zhengruifeng wants to merge 1 commit into
apache:masterfrom
zhengruifeng:pandas-native-invert-ufunc
Closed

[SPARK-58249][PS][FOLLOWUP] Use native function for NumPy invert#57562
zhengruifeng wants to merge 1 commit into
apache:masterfrom
zhengruifeng:pandas-native-invert-ufunc

Conversation

@zhengruifeng

Copy link
Copy Markdown
Contributor

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)

@uros-b

uros-b commented Jul 27, 2026

Copy link
Copy Markdown
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>
@zhengruifeng

Copy link
Copy Markdown
Contributor Author

Merge Summary:

Posted by merge_spark_pr.py

@zhengruifeng
zhengruifeng deleted the pandas-native-invert-ufunc branch July 28, 2026 00:35
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