HyukjinKwon opened a new pull request, #663:
URL: https://github.com/apache/spark-connect-rust/pull/663
### What changes were proposed in this pull request?
This follows up #620 (SPARK-61624), from a post-merge review. The native ML
fits raised a `TypeError` ("The native ML classes take no param map") for any
list or tuple `params`. `pyspark.ml`'s `Estimator.fit` runs `fitMultiple` for a
list or tuple instead: one fit per map, in order, with the models returned as a
list. Its cases:
- `[]` and `()` return `[]` with no fit, and do not touch the dataset;
- `[{}]` returns `[model]`, and `[{}, {}]` two models;
- a map in the list is checked as the `params` of a single fit, so `[1]`
raises `Params must be either a param map or a list/tuple of param maps, but
got <class 'int'>.` after fitting the maps before it;
- nested lists recurse.
The native fits now do the same. A shared helper, `fit_with`, sends each map
of a list or tuple through the class's own `fit`, so each map gets the checks
and the errors of a fit with that map alone. Every native fit wraps its body in
it and returns `Fitted<M>`, one model or the list of models:
- the 23 fits of `ml.rs`;
- ALS and FPGrowth;
- the 13 fitting feature stages of `feature_wrapper`.
`check_fit_params` no longer handles lists. Pipeline and CrossValidator
raise `NOT_IMPLEMENTED` per map, as for a single fit, and `[]` returns `[]`.
`docs/compatibility.md` describes the list fitting.
Two differences are kept, as before:
- a non-empty map in the list raises the native classes' `TypeError`, since
they have no Param objects to key a map by;
- a pandas DataFrame raises `reject_pandas`'s `TypeError`, unless the list
is empty.
### Why are the changes needed?
For parity with `pyspark.ml`, which code that fits a grid of param maps
relies on.
### Does this PR introduce _any_ user-facing change?
Yes. `fit(df, [map, ...])` returns a list of models where it raised a
`TypeError`.
### How was this patch tested?
- Compared with the reference client against a Spark 4.3.0 Connect server,
using `LinearRegression`. These cases match:
- `[]`, `()`, `[{}]`, `[{}, {}]` and `[[{}]]`;
- `[1]`, `1` and `[{}, 1]`;
- `fit(pdf, [])`.
- New and rewritten offline tests in `test_ml_offline.py` and
`test_ml_features_offline.py`, and a live test in `test_ml_e2e.py`, in which
two param maps give two models that transform. The changed offline tests failed
before (22 of 42), and the live test failed too.
- `tests/test_dropin_offline.py` and `tests/test_ml_offline.py` pass (2551
passed, 8 skipped), as do the live `test_ml_e2e.py` and
`test_ml_features_offline.py` (671 passed). After rebasing on master, the ML
offline suites pass (1086).
- `cargo clippy --workspace --all-targets -- -D warnings`, `cargo fmt
--check`, `scripts/audit_no_stubs.sh` and `ruff check` pass.
### 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]