Spenserrrr commented on code in PR #58319:
URL: https://github.com/apache/spark/pull/58319#discussion_r3875186022


##########
python/pyspark/pandas/numpy_compat.py:
##########
@@ -152,17 +152,29 @@ def _copysign_func(c1: Column, c2: Column) -> Column:
 def _fmod_func(c1: Column, c2: Column) -> Column:
     c1_double = c1.cast("double")
     c2_double = c2.cast("double")
+    integral_types = ["tinyint", "smallint", "int", "bigint"]
 
+    # Dispatched on type twice: floating operands need a NaN for a zero 
divisor, and among the
+    # rest, at the end of the branch below, only integral operands can take 
the remainder in
+    # integer space.
     return F.when(
         F.typeof(c1).isin("float", "double") | F.typeof(c2).isin("float", 
"double"),
         F.when(c1.isNull() | F.isnan(c1), c1_double)
         .when(c2.isNull() | F.isnan(c2), c2_double)
         .when(c2_double == 0, F.lit(float("nan")))
         .otherwise(F.try_mod(c1_double, c2_double)),
     ).otherwise(
+        # Non-floating operands, where NumPy normalizes a zero divisor to 0 
instead of a NaN.

Review Comment:
   NumPy always raises on a string column. Ours raises only conditionally: 
`["7", "8"]` computes and returns [1.0, 2.0], while `["7", "abc"]` fails at 
runtime with CAST_INVALID_INPUT, because we cast columns to double at the start 
of the helper function. This PR does not change this part.
   
   Note that the current mapping table doesn't validates dtypes so each entry 
just accepts whatever Spark can cast. If we want to fix this, we may need to 
add dtype check in the mapping table.



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