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

   ### What changes were proposed in this pull request?
   
   The native ML classes (`pyspark.ml.connect.*`) accepted only a `str` as the 
path of `save`, `load`, `write().save` and `read().load`. Any other value 
raised PyO3's TypeError (`'int' object is not an instance of 'str'`). They now 
take the path as PySpark does. Every row below was probed on both clients 
against a Spark 4.3.0 Connect server:
   
   | Path | Estimator / model / evaluator (PySpark: the protobuf field of 
`MlCommand.Write`/`Read`) | Pipeline / validator (PySpark: `os.path.join(path, 
"metadata")`) |
   |---|---|---|
   | `str` | as it is | as it is |
   | `bytes` (UTF-8) | decoded; saves and loads | `TypeError: Can't mix strings 
and bytes in path components` |
   | `b"\xff"` | `UnicodeDecodeError` | the same `TypeError` |
   | `None` | the empty path, which the server refuses: 
`IllegalArgumentException: Can not create a Path from an empty string` | 
`TypeError: expected str, bytes or os.PathLike object, not NoneType` |
   | `pathlib.Path` | `TypeError: bad argument type for built-in operation` | 
saves and loads |
   | `5`, `1.5` | `TypeError: bad argument type for built-in operation` | 
`TypeError: expected str, bytes or os.PathLike object, not int` |
   | `write().overwrite().save(5)` | the same `TypeError` | the server's 
`NoSuchMethodException` of `handleOverwrite(int, boolean)` (the ML helper's 
overwrite sends the path as PySpark's `serialize` does) |
   
   Also:
   - **Loading through a Python subclass** (`MyLR.load(path)`) now reads the 
JVM class of the subclass's own name, as PySpark's `RemoteMLReader` names it 
from the Python class (`__module__` with `pyspark` replaced by 
`org.apache.spark`, plus `__name__`). The server refuses it with 
`[CONNECT_ML.UNSUPPORTED_EXCEPTION] ... Unsupported read for __main__.MyLR`, as 
on PySpark. Before, it read the native class's JVM class and returned a plain 
`LogisticRegression`. A subclass of Pipeline loads a `Pipeline`, as on PySpark. 
Found by spark-0b's review of #735.
   - **`getParam` of a name that is not a str** raises the TypeError of 
PySpark's `getattr(self, paramName)`: `attribute name must be string, not 
'int'` (spark-76's F6).
   
   ### Why are the changes needed?
   
   So that persistence and `getParam` behave as in PySpark, down to their 
errors. These are findings F5 and F6 of the post-merge review of the last 50 
commits, and forked-0a's finding 3.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, in the native classes, which are unreleased: the behaviors above.
   
   ### How was this patch tested?
   
   - The cases of `tests/golden/ml_api_cases.json` were recaptured on official 
pyspark-client 4.3.0. They now record the saves and loads above for a 
LinearSVC, a KMeans and their models, and for a Pipeline, plus `getParam` of an 
int and of None. The recapture only adds keys (69); no recorded value changed.
   - A new e2e test of a subclass's load: official PySpark passes it too.
   - `test_ml_api_offline.py` and `test_ml_api_e2e.py` pass on this branch: 872 
passed. With master's extension, the new cases fail: the LinearSVC, KMeans and 
Pipeline live cases, the LinearSVC and KMeans params-API cases, and the 
subclass-load test.
   - `cargo fmt --all --check` and `ruff check` pass. The full exact-tree 
suites will run locally once the machine is free, 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