Skip to content

[SPARK-58533][PS] Use native Spark function for NumPy float_power - #57734

Closed
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:pandas-native-float-power-dev2
Closed

[SPARK-58533][PS] Use native Spark function for NumPy float_power#57734
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:pandas-native-float-power-dev2

Conversation

@zhengruifeng

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR replaces the pandas UDF implementation of np.float_power in pandas API on Spark with native Spark pow, casting both operands to double. It also adds compatibility coverage for integral inputs and floating-point special values.

Why are the changes needed?

Using a native Spark expression avoids pandas UDF and Arrow overhead while preserving NumPy float_power floating-point semantics.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Added test_np_float_power, covering integral inputs, signed zero, infinities, and NaN.

  • ruff check python/pyspark/pandas/numpy_compat.py python/pyspark/pandas/tests/test_numpy_compat.py
  • ruff format --check python/pyspark/pandas/numpy_compat.py python/pyspark/pandas/tests/test_numpy_compat.py
  • python/run-tests --testnames pyspark.pandas.tests.test_numpy_compat (test_np_float_power passed; the module has two unrelated existing reciprocal pandas-UDF failures due to a local Python/JVM class-signature mismatch.)

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

Generated-by: Codex GPT-5

}
),
):
with self.subTest(base=pdf.base.tolist(), exponent=pdf.exponent.tolist()):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we want to avoid using subTest?

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

This PR replaces the pandas UDF implementation of `np.float_power` in pandas API on Spark with native Spark `pow`, casting both operands to `double`. It also adds compatibility coverage for integral inputs and floating-point special values.

### Why are the changes needed?

Using a native Spark expression avoids pandas UDF and Arrow overhead while preserving NumPy `float_power` floating-point semantics.

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

No.

### How was this patch tested?

Added `test_np_float_power`, covering integral inputs, signed zero, infinities, and NaN.

- `ruff check python/pyspark/pandas/numpy_compat.py python/pyspark/pandas/tests/test_numpy_compat.py`
- `ruff format --check python/pyspark/pandas/numpy_compat.py python/pyspark/pandas/tests/test_numpy_compat.py`
- `python/run-tests --testnames pyspark.pandas.tests.test_numpy_compat` (`test_np_float_power` passed; the module has two unrelated existing reciprocal pandas-UDF failures due to a local Python/JVM class-signature mismatch.)

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

Generated-by: Codex GPT-5

Closes #57734 from zhengruifeng/pandas-native-float-power-dev2.

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

Copy link
Copy Markdown
Contributor Author

Merge Summary:

Posted by merge_spark_pr.py

@zhengruifeng
zhengruifeng deleted the pandas-native-float-power-dev2 branch August 4, 2026 09:31
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.

3 participants