Spenserrrr commented on code in PR #58319:
URL: https://github.com/apache/spark/pull/58319#discussion_r3876682978
##########
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:
I also flattened the dispatch here to match your suggestion on #58306, with
one branch per operand type.
One thing I noticed while doing it: NumPy raises on Decimal objects too, so
the decimal branch has no NumPy behavior to match. I kept your original answer
there, which is 0 for a zero divisor and the remainder in double. I think
fixing it properly needs the same dtype check as the string case.
--
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]