Skip to content

Commit 43a6e47

Browse files
committed
able to switch
1 parent b8f4287 commit 43a6e47

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

python/pyspark/pandas/data_type_ops/num_ops.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,21 @@ def truediv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
248248
if not is_valid_operand_for_numeric_arithmetic(right):
249249
raise TypeError("True division can not be applied to given types.")
250250

251-
right = transform_boolean_operand_to_numeric(right, spark_type=left.spark.data_type)
252-
253251
def truediv(left: PySparkColumn, right: Any) -> PySparkColumn:
254-
return F.when(
255-
right == 0,
256-
F.when(left < 0, F.lit(float("-inf")))
257-
.when(left > 0, F.lit(float("inf")))
258-
.otherwise(F.lit(np.nan)),
259-
).otherwise(left / right)
252+
if not get_option("compute.ansi_mode_support"):
253+
return F.when(
254+
F.lit(right != 0) | F.lit(right).isNull(),
255+
left.__div__(right),
256+
).otherwise(F.lit(np.inf).__div__(left))
257+
else:
258+
return F.when(
259+
right == 0,
260+
F.when(left < 0, F.lit(float("-inf")))
261+
.when(left > 0, F.lit(float("inf")))
262+
.otherwise(F.lit(np.nan)),
263+
).otherwise(left / right)
260264

265+
right = transform_boolean_operand_to_numeric(right, spark_type=left.spark.data_type)
261266
return numpy_column_op(truediv)(left, right)
262267

263268
def floordiv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
@@ -337,12 +342,22 @@ def truediv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
337342
raise TypeError("True division can not be applied to given types.")
338343

339344
def truediv(left: PySparkColumn, right: Any) -> PySparkColumn:
340-
return F.when(
341-
right == 0,
342-
F.when(left < 0, F.lit(float("-inf")))
343-
.when(left > 0, F.lit(float("inf")))
344-
.otherwise(F.lit(np.nan)),
345-
).otherwise(left / right)
345+
if not get_option("compute.ansi_mode_support"):
346+
return F.when(
347+
F.lit(right != 0) | F.lit(right).isNull(),
348+
left.__div__(right),
349+
).otherwise(
350+
F.when(F.lit(left == np.inf) | F.lit(left == -np.inf), left).otherwise(
351+
F.lit(np.inf).__div__(left)
352+
)
353+
)
354+
else:
355+
return F.when(
356+
right == 0,
357+
F.when(left < 0, F.lit(float("-inf")))
358+
.when(left > 0, F.lit(float("inf")))
359+
.otherwise(F.lit(np.nan)),
360+
).otherwise(left / right)
346361

347362
right = transform_boolean_operand_to_numeric(right, spark_type=left.spark.data_type)
348363
return numpy_column_op(truediv)(left, right)

0 commit comments

Comments
 (0)