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

   ### What changes were proposed in this pull request?
   
   A follow-up of #563 (SPARK-61531) and #574 (SPARK-61545). The native classes 
of `pyspark.ml.connect` (JVM estimators over the Connect ML protocol) now 
output PySpark's columns and take its inputs:
   
   **LogisticRegression.**
   - Its model outputs PySpark's `_output_columns`: a `bigint` prediction, then 
an `array<double>` probability, and no `rawPrediction`. Both are nullable, and 
the array contains null, as PySpark's pandas UDF outputs them.
   - It used to output the JVM's `rawPrediction` and `probability` vectors and 
a non-nullable double prediction.
   - An empty `probabilityCol` outputs no probability, as PySpark's `if 
prob_col`.
   - The constructor sends `rawPredictionCol=""`, as the StandardScaler 
constructor sends `withMean`, so a dataset with a `rawPrediction` column fits 
and transforms.
   - The constructor takes `probabilityCol` and `tol` in PySpark's order, with 
`setProbabilityCol` and `setTol`.
   - PySpark's PyTorch-only params (`numTrainWorkers`, `batchSize`, 
`learningRate`, `momentum`, `seed`) still raise the unexpected-keyword 
`TypeError`, since the JVM's L-BFGS cannot use them. This is documented.
   
   **pandas DataFrames.** `fit` and `transform` take a `dataset`, a DataFrame 
or a pandas DataFrame, as PySpark's do:
   - `LogisticRegression.fit` of a pandas DataFrame raises PySpark's 
`NotImplementedError("Fitting pandas dataframe is not supported yet.")`.
   - The other estimators fit it through `createDataFrame` of the active 
session.
   - A model's transform of a pandas DataFrame returns a pandas DataFrame: a 
shallow copy of the input with the output columns appended, computed on the 
server. MaxAbsScaler's matches the reference exactly: columns, dtypes, index, 
`float64` ndarray cells, and the shallow copy.
   - Another object raises PySpark's `AttributeError` of `columns` (transform) 
or `select` (fit).
   
   **Existing output columns.** The models of LogisticRegression, MaxAbsScaler 
and StandardScaler raise PySpark's `ValueError("Transformers does not allow 
output column having the same name with existing columns.")` before 
transforming. They used to raise the server's `IllegalArgumentException`. Their 
fits send only the columns that PySpark's fits read (features and label, or 
`inputCol`), so a dataset with an output column fits, as in PySpark.
   
   **Scaler output.** The scalers output an `array<double>` that is nullable 
and contains null, as PySpark's does. It used to be neither.
   
   On the live server, the transform schemas of the reference and of this 
client are now identical for MaxAbsScaler, StandardScaler, and 
LogisticRegression with default, empty and renamed probability columns.
   
   ### Why are the changes needed?
   
   To match PySpark 4.3.0's `pyspark.ml.connect`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, in the Python client. The native LogisticRegression model outputs a 
bigint prediction and an array probability, with no raw prediction. The native 
classes take pandas DataFrames, raise PySpark's errors, and output nullable 
scaled arrays.
   
   ### How was this patch tested?
   
   - New and updated tests in `test_ml_offline.py` (10) and `test_ml_e2e.py` 
(3), which fail without the change.
   - The lib tests of both crates (857 passed), the Rust integration tests 
against a local Spark 4.3.0 server (998 passed, 26 ignored), the build of all 
tests with `wasm-udf`, the offline Python suites (3269 passed, 8 skipped), and 
the live drop-in, Arrow and ML suites (310 and 51 passed), on master with 
SPARK-61590 and SPARK-61591 applied. `cargo fmt --all --check` and the no-stub 
audit 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]

Reply via email to