-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[WIP][PS] Enable divide-by-zero for boolean floordiv with ANSI enabled #51079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Failed test is irrelevant:
|
@@ -132,7 +128,7 @@ def test_floordiv(self): | |||
self.assertRaises(TypeError, lambda: b_psser // b_psser) | |||
self.assertRaises(TypeError, lambda: b_psser // True) | |||
|
|||
self.assert_eq(b_pser // pdf["float"], b_psser // psdf["float"]) | |||
self.assert_eq((b_pser // pdf["float"]).astype("int"), b_psser // psdf["float"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.floordiv.html, as well as, integers should always be returned.
@ueshin would you please review? |
if isinstance(right, numbers.Number): | ||
left = transform_boolean_operand_to_numeric(left, spark_type=as_spark_type(type(right))) | ||
return left // right |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be a numeric floor. I'm wondering if the numeric devision is ok or not.
I guess we should visit it first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> ps.Series([0,1,2]) // 0
...
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
I guess fixing this will fix the boolean case as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Filed #51209
What changes were proposed in this pull request?
Enable divide-by-zero for boolean floordiv with ANSI enabled
Why are the changes needed?
Ensure pandas on Spark works well with ANSI mode on.
Part of https://issues.apache.org/jira/browse/SPARK-52169.
Does this PR introduce any user-facing change?
Yes
FROM
TO
How was this patch tested?
Unit tests.
Was this patch authored or co-authored using generative AI tooling?
No