HyukjinKwon opened a new pull request, #607:
URL: https://github.com/apache/spark-connect-rust/pull/607
### What changes were proposed in this pull request?
A follow-up of the post-merge review of #574 (SPARK-61545), with the
decisions of its author:
- `pyspark.ml.connect.feature` is now PySpark 4.3.0's own module, vendored
byte-identical and checked by the drift gate. `StandardScaler`, `MaxAbsScaler`
and `ArrayAssembler` (with their models) come from it. They run over this
client's transport: the fit uses `summarize_dataframe`, and the transform uses
closures that the server's Python workers run.
- The drop-in's native `StringIndexer` and `VectorAssembler` are set on that
module by `pyspark.ml.connect`'s `__init__`, so `from
pyspark.ml.connect.feature import StringIndexer` still works.
- The PyO3 scaler wrappers and their dead arms in `ml.rs` are removed.
- The Rust API keeps `spark_connect::ml::StandardScaler` and `MaxAbsScaler`.
`StandardScaler` gets `set_with_mean` and `with_mean`; before, only the Python
constructor sent `withMean=true`.
- The native `LogisticRegression` fit runs PySpark's label checks before the
JVM fit, with PySpark's ValueErrors: "Training dataset distinct labels must >=
2." and "Training labels must be integers in [0, numClasses).". It runs
PySpark's `collect_set(label)` query. It doesn't run PySpark's count and
`first(array_size(features))`: they don't feed the checks, and `array_size`
raises on the vector features that the native fit takes.
- Docs: the native estimators of a `featuresCol` are documented as taking
vectors, arrays and pandas, unlike classic `pyspark.ml`'s VectorUDT-only
estimators; the code comment says so too. The JVM-scaler caveats are dropped,
and the label checks are documented.
### Why are the changes needed?
For parity with PySpark 4.3.0. Each case is the client before this change,
then PySpark (and the client after):
- `StandardScaler` fit on one row: `[(0.0, 0.0)]` / `ValueError: Standard
deviation evaluation requires more than one row data.`
- `MaxAbsScaler` on `[[1.0, None], [-3.0, -2.0]]`: `FAILED_EXECUTE_UDF`
(NOT_NULL_ASSERT_VIOLATION) / `[(0.333..., None), (1.0, None)]`.
- `MaxAbsScaler` with a NaN: finite values from the JVM, which ignores NaN /
`None` in that slot.
- A transform on another session: `CONNECT_ML.CACHE_INVALID` / works.
- Empty arrays, `array<boolean>`, and a shorter array: errors or silent
truncation / PySpark's results.
- `LogisticRegression` on labels `{0, 2}`, `{1, 2}`, or a single class:
fitted / `ValueError`.
An edge-case probe of about 24 scaler cases gives line-for-line the same
output on PySpark 4.3.0 and on the client.
### Does this PR introduce _any_ user-facing change?
Yes. The `pyspark.ml.connect` scalers are PySpark's own, with PySpark's
values, errors, Params API, models and save/load, and `ArrayAssembler` is
added. `LogisticRegression` raises PySpark's ValueErrors for bad labels before
fitting. The Rust `StandardScaler` has `set_with_mean`.
### How was this patch tested?
- The scaler tests in `test_ml_offline.py` and `test_ml_e2e.py` are
rewritten against the vendored behavior. The new label-check tests, offline and
e2e, fail with the check disabled.
- On the tree merged with the latest master, with `TZ=UTC` and protobuf's
default upb backend:
- the Rust lib tests (660 and 220) and the drift gate;
- `test_ml_offline.py`: 136 passed;
- `test_ml_e2e.py` against Spark 4.3.0: 29 passed;
- the ML tests of `test_dropin_e2e.py`.
- On the branch:
- CI's offline set: 3283 passed;
- the other native ML e2e files: 87 passed;
- the `--no-run` builds, `cargo fmt`, the stub audit and the ruff gates.
### 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]