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

   ### What changes were proposed in this pull request?
   
   A review of the native ML classes against PySpark 4.3.0 found these gaps in 
the summaries and the stat classes, each probed on both clients against a Spark 
4.3.0 server.
   
   **1. Summaries.**
   
   | case | PySpark 4.3.0 (now here too) | before |
   |---|---|---|
   | a DataFrame member of a summary built as `cls("<id>.summary")` | 
`AttributeError: '<cls>' object has no attribute '_summary_dataset'` 
(ml/util.py:114-115), as `invoke_remote_attribute_relation` reads it | a lazy 
DataFrame that failed at execution with `INTERNAL_ERROR` or `CACHE_INVALID` |
   | a summary built by the user, `cls()` or `cls("abc")` | copies and pickles 
as a plain object, and its `_java_obj` is the given value | `__deepcopy__` and 
`__reduce_ex__` raised, and `_java_obj` was None |
   | a pickle or deep copy of a fitted training summary of KMeans, 
BisectingKMeans or GaussianMixture, or of an `evaluate()` summary of 
LinearRegression or GeneralizedLinearRegression | the `TypeError` of pickling a 
lock (a `PicklingError` below protocol 2) | the session's `AttributeError` |
   | the docstrings of the members, such as `LinearRegressionSummary.r2` and 
`KMeansSummary.k` | PySpark's | empty |
   
   - A summary's `__init__` is PySpark's own `JavaWrapper.__init__`, which sets 
`_java_obj`, and the native members read it at each call.
   - The members of a summary class are properties and methods with PySpark's 
docstrings and signatures.
   - The core gets a doc-hidden `MlTarget::summary_dataset_reads_model`, a walk 
of a plan for a transform of a cached model, which tells which summaries hold a 
lock in PySpark.
   
   **2. The stat classes.**
   - `ChiSquareTest`, `Correlation`, `KolmogorovSmirnovTest` and `Summarizer` 
are plain classes in PySpark (ml/stat.py:36, 122, 197 and 286). In the drop-in, 
`ChiSquareTest()`, `Summarizer()` and their subclasses raised `TypeError: 
cannot create ... instances`. They now construct, also as subclasses, and copy 
and pickle as PySpark's.
   - `SummaryBuilder` is published with PySpark's `__init__(self, 
jSummaryBuilder)` (stat.py:489-502) and docstring. Before, 
`SummaryBuilder(jSummaryBuilder=None)` raised the `TypeError` of 
`JavaWrapper.__init__`, and its signature was `(java_obj=None)`. 
`Summarizer.metrics` sets `_metrics` and `_java_obj = None`, as PySpark's does, 
and `summary` reads `_metrics`.
   
   **3. `pyspark.ml.stat` has no `__all__`**, as PySpark's has none, so `from 
pyspark.ml.stat import *` gives PySpark's 21 names. #754 (SPARK-61766) did the 
same for `pyspark.ml.connect.pipeline`.
   
   **4. StopWordsRemover fetches its server defaults once.** The native 
constructor fetched them, then PySpark's own `__init__`, which the public class 
runs, fetched them again (feature.py:5120 and 5124). The native constructors no 
longer fetch them:
   
   | | PySpark | before | now |
   |---|---|---|---|
   | `StopWordsRemover()` | 2 requests | 4 | 2 |
   | a load | 3 | 5 | 3 |
   
   `docs/compatibility.md` is updated for each of these.
   
   ### Why are the changes needed?
   
   So that code that builds, copies or pickles summaries and stat objects, as 
PySpark's tests and users do, works on the drop-in as on PySpark, and so that 
the members document themselves as PySpark's.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, as above. Documented differences that remain:
   - a cloudpickle of a training summary of a plain training DataFrame raises 
the session's `AttributeError`, where PySpark raises the lock's `TypeError`;
   - PySpark's deep copy of a training summary sends AnalyzePlan requests 
first, which the drop-in does not;
   - the stat classes lack PySpark's class and method docstrings.
   
   ### How was this patch tested?
   
   - **New tests**, each failing on master and passing here. Their bodies also 
pass on pyspark-client 4.3.0 over the mock server.
     - `test_ml_offline.py`:
       - 
`test_the_dataframe_members_of_a_summary_of_its_constructor_read_its_summary_dataset`;
       - `test_a_summary_of_a_fit_or_an_evaluation_is_not_pickled_as_pysparks`.
     - `test_ml_subclasses_offline.py`:
       - 
`test_the_members_of_a_summary_have_pysparks_docstrings_and_signatures`;
       - 
`test_a_summary_keeps_its_java_obj_and_copies_and_pickles_as_a_plain_object`.
     - `test_statistics_offline.py`:
       - `test_the_module_has_pysparks_names_and_no_all`;
       - `test_the_statistics_classes_construct_as_pysparks_plain_classes`;
       - `test_a_summary_builder_constructs_and_summarizes_as_pysparks`.
     - `test_ml_features_offline.py`: 
`test_stop_words_remover_fetches_its_defaults_once_as_pyspark`.
     - `test_ml_subclasses_e2e.py`: two tests extended, with the 
`_summary_dataset` errors and the lock errors.
     - A Rust unit test of `summary_dataset_reads_model`.
   - **Probes of both clients:**
     - user-built summaries of 15 classes: 519 of 678 results differed before, 
15 now, of a subclass whose `__init__` skips `super().__init__()`;
     - pickles and deep copies of the summaries of 12 estimators at protocols 0 
to 5;
     - 846 checks of docstrings, kinds and signatures;
     - the stat classes;
     - the requests of StopWordsRemover.
   - **Python.** The offline suite of `coverage.yml`. The ML offline files on 
pandas 2 and 3 after the rebase on master: 2057 passed each. Seven live ML 
files (301 passed).
   - **Rust.** `cargo test -p apache-spark-connect --release --lib` (749 
passed).
   - **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