Commit b0c2ba3
[SPARK-52249][PS] Enable divide-by-zero for numeric truediv with ANSI enabled
### What changes were proposed in this pull request?
Enable divide-by-zero for truediv with ANSI enabled
### Why are the changes needed?
Part of https://issues.apache.org/jira/browse/SPARK-52169
### Does this PR introduce _any_ user-facing change?
Yes, divide-by-zero for truediv is enabled with ANSI enabled
```py
>>> spark.conf.get("spark.sql.ansi.enabled")
'true'
>>> pdf = pd.DataFrame({"a": [1.0, -1.0, 0.0, np.nan], "b": [0.0, 0.0, 0.0, 0.0]})
>>> psdf = ps.from_pandas(pdf)
```
FROM
```py
>>> psdf["a"] / psdf["b"]
...
pyspark.errors.exceptions.captured.ArithmeticException: [DIVIDE_BY_ZERO] Division by zero. Use `try_divide` to tolerate divisor being 0 and return NULL instead. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error. SQLSTATE: 22012
== DataFrame ==
"__div__" was called from
<stdin>:1
```
TO
```py
>>> psdf["a"] / psdf["b"]
0 inf
1 -inf
2 NaN
3 NaN
dtype: float64
```
### How was this patch tested?
Unit tests
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #50972 from xinrong-meng/divide_0.
Authored-by: Xinrong Meng <xinrong@apache.org>
Signed-off-by: Takuya Ueshin <ueshin@databricks.com>1 parent 73f1dd2 commit b0c2ba3
File tree
3 files changed
+39
-14
lines changed- python/pyspark/pandas
- data_type_ops
- tests/computation
3 files changed
+39
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
247 | 248 | | |
248 | 249 | | |
249 | 250 | | |
| 251 | + | |
| 252 | + | |
250 | 253 | | |
251 | 254 | | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
256 | 267 | | |
257 | | - | |
258 | 268 | | |
259 | 269 | | |
260 | 270 | | |
| |||
332 | 342 | | |
333 | 343 | | |
334 | 344 | | |
| 345 | + | |
| 346 | + | |
335 | 347 | | |
336 | 348 | | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
343 | 364 | | |
344 | | - | |
345 | 365 | | |
346 | | - | |
347 | 366 | | |
348 | 367 | | |
349 | 368 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | 114 | | |
116 | 115 | | |
117 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1070 | 1070 | | |
1071 | 1071 | | |
1072 | 1072 | | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
1073 | 1080 | | |
1074 | 1081 | | |
1075 | 1082 | | |
| |||
0 commit comments