Skip to content

[SPARK-58548][PS] Use native Spark function for NumPy heaviside - #57749

Open
zhengruifeng wants to merge 3 commits into
apache:masterfrom
zhengruifeng:pandas-native-heaviside-dev2
Open

[SPARK-58548][PS] Use native Spark function for NumPy heaviside#57749
zhengruifeng wants to merge 3 commits into
apache:masterfrom
zhengruifeng:pandas-native-heaviside-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.heaviside in pandas API on Spark with a native Spark when expression. It returns 0.0 for negative values, the second argument at either signed zero, and 1.0 for positive values; null and NaN first arguments propagate.

The new test covers integral inputs, signed zero, NaN, infinities, and NaN as the second argument at zero.

Why are the changes needed?

Using native Spark expressions avoids pandas UDF and Arrow overhead while preserving NumPy heaviside semantics.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

  • Added NumPyCompatTests.test_np_heaviside.
  • 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 -m unittest pyspark.pandas.tests.test_numpy_compat.NumPyCompatTests.test_np_heaviside

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

Generated-by: Codex GPT-5

@uros-b

uros-b commented Aug 4, 2026

Copy link
Copy Markdown
Member

Thank you @zhengruifeng, just please resolve conflicts

@zhengruifeng
zhengruifeng force-pushed the pandas-native-heaviside-dev2 branch from 52f288e to c1aaa0c Compare August 4, 2026 13:35
@zhengruifeng
zhengruifeng force-pushed the pandas-native-heaviside-dev2 branch from 5af3a3d to df13ed2 Compare August 5, 2026 01:22
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