HyukjinKwon opened a new pull request, #722:
URL: https://github.com/apache/spark-connect-rust/pull/722

   ### What changes were proposed in this pull request?
   
   #718 (SPARK-61737) made the native ML classes subclasses of PySpark's 
classes. This PR tests, for the classification classes, what that provides: 
every object that the native classes make in Rust is of its public class of 
`pyspark.ml.connect.classification`, and an instance of every class of 
PySpark's MRO, as PySpark's object is of its class. It also tests that 
PySpark's meta-algorithms work over native classifiers.
   
   Writing those tests found a bug, which this PR also fixes. A copy of a 
native OneVsRestModel lost its models, so `model.copy().models` raised 
`ValueError: the models of a loaded OneVsRestModel are not held`. PySpark's 
`OneVsRestModel.copy(extra)` sets `models` to `[model.copy(extra) for model in 
self.models]`, and the native copy now does the same.
   
   - **The fix** (`crates/pyspark-rs/src/ml/classification_api/one_vs_rest.rs`):
     - `OneVsRestModel.copy(extra)` has copies of the models, each made with 
`extra`.
     - As in PySpark, a param of the classifier's uid, which the models share, 
sets the models' params. The model's own params leave the models' params 
unchanged.
   - **The class tests** (`python/tests/test_ml_classification_classes_e2e.py`, 
new, live). Each object is asserted to be of the public class and an instance 
of every class of PySpark's MRO.
     - The 8 classifiers: the estimator and its copy; the model of a fit, a fit 
of a param map, a fit of a list of maps and `fitMultiple`; the model's copy, 
with and without `extra`; the loads by `load` and `read().load`, and the copy 
of a load; the estimator's load. For the models that have them, also the 
training summary and an evaluation, of the fitted and the loaded model.
     - The multiclass summaries of LogisticRegression and 
RandomForestClassifier.
     - The trees of RandomForestClassificationModel 
(`DecisionTreeClassificationModel`) and of GBTClassificationModel (regression's 
`DecisionTreeRegressionModel`), of the model, its copy and its load.
     - OneVsRest over each of the 8 classifiers: the classifier of the 
estimator, of its copy, of its load and of the model; the models of the model, 
its copy and its load. Also the fits of param maps and `fitMultiple`.
     - CrossValidator and TrainValidationSplit over LogisticRegression, with 
`collectSubModels`: the estimator, its copy and its load, with their estimator 
and evaluator; `bestModel` and the `subModels` of the model, its copy and its 
load (`persistSubModels`).
   - **Interop**, both ways. The meta-algorithms are pyspark.ml's Pipeline, 
OneVsRest, CrossValidator and TrainValidationSplit, and this client's own.
     - Each meta-algorithm fits native classifiers. Its stages, models and 
`bestModel` are the public classes.
     - Each save loads in pyspark.ml, as PySpark's classes, which it takes from 
the class names of the metadata. It also loads in this client, as the public 
classes.
     - Every load has the uid, the submodels' uids and the predictions of the 
saved model. The estimators and their stages, classifier or estimator and 
evaluator load the same way.
   - **Copy cases** in `python/tests/_misc_api_cases.py` for OneVsRestModel: 
the copies of the models, the params of `extra`, and the copy of a loaded 
model. Their golden values in `tests/golden/misc_api_cases.json` are captured 
on official PySpark 4.3.0.
   - The new file is added to the drop-in live-server step of 
`build_python_connect.yml`.
   
   Official PySpark runs the new file too, as the reference 
(`_native_classes.native_class`).
   
   ### Why are the changes needed?
   
   #718 makes the native ML classes subclasses of every class of PySpark's MRO. 
These tests pin that for every object of the classification classes, not only 
for the classes, and for the code of pyspark.ml that dispatches on those 
classes (`MLWritable` in the meta-algorithms' saves, `HasWeightCol` and 
`HasRawPredictionCol` in OneVsRest).
   
   The copy bug broke PySpark code that copies a OneVsRestModel, such as a 
validator model's `copy` over a OneVsRest.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No, compared with a released version: the native OneVsRestModel is new in 
this release. Compared with master, a copy of a native OneVsRestModel now has 
its models, as PySpark's does. Before, its `models` raised a ValueError.
   
   ### How was this patch tested?
   
   - The new file, live against a Spark 4.3.0 Connect server: 27 passed on this 
client, with the drop-in built at this head, and 27 passed on official PySpark 
4.3.0, as the reference.
   - Without the fix: 9 tests fail: the 8 OneVsRest class tests (`ValueError: 
the models of a loaded OneVsRestModel are not held`) and `test_misc_api_e2e.py` 
on the new golden cases.
   - The misc golden is captured twice on official PySpark, and the two 
captures are byte-identical. The diff to the old golden only adds the 7 new 
cases.
   - On this client, the CI-order offline Python suite passes (5491 passed, 76 
skipped), and so do `test_misc_api_offline.py` and `test_misc_api_e2e.py`. 
`test_misc_api_e2e.py` passes on official PySpark too.
   - `cargo fmt --check`, `cargo +1.100.0 clippy --workspace --all-targets -- 
-D warnings`, `scripts/audit_no_stubs.sh`, `ruff check` and `ruff format 
--check` are clean.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to