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

   ### What changes were proposed in this pull request?
   
   - The native `Pipeline.fit` and `CrossValidator.fit` of the Python client 
ran the checks of PySpark's param serialization (`VALUE_NOT_BETWEEN` for an int 
that cannot be sent, `CANNOT_INFER_ARRAY_ELEMENT_TYPE` for an empty list) 
before the core raised `NOT_IMPLEMENTED`. They now raise `NOT_IMPLEMENTED` for 
every param state, without a request.
   - The docs of the native `DecisionTreeClassifier` and 
`RandomForestClassifier`, in the Rust API and in `docs/compatibility.md`, now 
describe the seed and the labels as Spark 4.3.0 implements them. A single tree 
uses the seed only to sample the rows that find its split candidates on large 
inputs, and it chooses equal-gain splits deterministically. Labels are 
non-negative integer class indices below `numClasses`, so a class with no rows 
is allowed.
   - `e2e_random_forest_regressor.rs` uses `common::live_session` instead of 
its own copy of it, the long import of `pyspark/ml/connect/__init__.py` is 
wrapped, and the decision tree unit tests use `assert!` for bools.
   
   ### Why are the changes needed?
   
   `pyspark.ml.connect.pipeline.Pipeline(stages=[]).fit(df)` raised 
`PySparkTypeError` `CANNOT_INFER_ARRAY_ELEMENT_TYPE`, and a test said PySpark 
does so. `Pipeline(stages=["a"]).fit(df)` raised `PySparkNotImplementedError` 
`NOT_IMPLEMENTED`. PySpark's `Pipeline(stages=[]).fit` returns an empty 
`PipelineModel`. The drop-in cannot fit a native pipeline at all, so it now 
raises `NOT_IMPLEMENTED` in every case. `CrossValidator(seed=2**64).fit` raised 
`VALUE_NOT_BETWEEN` for the same reason, and now raises `NOT_IMPLEMENTED` too.
   
   The docs claimed that the seed of a decision tree breaks ties between equal 
splits, and that labels must be contiguous class indices starting at zero. 
Neither matches Spark 4.3.0. In `RandomForest.findSplits`, the seed samples the 
input when it has more than `max(maxBins^2, 10000)` rows, and the best split is 
a `maxBy` of the gains. `getNumClasses` takes the label metadata, else the 
maximum label plus one. With `maxBins=4` on 30,000 rows, seeds 1 and 2 give 
different predictions, and labels `{0, 2, 4}` train fine in both clients.
   
   This is a follow-up of SPARK-61399 (#490), SPARK-61391 (#487) and 
SPARK-61450 (#512).
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `Pipeline.fit` and `CrossValidator.fit` of the native classes now raise 
`NOT_IMPLEMENTED` where an empty-list or unsendable param raised 
`CANNOT_INFER_ARRAY_ELEMENT_TYPE` or `VALUE_NOT_BETWEEN`. The rest is 
documentation and tests.
   
   ### How was this patch tested?
   
   `test_ml_pipeline_and_cross_validator_fit_is_not_implemented` in 
`python/tests/test_ml_offline.py` now covers `Pipeline(stages=[])`, 
`CrossValidator(seed=2**64)` and `CrossValidator(numFolds=2**70)`. It asserts 
`NOT_IMPLEMENTED` and that no request is sent, and fails without this change. 
The ML offline suite (110 passed), the drop-in offline suite, the Rust library 
tests, the `--no-run` builds (with and without `wasm-udf`), and the Rust and 
Python ML e2e suites against Spark 4.3.0 pass, as do `cargo fmt --check`, 
`scripts/audit_no_stubs.sh` 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]

Reply via email to