Skip to content

[SPARK-58514][PS] Restore native NumPy log2 mapping - #57717

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

[SPARK-58514][PS] Restore native NumPy log2 mapping#57717
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:pandas-native-log2-dev2

Conversation

@zhengruifeng

@zhengruifeng zhengruifeng commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Restore the pandas-on-Spark np.log2 mapping using the native Spark SQL log2 function. Preserve NumPy behavior for 0.0 and -0.0, for which NumPy returns -inf while Spark SQL returns null. Add end-to-end coverage for negative, zero, finite, infinite, and NaN inputs.

Why are the changes needed?

SPARK-58249 unintentionally removed the existing np.log2 mapping while replacing other NumPy mappings with native Spark SQL expressions. Spark already provides an equivalent native function, with an explicit zero branch needed to match NumPy semantics.

Does this PR introduce any user-facing change?

Yes. np.log2 on pandas-on-Spark objects is dispatched to Spark SQL again instead of being unsupported by the NumPy compatibility mapping.

How was this patch tested?

Added end-to-end pandas-on-Spark coverage for np.log2 edge cases.

Ran:

  • python/run-tests --testnames pyspark.pandas.tests.test_numpy_compat
  • python/run-tests --testnames pyspark.pandas.tests.connect.test_parity_numpy_compat
  • Ruff check and format check
  • git diff --check, source ASCII, and line-length checks

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

Generated-by: Codex (GPT-5)

@uros-b

uros-b commented Aug 3, 2026

Copy link
Copy Markdown
Member

LGTM, thank you @zhengruifeng!

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

Restore the pandas-on-Spark `np.log2` mapping using the native Spark SQL `log2` function. Preserve NumPy behavior for `0.0` and `-0.0`, for which NumPy returns `-inf` while Spark SQL returns null. Add end-to-end coverage for negative, zero, finite, infinite, and NaN inputs.

### Why are the changes needed?

SPARK-58249 unintentionally removed the existing `np.log2` mapping while replacing other NumPy mappings with native Spark SQL expressions. Spark already provides an equivalent native function, with an explicit zero branch needed to match NumPy semantics.

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

Yes. `np.log2` on pandas-on-Spark objects is dispatched to Spark SQL again instead of being unsupported by the NumPy compatibility mapping.

### How was this patch tested?

Added end-to-end pandas-on-Spark coverage for `np.log2` edge cases.

Ran:

- `python/run-tests --testnames pyspark.pandas.tests.test_numpy_compat`
- `python/run-tests --testnames pyspark.pandas.tests.connect.test_parity_numpy_compat`
- Ruff check and format check
- `git diff --check`, source ASCII, and line-length checks

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

Generated-by: Codex (GPT-5)

Closes #57717 from zhengruifeng/pandas-native-log2-dev2.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
(cherry picked from commit 3e2bb12)
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-log2-dev2 branch August 4, 2026 03:15
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