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

   ### What changes were proposed in this pull request?
   
   A follow-up of #718 (SPARK-61737), which made the native ML classes 
subclasses of PySpark's classes. Since then a public class takes each member 
that its native class lacks from PySpark's class, through the MRO. Two of those 
members were PySpark's code of its Java wrapper, which reads PySpark's 
server-side object through `_call_java`. A native object has none (`_java_obj` 
is None), so both raised:
   
   | Call | Before (this client) | PySpark 4.3.0 |
   |---|---|---|
   | `repr(glr_model.summary)`, `str(...)` | `AttributeError: 'NoneType' object 
has no attribute 'split'` | the server's `toString` of the summary: its table 
of coefficients and its deviances |
   | `str(rformula_model)` | bare `AssertionError` | 
`RFormulaModel(ResolvedRFormula(label=y, terms=[s,x], hasIntercept=true)) 
(uid=RFormula_...)` |
   
   The native classes now define these members themselves, with the same 
fetches as PySpark's:
   - the GLR training summary's `__repr__` fetches its `toString`;
   - RFormulaModel's `__str__` fetches its `resolvedFormulaString`.
   
   A scan of every public member and dunder of the 140 classes that follow 
pyspark.ml in full found no other PySpark code reached through the MRO, except 
RFormula's `__str__`. That one reads only native members (`getFormula`, 
`isDefined`, `uid`), and its output matches. A new offline test, 
`test_public_members_and_dunders_are_the_native_classes`, fails when a public 
member or dunder of a native class resolves to PySpark's code outside that 
allowlist, so a new class cannot regress silently (spark-0b's suggestion).
   
   `docs/compatibility.md`:
   - says what these two members do now;
   - drops the stale passage about the message of a missing class attribute. A 
public class is a Python class now, so the message is CPython's for the class 
name (`type object 'DecisionTreeRegressor' has no attribute 'maxIter'`), the 
same as PySpark's;
   - rewords the `outputCol` default of a loaded feature stage, which PySpark's 
`_resetUid` keeps (forked-0a's wording; the behavior already matched).
   
   ### Why are the changes needed?
   
   So that `repr` and `str` of these objects behave as in PySpark rather than 
raising.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `repr`/`str` of a native `GeneralizedLinearRegressionTrainingSummary`, 
and `str` of a native `RFormulaModel`, now return PySpark's text instead of 
raising.
   
   ### How was this patch tested?
   
   The goldens of the feature and regression cases were recaptured on official 
pyspark-client 4.3.0 against a Spark 4.3.0 Connect server. They now record:
   - `str` of every feature stage (38);
   - `repr`, `str` and the loaded `str` of every feature model (19);
   - `repr` and `str` of the GLR training summary.
   
   The recaptures only add keys; no recorded value changed.
   
   On this branch:
   - `test_feature_api_offline.py`, `test_feature_api_e2e.py`, 
`test_regression_api_offline.py` and `test_regression_api_e2e.py` pass: 152 
tests.
   - The new offline test passes for all 140 classes. It is skipped on official 
PySpark, since it checks this client's classes.
   
   With master's extension (without the fix), the same tests fail for exactly 
these cases:
   - the RFormulaModel live cases;
   - the GeneralizedLinearRegression live cases;
   - the new test of those two classes.
   
   `cargo fmt --all --check` and `ruff check` pass. The full exact-tree suites 
(core tests against the server, plus the CI offline and live Python lists) are 
running locally, and I'll report them here.
   
   ### 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