{{ message }}
[SPARK-59516][MLLIB][PYTHON] Handle infinity norm of all-zero sparse vectors - #58788
Open
laserninja wants to merge 2 commits into
Open
laserninja wants to merge 2 commits into
laserninja wants to merge 2 commits into
Conversation
laserninja
force-pushed
the
fix/sparse-zero-norm
branch
from
September 15, 2026 01:16
0da8f75 to
0ba7c74
Compare
Author
laserninja
marked this pull request as ready for review
September 15, 2026 02:32
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?
Jira: SPARK-59516
Return zero for the infinity norm of a positive-dimensional sparse vector with no stored entries. Apply the same fix to pyspark.ml.linalg and pyspark.mllib.linalg, with tests for both APIs.
Why are the changes needed?
With NumPy before 2.3, SparseVector.norm passes its empty values array to numpy.linalg.norm, which raises on the maximum reduction. Dense vectors and sparse vectors storing an explicit zero return 0.0 for the same logical vector.
NumPy 2.3 changed empty-array infinity norms to return zero (release notes). This fix provides consistent behavior for positive-dimensional sparse zero vectors on older supported NumPy releases too.
Does this PR introduce any user-facing change?
Yes. All-zero sparse vectors return 0.0 for infinity norm. Zero-dimensional vectors and invalid norm orders retain their existing behavior.
How was this patch tested?
The new regression tests failed before the fix and passed afterward on Python 3.10.11 with NumPy 2.2.6. After correcting a NumPy-version assumption in the zero-dimensional test, all 6 focused tests pass on Python 3.10.11 / NumPy 2.2.6 and Python 3.11 / NumPy 2.3.0, including parameterized subtests. Zero-dimensional sparse vectors are checked against existing dense-vector behavior: ValueError on older NumPy, zero on NumPy 2.3. Ruff lint and formatting pass for the updated tests.
Focused test commands:
Run the commands with the Python virtual environment activated; the local run shared an environment from a sibling checkout. The tests call public Python APIs directly and require no SparkSession. Python compilation, custom-error checks, Ruff lint, and Ruff formatting passed. JVM-backed suites were not run because these fixes are confined to Python-side logic.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-6).