anshulbaliga7 opened a new pull request, #60714:
URL: https://github.com/apache/spark/pull/60714

   ### What changes were proposed in this pull request?
   
   This PR converts the `weights` of classic `DataFrame.randomSplit` to `float` 
before it passes them to the JVM.
   
   ### Why are the changes needed?
   
   Classic `randomSplit` passes the weights through `_to_list` to a JVM method 
that takes a list of `Double`. A Python `int` in the list reaches the JVM as a 
`java.lang.Integer`, which cannot be cast to `Double`:
   
   ```python
   >>> spark.range(10).randomSplit([1, 2], 24)
   py4j.protocol.Py4JJavaError: An error occurred while calling o30.randomSplit.
   : java.lang.ClassCastException: class java.lang.Integer cannot be cast to 
class java.lang.Double
   ```
   
   The signature is `weights: List[float]`, which accepts ints, and the Spark 
Connect implementation already does, because it divides the weights by their 
sum. SPARK-61464 fixed the same problem for `approxQuantile` in classic mode.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `randomSplit` with integer weights, such as `[1, 2]`, now works in 
classic mode, and splits the rows as the equal float weights do. It used to 
fail with a `ClassCastException`.
   
   ### How was this patch tested?
   
   New test case `test_random_split_int_weights` in `DataFrameTestsMixin`, 
which also runs in the Spark Connect parity suite. It checks that integer 
weights split the rows exactly like the equal float weights with the same seed, 
and that no row is lost. Without the fix, the classic run fails with the 
`ClassCastException` above.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Yes.


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