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

   ### What changes were proposed in this pull request?
   
   [SPARK-61334](https://issues.apache.org/jira/browse/SPARK-61334): the 
setters of the native `pyspark.ml.connect` classes set the value on the object 
and return the object, as PySpark's do.
   
   - In `crates/pyspark-rs/src/ml.rs`, every setter of these classes now has 
the mutating form `fn set_x(mut slf: PyRefMut<Self>, value) -> PyRefMut<Self>`. 
That form is the one the native KMeans, LinearSVC and LinearRegression already 
use. The classes:
     - StandardScaler, MaxAbsScaler, StringIndexer, VectorAssembler
     - LogisticRegression
     - RegressionEvaluator, BinaryClassificationEvaluator, 
MulticlassClassificationEvaluator
     - Pipeline, CrossValidator
   - The argument is named `value`, as in PySpark's setters.
   
   ### Why are the changes needed?
   
   Those setters returned a new object and left the receiver unchanged. So a 
call whose result was not kept was silently ignored:
   - `ev = RegressionEvaluator(labelCol="label", predictionCol="pred"); 
ev.setMetricName("r2"); ev.evaluate(df)` returned the rmse.
   - `MulticlassClassificationEvaluator(...).setMetricName("accuracy")` gave 
the f1.
   - `BinaryClassificationEvaluator().setRawPredictionCol("score")`, then 
`evaluate`, failed with `FIELD_NOT_FOUND rawPrediction`.
   - `LogisticRegression().setLabelCol("y")`, then `fit`, failed on the column 
`label`.
   - `Pipeline().setStages([...])` kept no stages, and CrossValidator's 
`setNumFolds`/`setParallelism`/`setSeed` were ignored.
   
   PySpark's setters (`Params._set`, as in `pyspark.ml.connect`'s Pipeline and 
CrossValidator) set the value on the object and return it.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, in the Python client: these setters now change the object they are 
called on, and return it, as in PySpark.
   
   ### How was this patch tested?
   
   - Offline (`python/tests/test_ml_offline.py`): 
`test_ml_connect_setters_set_the_params_of_their_receiver_as_pyspark`.
     - It covers every setter of each of the 14 native estimators, transformers 
and evaluators.
     - Each setter returns its receiver (called with the keyword `value`).
     - The next evaluate, fit or transform sends the new value, the same as an 
object built with the value in its constructor. It also checks that no setter 
of a class is left out.
     - It fails without the change.
   - Live (`python/tests/test_ml_e2e.py`): 
`test_ml_connect_setters_change_the_next_evaluate_and_fit_as_pyspark`.
   - A probe against official PySpark 4.3.0: `setMetricName`, 
`setRawPredictionCol`, `setLabelCol`, `setStages` and the CrossValidator 
setters now give official's results.
   - Checks: `test_ml_offline.py` 98 passed, `test_ml_e2e.py` 15 passed; the 
lib tests, the build of all tests (also `wasm-udf`, `datafusion,polars`) 
without warnings, `cargo fmt --all --check`, and clippy with no diagnostics on 
the changed lines.
   
   ### 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