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

   ### What changes were proposed in this pull request?
   
   The native ML classes of the Python client now take PySpark's `setParams` 
and the `params` argument of `fit`, `transform` and `evaluate`. A post-merge 
review found the gap: `GBTRegressor().setParams(maxIter=3)` raised 
`AttributeError`, and `NaiveBayes().fit(df, None)` raised `TypeError: ... takes 
1 positional arguments but 2 were given`. PySpark 4.3.0 accepts both.
   
   1. **`setParams`** exists where PySpark's class has one: on the 18 classes 
that PySpark has in `pyspark.ml` (LinearSVC, FMClassifier, 
MultilayerPerceptronClassifier, OneVsRest, NaiveBayes, the trees, the GBTs and 
the forests, LinearRegression, GeneralizedLinearRegression, KMeans, 
GaussianMixture, BisectingKMeans, StringIndexer and VectorAssembler), and on 
the `Pipeline` and `CrossValidator` of `pyspark.ml.connect`. 
`LogisticRegression` and the evaluators of `pyspark.ml.connect` have none, as 
in PySpark.
      - It is keyword-only, as PySpark's `@keyword_only`. It sets only the 
params that it is given, in order, and returns the object, as `_set` does.
      - It converts values with the constructor's conversions and raises its 
errors. One shared implementation binds the arguments of `__init__` and 
`setParams`.
      - Its signature is PySpark's, names, kinds and defaults, checked against 
the reference client with `inspect.signature`, with three exceptions. 
`StringIndexer`, `VectorAssembler` and `CrossValidator` take only the params 
that their constructors take.
   2. **`fit(dataset, params=None)`, `transform(dataset, params=None)` and 
`evaluate(dataset, params=None)`** on 25 methods, the models' `transform` 
included.
      - `None` and an empty dict leave the params as they are.
      - A non-empty param map raises a `TypeError` that says that the native 
classes take no param map. PySpark keys a map by Param objects, and the native 
classes have none. The same goes for a list or tuple of maps given to the fit 
of a `pyspark.ml` class, which PySpark fits one model per map of.
      - Any other value raises PySpark's `TypeError` for it: `Params must be 
either a param map or a list/tuple of param maps, but got <class 'str'>.` for a 
fit, and `Params must be a param map but got ...` for a transform or an 
evaluate. A transformer of `pyspark.ml.connect` returns `None` for such a value 
in PySpark. The native classes raise the same `TypeError` as the others instead.
   3. `docs/compatibility.md` documents both in its native ML section.
   
   The tests also add GaussianMixture and GeneralizedLinearRegression to the 
setter check of `test_ml_offline.py`, which missed them.
   
   ### Why are the changes needed?
   
   For parity with PySpark 4.3.0: code that sets params with `setParams`, or 
passes `params` through to `fit`, fails on the native classes.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `setParams` and the `params` argument above work where they raised 
`AttributeError` and `TypeError`.
   
   ### How was this patch tested?
   
   - New offline tests in `python/tests/test_ml_offline.py`. Each fails before 
the change and passes after:
     - `setParams` of every class: its signature, the params that it sends, its 
return value and its errors;
     - OneVsRest's `setParams`, which sets its classifier as its constructor 
does;
     - the `params` argument of `fit`, `transform` and `evaluate`, with `None`, 
`{}`, a non-empty dict, a list and a str.
   - A new live test in `python/tests/test_ml_e2e.py`: `setParams`, then `fit`, 
gives the predictions of the model of the same constructor params, for 
LinearSVC and KMeans.
   - Results: `tests/test_ml_offline.py` 148 passed; 
`tests/test_dropin_offline.py` 1967 passed, 8 skipped; `tests/test_ml_e2e.py` 
against a Spark 4.3.0 Connect server 30 passed. `cargo fmt --check`, 
`scripts/audit_no_stubs.sh` and `ruff check` pass.
   
   ### 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