-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[SPARK-52570][PS] Enable divide-by-zero for numeric rmod with ANSI enabled #51275
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
Conversation
spark_session = left._internal.spark_frame.sparkSession | ||
|
||
def safe_mod(left_col: PySparkColumn, right_val: Any) -> PySparkColumn: | ||
if is_ansi_mode_enabled(spark_session): |
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.
Just curious why don't we need to check ansi_mode here anymore?
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.
Bools are considered numeric and will take num_ops logic if that makes sense
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.
Merged to unblock prs, please let me know if you have further concerns :)
Merged to master, thanks! |
@@ -225,11 +225,12 @@ def test_binary_operator_floordiv(self): | |||
|
|||
def test_binary_operator_mod(self): | |||
# Positive | |||
pdf = pd.DataFrame({"a": [3], "b": [2]}) | |||
pdf = pd.DataFrame({"a": [3], "b": [2], "c": [0]}) |
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.
Seems like this change broke the non ANSI mode:
======================================================================
ERROR [4.586s]: test_binary_operator_mod (pyspark.pandas.tests.computation.test_binary_ops.FrameBinaryOpsTests.test_binary_operator_mod)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/__w/spark/spark/python/pyspark/pandas/tests/computation/test_binary_ops.py", line 233, in test_binary_operator_mod
self.assert_eq(1 % psdf["c"], 1 % pdf["c"])
~~^~~~~~~~~~~
File "/__w/spark/spark/python/pyspark/pandas/base.py", line 386, in __rmod__
return self._dtype_op.rmod(self, other)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/__w/spark/spark/python/pyspark/pandas/data_type_ops/num_ops.py", line 177, in rmod
return column_op(safe_rmod)(left, right)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/__w/spark/spark/python/pyspark/pandas/base.py", line 222, in wrapper
scol = f(
^^
File "/__w/spark/spark/python/pyspark/pandas/data_type_ops/num_ops.py", line 175, in safe_rmod
return ((right % left) + left) % left
~~~~~~^~~~~~
File "/__w/spark/spark/python/pyspark/pandas/base.py", line 386, in __rmod__
return self._dtype_op.rmod(self, other)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/__w/spark/spark/python/pyspark/pandas/data_type_ops/num_ops.py", line 177, in rmod
return column_op(safe_rmod)(left, right)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/__w/spark/spark/python/pyspark/pandas/base.py", line 222, in wrapper
scol = f(
^^
File "/__w/spark/spark/python/pyspark/pandas/data_type_ops/num_ops.py", line 175, in safe_rmod
return ((right % left) + left) % left
~~~~~~^~~~~~
File "/__w/spark/spark/python/pyspark/pandas/base.py", line 386, in __rmod__
return self._dtype_op.rmod(self, other)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/__w/spark/spark/python/pyspark/pandas/data_type_ops/num_ops.py", line 177, in rmod
return column_op(safe_rmod)(left, right)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/__w/spark/spark/python/pyspark/pandas/base.py", line 222, in wrapper
scol = f(
^^
https://github.com/apache/spark/actions/runs/15987607479/job/45094971366
Let me revert it for now.
What changes were proposed in this pull request?
Enable divide-by-zero for numeric rmod 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.
How was this patch tested?
Unit tests.
Was this patch authored or co-authored using generative AI tooling?
No.