dongjoon-hyun opened a new pull request, #60346:
URL: https://github.com/apache/spark/pull/60346

   ### What changes were proposed in this pull request?
   
   This PR aims to fix `ClassCastException` in the classic 
`DataFrame.approxQuantile` when `probabilities` contains Python `int` values 
like `0` and `1`. To do that, the shared 
`_validate_approx_quantile_probabilities` helper returns the probabilities as a 
list of `float`, as `relativeError` is already converted with 
`float(relativeError)`.
   
   ### Why are the changes needed?
   
   Py4J passes a Python `int` as `java.lang.Integer`, and the Python-friendly 
`DataFrameStatFunctions.approxQuantile(cols: List[String], probabilities: 
List[Double], relativeError: Double)` fails at `probabilities.toArray` because 
it cannot unbox `java.lang.Integer` to `Double`. The validation accepts `int` 
(its error message says `list[float, int]`), and `0` and `1` are the only valid 
`int` values, so natural calls such as `[0, 0.5, 1]` fail. Spark Connect is not 
affected because it puts the values into a `repeated double` proto field.
   
   This has been the case since the Python API was added by SPARK-13479 in 
[v2.0.0](https://github.com/apache/spark/releases/tag/v2.0.0) (2016-07-19). For 
example, on [v4.3.0](https://github.com/apache/spark/releases/tag/v4.3.0) 
(2026-10-27):
   
   ```python
   >>> df = spark.range(10)
   >>> df.approxQuantile("id", [0.0, 0.5, 1.0], 0.0)
   [0.0, 4.0, 9.0]
   >>> df.approxQuantile("id", [0, 0.5, 1], 0.0)
   ...
   java.lang.ClassCastException: class java.lang.Integer cannot be cast to 
class java.lang.Double (java.lang.Integer and java.lang.Double are in module 
java.base of loader 'bootstrap')
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `int` probabilities work in the classic `approxQuantile` like in Spark 
Connect, instead of failing with `ClassCastException`.
   
   ### How was this patch tested?
   
   Pass the CIs with the newly added test case in `test_approxQuantile`, which 
runs on both classic and Spark Connect via `test_parity_functions.py`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5


-- 
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