Repository navigation
[SPARK-60146][PYTHON] Use len for MLlib vector dimensions - #59348
Draft
bearomorphism wants to merge 2 commits into
Draft
bearomorphism wants to merge 2 commits into
bearomorphism wants to merge 2 commits into
Conversation
bearomorphism
marked this pull request as ready for review
October 11, 2026 05:17
bearomorphism
marked this pull request as draft
October 11, 2026 05:29
Author
|
After taking a second look I think we need a deeper discussion on the fix. |
This branch has not been deployed
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?
Replace five
.sizeaccesses withlen()inpyspark.mllib.classification, covering coefficient dimensions, multiclass prediction, and streaming initial weights. This removes four redundanttype: ignore[attr-defined]comments.The
Vectorbase class and concrete implementations remain unchanged. Suppressions for undeclared methods such asdot()are outside this PR's scope.Why are the changes needed?
Vectoralready declares__len__(), and existing dot-product and squared-distance dimension checks rely on it. Both built-in vector implementations return their logical dimension fromlen(), including trailing zeros in sparse vectors.Using this existing interface avoids relying on an undeclared
.sizeattribute or adding.sizeas a new requirement for allVectorsubclasses.Does this PR introduce any user-facing change?
No behavior change for the built-in
DenseVectorandSparseVectorimplementations. Custom subclasses used by these classification paths must implement the existingVector.__len__()interface; providing only.sizeis no longer sufficient for these dimension accesses.How was this patch tested?
Passed:
Temporary Python checks passed 38 scenarios both before and after the revision, covering dense/sparse weights and features, multiclass prediction with and without bias, trailing zeros, and streaming initialization with empty, all-zero, and nonzero weights.
No permanent tests were added for this cleanup. No JVM-backed test suites were run.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Pi 1.1.0