Repository navigation
[SPARK-62488][CONNECT][PYTHON] Delegate standard KMeans operations to Rust - #1000
Closed
zhengruifeng wants to merge 1 commit into
Closed
zhengruifeng wants to merge 1 commit into
zhengruifeng wants to merge 1 commit into
Conversation
… Rust Co-authored-by: Isaac <no-reply@databricks.com>
zhengruifeng
added a commit
that referenced
this pull request
Dec 1, 2026
…ations to Rust ### What changes were proposed in this pull request? Delegate `pyspark.ml.clustering.BisectingKMeans` fit, transform, prediction, cost, training summaries and persistence to the existing Rust implementation. Python keeps its setters, parameter maps, copying and subclass hooks. Changes to estimator and model parameters reach Rust as soon as the setter returns. The standard and compatibility imports share the estimator, model and summary classes. The native `computeCost` method uses the original PySpark warning location so filters for `pyspark.ml.clustering` and the warn-once behavior still work. ### Why are the changes needed? The standard Python estimator previously built its own ML requests. This lets Spark’s existing BisectingKMeans tests exercise the same implementation as Rust callers and continues the clustering migration started with KMeans. [SPARK-62493](https://issues.apache.org/jira/browse/SPARK-62493) · [KMeans PR #1000](#1000) ### Does this PR introduce _any_ user-facing change? The three compatibility classes now report `pyspark.ml.clustering` as their public module. The standard signatures and persistence format match PySpark 4.3.0. ### How was this patch tested? - Ran Spark 4.3.0’s official clustering, cache, pipeline and tuning suites against the Rust-backed package and a live Spark Connect server. All eight clustering tests passed. The four suites had 25 passes and four upstream pipeline skips. - Extended the weighted clustering test with Python ML request builders disabled. With four clusters requested and a minimum divisible cluster size of 75%, it verifies two fitted centers, summary sizes of `[2, 2, 0, 0]`, weighted training cost of `15.0` and `computeCost` of `12.5`. It also exercises prediction, save/load and a lazy transform after releasing the loaded model. - Verified both clients could load one another’s saved estimator and model and produce identical predictions, with optional Python transport dependencies blocked in the Rust-backed process. Compared public member signatures and kinds for the estimator, model and summary against official PySpark. - Ran the standard ML and native binding offline suites, mypy and Pyright stub tests, Rust library and live BisectingKMeans tests, release integration-test compilation with and without `wasm-udf`, Clippy, rustfmt, Ruff, and the vendoring, generated stub and binary license checks. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-6) This pull request and its description were written by Isaac. Closes #1001 from zhengruifeng/feature/standard-bisecting-kmeans-rust. Authored-by: Ruifeng Zheng <ruifengz@apache.org> Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
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?
Route
pyspark.ml.clustering.KMeans.fit, model transformation and prediction, training summary access, and estimator/model persistence through the existing Rust KMeans implementation. Python keeps its parameter setters, copying, and subclass hooks. Setter calls update the native parameter state immediately.The standard and compatibility imports share
KMeans,KMeansModel, andKMeansSummary. The clustering adapter loads the Spark 4.3.0 source fromml/_upstream/clustering.py. The vendor check verifies that copy against the Spark tag.Why are the changes needed?
The standard Python estimator previously assembled ML requests in Python, so running Spark’s upstream KMeans tests against this package did not exercise the Rust KMeans implementation. This extends the standard ML delegation used for classification and regression to the first clustering estimator. SPARK-62488
Does this PR introduce any user-facing change?
The three compatibility imports now identify their public module as
pyspark.ml.clustering. Their standard Python signatures, fitted results and persisted formats match PySpark 4.3.0.How was this patch tested?
wasm-udf, Clippy, rustfmt, Ruff, and the vendor, generated stub and binary license checks.Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-6)
This pull request and its description were written by Isaac.