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

   ### What changes were proposed in this pull request?
   
   The public classes of the native ML classes (`pyspark.ml.connect.*`, 
subclasses of PySpark's classes) kept their params in the native object, and 
their Params API was native code. So PySpark's own Python code over a Params 
object's param maps did not apply to them, nor to the Python code that reads 
them (a subclass's, PySpark's meta-algorithms'): `_paramMap` and 
`_defaultParamMap`, `_set`, `_setDefault`, `_copyValues`, `_resetUid`, 
`_input_kwargs`, the order of `extractParamMap()`, the conversions of the 
`TypeConverters`, the messages of a call that does not bind, and the Params of 
an old uid after an assignment of `uid`.
   
   With this change, a public class keeps its params in PySpark's param maps, 
in the object's attributes, and takes PySpark's own functions of the Params 
API, the getters and setters, `setParams` and the `keyword_only` constructors 
as they are (`_native_classes.py`: `_pysparks_own` takes a member of PySpark's 
that reads none of its server-side object, `_call_java`, `_java_obj`, 
`summary`, ...).
   - Before each native member that reads the params (a fit, a transform, an 
evaluation, a writer, a model's members), the native object's params are made 
those of the maps by name (`_native_sync`, `sync_params` of `params_api.rs`).
   - So are the params of each object that it holds and whose native object it 
reads: an OneVsRest's classifier, a Pipeline's stages, a validator's estimator, 
evaluator and grid values, a PipelineModel's stages, an OneVsRestModel's 
models, and a validator model's best model and sub-models (`_sync`).
   - The maps of an object that this client makes (a fit's model, a load, a 
native copy) are made of the native object's values at their first read 
(`_LazyParamMap`, `_native_params`).
   - A load of the server's format sets its params by `_resetUid(uid)` and 
`_set(**params)`, as `RemoteMLReader.loadInstance` does, and a load of a 
validator sets its defaults by `_setDefault`, as `getAndSetParams` does.
   - OneVsRest's `parallelism` syncs with the conversion of its setter, so that 
an int of more than 64 bits raises PySpark's `Number of processes must be at 
least 1`.
   - The native members of a public class have PySpark's docstrings, qualified 
names and signatures.
   
   ### Why are the changes needed?
   
   For the native ML classes to behave as PySpark's, and their subclasses as 
subclasses of PySpark's. For example, `lr._paramMap`, `lr._copyValues(other)`, 
`LogisticRegression(family=np.str_("auto")).getFamily()` (a NumPy string, as 
PySpark keeps it), `lr.setRegParam(np.float32(0.5))` (PySpark's TypeError), 
`extractParamMap()` in the order that the params were set, and `getMaxIter()` 
after `lr.uid = ...` (PySpark's ValueError of a Param of the old uid). A 
follow-up of OneVsRest (a classifier that is not native) builds on PySpark's 
own `_fit` and `_copyValues` over these maps.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. The native ML classes of `pyspark.ml.connect` have PySpark's param maps 
and PySpark's own Params API over them, as described above. A writer still 
takes the params at `write()`, where PySpark's reads them at its `save`; that 
difference is not changed here.
   
   ### How was this patch tested?
   
   - New offline tests in `test_ml_subclasses_offline.py`:
     - the param maps, `_set`, `_setDefault`, `_copyValues` and `_input_kwargs` 
as PySpark's;
     - an assignment of `uid`;
     - the messages of a call that does not bind;
     - the NumPy values of the `TypeConverters`;
     - the sync of the objects that an object holds;
     - PySpark's docstrings and signatures of the native members;
     - the native summaries.
   - The expected signatures and setter cases of `test_ml_offline.py`, 
`test_ml_features_offline.py` and `test_evaluators_offline.py` now follow 
PySpark's, including PySpark's own broken `LinearRegression.setLoss`, which 
raises `AttributeError: 'LinearRegression' object has no attribute 'lossType'`.
   - The CI offline and live Python lists, against a Spark 4.3.0 Connect server.
   
   ### 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