Skip to content

Commit fb339f0

Browse files
committed
fix
1 parent 763db74 commit fb339f0

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

python/pyspark/pandas/data_type_ops/num_ops.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ def truediv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
252252

253253
def truediv(left: PySparkColumn, right: Any) -> PySparkColumn:
254254
return F.when(
255-
right_col == 0,
256-
F.when(left_col < 0, F.lit(float("-inf")))
257-
.when(left_col > 0, F.lit(float("inf")))
255+
right == 0,
256+
F.when(left < 0, F.lit(float("-inf")))
257+
.when(left > 0, F.lit(float("inf")))
258258
.otherwise(F.lit(np.nan)),
259-
).otherwise(left_col / right_col)
259+
).otherwise(left / right)
260260

261261
return numpy_column_op(truediv)(left, right)
262262

@@ -336,15 +336,13 @@ def truediv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
336336
if not is_valid_operand_for_numeric_arithmetic(right):
337337
raise TypeError("True division can not be applied to given types.")
338338

339-
def truediv(left_col: PySparkColumn, right_val: Any) -> PySparkColumn:
339+
def truediv(left: PySparkColumn, right: Any) -> PySparkColumn:
340340
return F.when(
341-
F.lit(right_val != 0) | F.lit(right_val).isNull(),
342-
left_col / right_val,
343-
).otherwise(
344-
F.when(
345-
(left_col == float("inf")) | (left_col == float("-inf")), left_col
346-
).otherwise(float("inf") / left_col)
347-
)
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)
348346

349347
right = transform_boolean_operand_to_numeric(right, spark_type=left.spark.data_type)
350348
return numpy_column_op(truediv)(left, right)

0 commit comments

Comments
 (0)