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

   ### What changes were proposed in this pull request?
   
   This is a follow-up of #687 (SPARK-61699), found while reviewing the last 50 
commits.
   
   The Rust API's `LogisticRegression::threshold()` and `thresholds()`, and 
those of `LogisticRegressionModel`, compute two things in `f64` arithmetic: 
PySpark's `getThreshold` equivalent of two thresholds, `1 / (1 + t0 / t1)`, and 
its `_checkThresholdConsistency`. A zero `t1` gave 0.0 or NaN, and a ratio `t0 
/ t1` of -1 gave infinity. PySpark computes both in Python, which raises 
`ZeroDivisionError: float division by zero` for a zero divisor.
   
   This PR makes both divisions return that error, as `ml/tuning.rs` already 
does for the ZeroDivisionError of PySpark's `_kFold`.
   
   ### Why are the changes needed?
   
   To match PySpark 4.3.0. Probes of official pyspark-client 4.3.0:
   
   | thresholds | `getThreshold()` | with `threshold=0.5` also set |
   |---|---|---|
   | `[0.5, 0.0]`, `[0.0, 0.0]`, `[1.0, -0.0]` | ZeroDivisionError: float 
division by zero | ZeroDivisionError, also from `getThresholds()` and the 
constructor |
   | `[-1.0, 1.0]` | ZeroDivisionError: float division by zero (the outer 
division) | the same |
   | `[0.0, 0.5]` | 1.0 | ValueError: inconsistent values (equivalent to 1) |
   
   `getThresholds()` alone returns the thresholds in every case. The Python 
binding already raised PySpark's errors here; only the Rust API differed.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, in the Rust API. For thresholds whose equivalent has a zero divisor, 
`threshold()` returns the error "float division by zero" instead of 0.0, NaN or 
infinity. With a threshold set as well, `thresholds()` returns it too, from the 
consistency check.
   
   ### How was this patch tested?
   
   - A new offline test in `crates/spark-connect/tests/lr_svc_params.rs` covers 
the four zero-divisor cases, with and without a set threshold, and the non-zero 
`[0.0, 0.5]`. It fails without the fix 
(`a_zero_divisor_of_the_thresholds_is_pythons_zero_division`) and passes with 
it.
   - The crate's offline tests pass.
   - `cargo fmt --check`, `cargo +1.100.0 clippy --workspace --all-targets -- 
-D warnings` and `scripts/audit_no_stubs.sh` are clean.
   
   ### 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