xinrong-meng opened a new pull request, #51090:
URL: https://github.com/apache/spark/pull/51090

   ### What changes were proposed in this pull request?
   Fix divide-by-zero error in groupby().corr('kendall') with ANSI mode enabled
   
   
   ### Why are the changes needed?
   
   ### Does this PR introduce _any_ user-facing change?
   Yes
   ```py
   >>> ps.set_option("compute.fail_on_ansi_mode", False)
   >>> ps.set_option("compute.ansi_mode_support", True)
   >>> df = ps.DataFrame(
   ...     {"A": [0, 0, 0, 1, 1, 2], "B": [-1, 2, 3, 5, 6, 0], "C": [4, 6, 5, 
1, 3, 0]},
   ...     columns=["A", "B", "C"]
   ... )
   ```
   
   FROM
   ```py
   >>> df.groupby("A").corr('kendall')
   25/06/04 14:40:03 ERROR Executor: Exception in task 0.0 in stage 13.0 (TID 
51)
   org.apache.spark.SparkArithmeticException: [DIVIDE_BY_ZERO] Division by 
zero. Use `try_divide` to tolerate divisor being 0 and return NULL instead. If 
necessary set "spark.sql.ansi.enabled" to "false" to bypass this error. 
SQLSTATE: 22012
   == DataFrame ==
   "__truediv__" was called from
   ...
   ```
   TO
   ```py
   >>> df.groupby("A").corr('kendall')
               B         C                                                      
   
   A                      
   0 B  1.000000  0.333333
     C  0.333333  1.000000
   1 B  1.000000  1.000000
     C  1.000000  1.000000
   2 B  1.000000       NaN
     C       NaN  1.000000
   ```
   
   ### How was this patch tested?
   Unit tests
   
   ### Was this patch authored or co-authored using generative AI tooling?
   No


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