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

   ### What changes were proposed in this pull request?
   
   This is a follow-up of #706 (SPARK-61721). It needs #744 (SPARK-61752) and 
should merge after it.
   
   This PR's branch carries #744's commit under its own two; only the last two 
commits are this change.
   
   PySpark's `OneVsRest` takes any classifier. Its `_fit` calls 
`classifier.fit(trainingDataset, paramMap)` once per class, on the binary label 
`mc2b$<index>`, and returns `OneVsRestModel(models=...)` of those models. The 
native `OneVsRest` took only the native classification estimators. With any 
other classifier, such as PySpark's own 
`pyspark.ml.classification.LogisticRegression` or a Python subclass of it, the 
fit raised `TypeError: classifier must be a native classification estimator 
from pyspark.ml.connect.classification`. Since #744, the constructor, setters 
and getters are PySpark's own code and take any classifier, as PySpark does, so 
only the fit was left.
   
   Now the native fit handles only what it implements, a native classifier on a 
Spark DataFrame. Any other fit goes to PySpark's own `OneVsRest._fit`, over 
this object's params:
   
   - a classifier that is not a native one: the model is PySpark's 
`OneVsRestModel` of the classifier's own models, as on PySpark;
   - a None classifier: it now warns of a `weightCol` and persists the dataset 
before it fails at the classifier's first use, as PySpark's does, where it 
failed before either;
   - a dataset that is not a Spark DataFrame, such as a pandas DataFrame: it 
raises the `KeyError` of PySpark's pandas aggregate of its max label, where it 
raised the drop-in's own `TypeError` (and `OneVsRest()` raises the `KeyError` 
of its unset classifier first, as PySpark's does).
   
   `docs/compatibility.md`'s OneVsRest section describes it, and drops the 
difference of `setClassifier` and the `classifier` keyword, which #744 removed.
   
   ### Why are the changes needed?
   
   To match PySpark 4.3.0, whose `OneVsRest` fits any classifier.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A native `OneVsRest` of a classifier that is not native now fits as in 
PySpark, where it raised the `TypeError` above. Its fit of a pandas DataFrame 
raises PySpark's `KeyError` instead of the drop-in's `TypeError`, and its fit 
of a None classifier warns of a `weightCol` and persists the dataset before it 
fails, as PySpark's does.
   
   ### How was this patch tested?
   
   - New live cases in `python/tests/_misc_api_cases.py` 
(`_one_vs_rest_plain_classifier_cases`), compared with official PySpark 4.3.0:
     - the fit with PySpark's `LogisticRegression`: the model's class, uid, 
params and classifier, its models (classes, label columns, params, summaries) 
and its transform;
     - the fits of a param map, of a list of maps, and of a map of the 
classifier's own param;
     - a Python subclass of the `LogisticRegression`;
     - the `weightCol`, which the `LogisticRegression` takes and the perceptron 
warns of;
     - an object that is no classifier, and None;
     - the saves and loads of the estimator and of the model.
   
     Their golden in `tests/golden/misc_api_cases.json` is captured on official 
PySpark 4.3.0, twice, and the two captures are byte-identical. It adds 31 keys 
and changes none. On #744 without this change, the fit raises the `TypeError`, 
and `test_misc_api_e2e.py`'s OneVsRest case fails.
   - `test_ml_offline.py`:
     - a new test pins the fit of a pandas DataFrame to the error of PySpark's 
own expression, for each of its pandas inputs;
     - the pandas cases of OneVsRest now expect PySpark's `KeyError`s.
   - `test_misc_api_e2e.py`, `test_ml_classification_classes_e2e.py`, 
`test_remaining_classifiers_e2e.py` and `test_ml_e2e.py` pass live (110 
passed). `test_misc_api_offline.py`, `test_ml_offline.py`, 
`test_ml_subclasses_offline.py` and `test_ml_api_offline.py` pass offline (1233 
passed).
   - A probe of the same calls on both clients gives the same output, with two 
exceptions, both by design: the module of the native `OneVsRest` class itself, 
and that of the classifier its load reads back 
(`pyspark.ml.connect.classification`).
   - `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