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

   ### What changes were proposed in this pull request?
   
   From a review of the documented differences of ML (`docs/compatibility.md`, 
`dev/parity/known-differences.md`) against PySpark 4.3.0, and the other 
session's review of the last 100 commits. Each item was probed on both clients 
against a Spark 4.3.0 server.
   
   **1. The state of Python subclasses of the native ML classes.**
   - A subclass's `__getstate__`, `__setstate__` and `__reduce__` were ignored, 
because `uid` was a native property outside `__dict__`, and the native 
`__copy__` took precedence:
     - a pickle or deep copy of `class MyTok(Tokenizer)` with the usual state 
methods lost its uid and Params (`getInputCol()` raised "Param ... does not 
belong to");
     - with `__getstate__` only, a pickled `maxIter=3` became 100;
     - `copy.copy` and `Params.copy` ignored the subclass's methods.
   - Now `uid` is an attribute of `__dict__`, synced to the native object 
before its native members.
   - `__getstate__` and `__setstate__` are PySpark's state, and `__setstate__` 
still reads the old format.
   - `copy.copy` goes through `__reduce_ex__(4)` and `copy._reconstruct` when a 
subclass or mixin has its own reduce, state, newargs, slots or a `copyreg` 
reducer.
   - The models of server objects still refuse to pickle first.
   
   **2. `pyspark.ml.stat`.**
   - `ChiSquareTest`, `Correlation`, `KolmogorovSmirnovTest` and `Summarizer` 
are public subclasses of the native classes.
   - They have PySpark's class docstrings, and static methods of PySpark's 
signatures, annotations, docstrings and `since`, which delegate to the native 
methods.
   - `_check_param` and `_get_single_metric` are PySpark's code.
   
   **3. Pickles and plans.**
   - A DataFrame of the vendored `pyspark.ml` models, such as a 
`LinearRegressionModel` transform, raised the session's `AttributeError` at 
pickle and deep copy. It now raises PySpark's `cannot pickle '_thread.lock'`, a 
`PicklingError` below protocol 2. A summary DataFrame follows the summary's 
path.
   - The walk of the plans for that check enters subqueries.
   - The members of the native classes (methods, properties, classmethods) 
cloudpickle.
   - A Pipeline of a one-shot iterator of stages saves its stages, as PySpark's 
writer iterates them three times.
   
   **4. Metadata, uids and attributes.**
   - A validator's metadata `paramMap` and `defaultParamMap` are those of 
PySpark's `extractParamMap()` and `_defaultParamMap`, so a subclass's own 
Params are saved. A Pipeline's `defaultParamMap` is written; it was `{}`.
   - A Python subclass of `PipelineModel`, `OneVsRestModel` or a validator 
model takes the uid prefix of its class, as #791 did for the JavaModels.
   - Pipeline, OneVsRest, the validators and their models have no `_java_obj`, 
as PySpark's do not.
   - A model and its training summary share one remote reference, as PySpark's 
`_remote_model_obj` does.
   - An object with a `sparkSession` but no `_plan` raises PySpark's 
`AttributeError` of `_plan`.
   
   **5. Docs.**
   - Stale entries fixed:
     - the assignment of `uid`;
     - CrossValidator's `setParams`;
     - OneVsRest's "remaining differences" (its `write()` succeeds);
     - the cause of the RandomForest cross-validation failure, which is the 
per-process default seed `hash(type(self).__name__)`.
   - Reasons given: the non-active session, the release counts of shallow 
copies, the deprecated `pyspark.ml.connect` API, and OneVsRest's class cap.
   - Remaining differences documented:
     - the laziness of `vars()` of fitted, loaded and copied models;
     - the native properties of the meta-models;
     - a dropped model deleted in its own session;
     - ML on a thread with no active session;
     - plain pickles of a member;
     - OneVsRest's order of reads.
   
   ### Why are the changes needed?
   
   So that Python subclasses of the ML classes, as users and libraries write 
them, keep their state in copies and pickles as with PySpark, and so that the 
ML objects, their docs and their metadata are PySpark's.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, as above.
   
   ### How was this patch tested?
   
   - **New tests.**
     - `test_ml_subclasses_offline.py`: subclass reduce and state, the old 
state, no `_java_obj`, cloudpickles of members, subclass uids. They pass on the 
official client too.
     - `test_ml_offline.py`: the errors of datasets, the shared references, the 
DataFrames of vendored models, and subqueries.
     - `test_statistics_offline.py`: the stat docs, signatures and annotations.
     - Live `test_ml_subclasses_e2e.py`: subclass metadata Params and the save 
of a one-shot iterator; both pass on the official client too.
     - Core unit tests in `ml/object.rs`.
   - **Probes of both clients:** 17 probes, whose differences went from 175 to 
27. All 27 left are documented: the laziness of `vars()`, the native 
properties, PySpark's release counts, Column module names in annotations, and 
the MRO of the stat classes.
   - **Python.** The offline suite of `coverage.yml` on pandas 2 and 3. Live ML 
tests (326 passed).
   - **Rust.** `cargo test -p apache-spark-connect -p apache-spark-connect-core 
--release`, and `--features wasm-udf`, and in a debug build; `cargo test -p 
pyspark-rs --lib`, linked as `rust.yml` links it.
   - **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -p pyspark-rs 
-p apache-spark-connect --all-targets -- -D warnings`, ruff 0.14.0, 
`audit_no_stubs.sh` and `scripts/tests`.
   
   ### 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