This is an automated email from the ASF dual-hosted git repository.

HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git


The following commit(s) were added to refs/heads/master by this push:
     new bd9291c9 [SPARK-61612][FOLLOWUP][CONNECT][PYTHON] Raise PySpark's 
ValueError for a OneVsRest parallelism below 1, in the Python client
bd9291c9 is described below

commit bd9291c9844028636c129babb543e27951d91fc9
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Fri Nov 13 16:33:09 2026 +0900

    [SPARK-61612][FOLLOWUP][CONNECT][PYTHON] Raise PySpark's ValueError for a 
OneVsRest parallelism below 1, in the Python client
    
    ### What changes were proposed in this pull request?
    
    The fit of the native `OneVsRest` now raises PySpark's error for a 
`parallelism` below 1: a plain `ValueError`, "Number of processes must be at 
least 1". It raises before anything is sent. Before, it raised the Rust core's 
`PySparkValueError`, "parallelism must be at least 1".
    
    ### Why are the changes needed?
    
    PySpark's `OneVsRest` fits its classifiers in a `ThreadPool` of 
`parallelism` processes, which raises that `ValueError` for 0 or less. A 
post-merge review of #605 found the difference.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes. The error class and message now match PySpark 4.3.0. The Rust API's 
own message does not change.
    
    ### How was this patch tested?
    
    - A new offline test covers `parallelism` of 0 and -1, from the constructor 
and from `setParallelism`.
    - `test_ml_offline.py`: 148 passed.
    - `test_remaining_classifiers_e2e.py` against a Spark 4.3.0 Connect server: 
36 passed.
    - With a real DataFrame on the server, the official `pyspark-client` 4.3.0 
and this client both raise `builtins.ValueError: Number of processes must be at 
least 1`, for 0 and -1.
    
    ### 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.
    
    Closes #611 from HyukjinKwon/SPARK-61612-followup-ovr-parallelism.
    
    Authored-by: Hyukjin Kwon <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 crates/pyspark-rs/src/ml.rs     |  7 +++++++
 python/tests/test_ml_offline.py | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/crates/pyspark-rs/src/ml.rs b/crates/pyspark-rs/src/ml.rs
index 368dd776..d483bc58 100644
--- a/crates/pyspark-rs/src/ml.rs
+++ b/crates/pyspark-rs/src/ml.rs
@@ -1965,6 +1965,13 @@ impl PyOneVsRest {
                     ("weightCol is ignored, as it is not supported by this 
classifier",),
                 )?;
             }
+            // PySpark's fit trains the binary classifiers in a ThreadPool of 
`parallelism`
+            // processes, which raises this ValueError when there are fewer 
than one.
+            if this.inner.parallelism() < 1 {
+                return Err(PyValueError::new_err(
+                    "Number of processes must be at least 1",
+                ));
+            }
             this.inner = this.inner.clone().set_classifier(classifier);
         }
         fit_native(slf, dataset, None)
diff --git a/python/tests/test_ml_offline.py b/python/tests/test_ml_offline.py
index 732713f5..6df3f67c 100644
--- a/python/tests/test_ml_offline.py
+++ b/python/tests/test_ml_offline.py
@@ -3781,6 +3781,22 @@ def 
test_one_vs_rest_defers_base_param_validation_until_fit():
         estimator.fit(None)
 
 
[email protected]("use_setter", [False, True])
[email protected]("parallelism", [0, -1])
+def 
test_one_vs_rest_raises_pysparks_error_for_fewer_than_one_process(parallelism, 
use_setter):
+    from pyspark.ml.connect.classification import LinearSVC, OneVsRest
+
+    if use_setter:
+        estimator = 
OneVsRest(classifier=LinearSVC()).setParallelism(parallelism)
+    else:
+        estimator = OneVsRest(classifier=LinearSVC(), parallelism=parallelism)
+    # PySpark's fit trains the classifiers in a ThreadPool of `parallelism` 
processes, which
+    # raises a plain ValueError for fewer than one, before anything is sent.
+    with pytest.raises(ValueError, match="^Number of processes must be at 
least 1$") as raised:
+        estimator.fit(None)
+    assert type(raised.value) is ValueError
+
+
 @pytest.mark.parametrize("name", ["AFTSurvivalRegression", 
"IsotonicRegression", "FMRegressor"])
 @pytest.mark.parametrize("use_setters", [False, True])
 def test_remaining_regressor_native_parameters_match_official_fixture(ml_mock, 
name, use_setters):


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to