xinrong-meng commented on code in PR #51209:
URL: https://github.com/apache/spark/pull/51209#discussion_r2155414121
##########
python/pyspark/pandas/data_type_ops/num_ops.py:
##########
@@ -271,13 +271,14 @@ def floordiv(self, left: IndexOpsLike, right: Any) ->
SeriesOrIndex:
_sanitize_list_like(right)
if not is_valid_operand_for_numeric_arithmetic(right):
raise TypeError("Floor division can not be applied to given
types.")
+ spark_session = left._internal.spark_frame.sparkSession
def floordiv(left: PySparkColumn, right: Any) -> PySparkColumn:
return F.when(F.lit(right is np.nan), np.nan).otherwise(
F.when(
F.lit(right != 0) | F.lit(right).isNull(),
F.floor(left.__div__(right)),
- ).otherwise(F.lit(np.inf).__div__(left))
+ ).otherwise(F.try_divide(F.lit(np.inf), left))
Review Comment:
Forgot we need to keep the current error, updated thanks!
##########
python/pyspark/pandas/data_type_ops/num_ops.py:
##########
@@ -369,18 +369,28 @@ def floordiv(self, left: IndexOpsLike, right: Any) ->
SeriesOrIndex:
_sanitize_list_like(right)
if not is_valid_operand_for_numeric_arithmetic(right):
raise TypeError("Floor division can not be applied to given
types.")
+ spark_session = left._internal.spark_frame.sparkSession
def floordiv(left: PySparkColumn, right: Any) -> PySparkColumn:
- return F.when(F.lit(right is np.nan), np.nan).otherwise(
- F.when(
- F.lit(right != 0) | F.lit(right).isNull(),
- F.floor(left.__div__(right)),
- ).otherwise(
- F.when(F.lit(left == np.inf) | F.lit(left == -np.inf),
left).otherwise(
- F.lit(np.inf).__div__(left)
+ if is_ansi_mode_enabled(spark_session):
+ return F.when(F.lit(right is np.nan), F.lit(np.nan)).otherwise(
+ F.when(F.lit(right != 0), F.floor(left /
F.lit(right))).otherwise(
+ F.when(
+ F.lit(left == np.inf) | F.lit(left == -np.inf),
F.lit(left)
+ ).otherwise(F.lit(np.inf).__div__(left))
+ )
+ )
+ else:
+ return F.when(F.lit(right is np.nan), np.nan).otherwise(
Review Comment:
Same as before
--
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]