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

   ### What changes were proposed in this pull request?
   
   `ChiSquareTest.test`, `Correlation.corr` and `KolmogorovSmirnovTest.test` of 
`pyspark.ml.stat` are helper calls (`invoke_helper_relation`). They serialize 
each argument as `serialize` of `pyspark.ml.connect.serialize` does: a 
DataFrame as its relation, and any other value as a literal.
   
   Official PySpark 4.3.0 sends a literal of a type the helper does not take, 
and the server rejects the call when the DataFrame is analyzed or collected. 
That covers a dataset that is not a DataFrame, a column name that is not a str, 
and a `flatten` or `method` of another type. The native classes raised a 
client-side `TypeError` for these instead. For a non-bool `flatten` or a 
non-str `method`, they raised PyO3's argument error.
   
   This PR builds the helper relation of each argument as PySpark serializes 
it, with `fetch_arg_of` and `attribute_relation` of the ML base:
   - The relation is built on the session of the dataset. When the dataset is 
not a DataFrame, it uses the active session, which is what PySpark uses 
(`AssertionError` when there is none).
   - An argument that cannot be a literal still raises PySpark's error of that 
conversion, before any request. That includes a pandas DataFrame 
(`UNSUPPORTED_DATA_TYPE`) and an empty list (`CANNOT_INFER_ARRAY_ELEMENT_TYPE`).
   - The KS test still converts its parameters with `float()` first. It sends 
them as the `array<double>` literal it sent before.
   - `flatten=False` and `method='pearson'` keep their signature defaults 
(`DefaultedOption`), so an explicit `None` is sent as PySpark sends it.
   
   Tests:
   - `tests/golden/statistics_arguments.json` holds 35 cases, captured from 
official PySpark by `scripts/capture_statistics_arguments_golden.py`. Each 
records the error of the call, or the arguments the call sends and the error of 
`collect()`.
   - `test_statistics_offline.py` checks the native classes against the golden: 
the errors before any request, and the arguments sent. These checks replace the 
`TypeError` checks.
   - `test_statistics_e2e.py` checks the server's errors of the lazy cases.
   
   ### Why are the changes needed?
   
   So that the native statistics classes behave as `pyspark.ml.stat` does over 
Spark Connect, down to their error paths. This item was left open in the parity 
inventory of the stat classes.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, in the native classes, which are unreleased. A call with an argument of 
the wrong type now returns a lazy DataFrame, as PySpark's does. The server's 
error, such as `NoSuchMethodException` or `NULL not supported`, is raised when 
the DataFrame is analyzed or collected, instead of a `TypeError` at the call.
   
   ### How was this patch tested?
   
   All of the following runs against a Spark 4.3.0 Connect server.
   - A probe of 38 argument cases gives identical results on ours and on 
official `pyspark-client` 4.3.0: the error of the call, or the errors of 
`columns` and of `collect()`.
   - Ours: `test_statistics_offline.py` passed 115 and `test_statistics_e2e.py` 
passed 68.
   - Official, in its reference mode (`STATISTICS_REFERENCE=1`): 
`test_statistics_e2e.py` passed 68.
   - The coverage job's offline list passed 4718, with 13 skipped.
   - Clippy (`-D warnings`), fmt and ruff 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