[SPARK-59173][ML] Use isEmpty/nonEmpty instead of size comparisons in MLlib - #58471
Open
uros-b wants to merge 2 commits into
Open
[SPARK-59173][ML] Use isEmpty/nonEmpty instead of size comparisons in MLlib#58471uros-b wants to merge 2 commits into
uros-b wants to merge 2 commits into
Conversation
Member
Author
|
cc @dongjoon-hyun @HyukjinKwon here, regarding #58449. |
Member
Author
|
added @HyukjinKwon for ML |
dongjoon-hyun
approved these changes
Sep 2, 2026
HyukjinKwon
approved these changes
Sep 2, 2026
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?
This replaces size-vs-zero comparisons with the direct emptiness / non-emptiness predicates in the
mllibmodule:x.size == 0->x.isEmpty):TreeEnsembleModel.totalImportances(anOpenHashMap, whichextends Iterable) and twoSeq[ShuffleDependency]checks inALSSuite.x.size > 0->x.nonEmpty):DecisionTreeMetadata.featureArityandStrategy.categoricalFeaturesInfo, both ScalaMap[Int, Int].There are no Java-collection cases in this module.
Deliberately left unchanged, because they are not collection-emptiness checks -- they are
mllib.linalg.Vectordimensions or numeric sizes/thresholds, andVectorhas noisEmpty/nonEmpty:ChiSqTest(expected/observedareVectordimensions, compared with!= 0and== 0.0);BinaryClassificationPMMLModelExportandGeneralizedLinearPMMLModelExport(model.weights, aVector);MultivariateOnlineSummarizer(instance, aVector-- the message reads "Vector should have dimension larger than zero");BlockMatrix(a matrix rowVector);ALS(RatingBlockBuilder.size, a custom builder with nononEmpty);SpearmanCorrelation(cachedUids.size >= 10000000, a size threshold, not an emptiness check).Why are the changes needed?
isEmpty/nonEmptystate the intent directly. Behavior is unchanged: every converted receiver (OpenHashMap,Seq, ScalaMap) defines the predicate as exactly equivalent to the original comparison.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing tests. This is a behavior-preserving refactor; the
mllibmodule compiles cleanly. Counterpart of SPARK-59149 (SQL) and SPARK-59172 (core).Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)