@@ -248,16 +248,21 @@ def truediv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
248
248
if not is_valid_operand_for_numeric_arithmetic (right ):
249
249
raise TypeError ("True division can not be applied to given types." )
250
250
251
- right = transform_boolean_operand_to_numeric (right , spark_type = left .spark .data_type )
252
-
253
251
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 )
260
264
265
+ right = transform_boolean_operand_to_numeric (right , spark_type = left .spark .data_type )
261
266
return numpy_column_op (truediv )(left , right )
262
267
263
268
def floordiv (self , left : IndexOpsLike , right : Any ) -> SeriesOrIndex :
@@ -337,12 +342,22 @@ def truediv(self, left: IndexOpsLike, right: Any) -> SeriesOrIndex:
337
342
raise TypeError ("True division can not be applied to given types." )
338
343
339
344
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 )
346
361
347
362
right = transform_boolean_operand_to_numeric (right , spark_type = left .spark .data_type )
348
363
return numpy_column_op (truediv )(left , right )
0 commit comments