Skip to content

Commit eca8c62

Browse files
xinrong-mengHyukjinKwon
authored andcommitted
[SPARK-53427][PS][TESTS] Test divisor 0 in truediv/floordiv/mod tests under ANSI
### What changes were proposed in this pull request? Test divisor 0 in truediv/floordiv/mod tests under ANSI ### Why are the changes needed? Part of https://issues.apache.org/jira/browse/SPARK-53427 ### Does this PR introduce _any_ user-facing change? No, test change only ### How was this patch tested? Commands below passed ``` 1067 SPARK_ANSI_SQL_MODE=true ./python/run-tests --python-executables=python3.11 --testnames "pyspark.pandas.tests.data_type_ops.test_boolean_ops BooleanOpsTests.test_truediv" 1068 SPARK_ANSI_SQL_MODE=false ./python/run-tests --python-executables=python3.11 --testnames "pyspark.pandas.tests.data_type_ops.test_boolean_ops BooleanOpsTests.test_truediv" 1069 SPARK_ANSI_SQL_MODE=true ./python/run-tests --python-executables=python3.11 --testnames "pyspark.pandas.tests.data_type_ops.test_boolean_ops BooleanOpsTests.test_floordiv" 1070 SPARK_ANSI_SQL_MODE=false ./python/run-tests --python-executables=python3.11 --testnames "pyspark.pandas.tests.data_type_ops.test_boolean_ops BooleanOpsTests.test_floordiv" 1071 SPARK_ANSI_SQL_MODE=true ./python/run-tests --python-executables=python3.11 --testnames "pyspark.pandas.tests.data_type_ops.test_boolean_ops BooleanOpsTests.test_mod" 1072 SPARK_ANSI_SQL_MODE=false ./python/run-tests --python-executables=python3.11 --testnames "pyspark.pandas.tests.data_type_ops.test_boolean_ops BooleanOpsTests.test_mod" 1073 SPARK_ANSI_SQL_MODE=true ./python/run-tests --python-executables=python3.11 --testnames "pyspark.pandas.tests.computation.test_binary_ops FrameBinaryOpsTests.test_binary_operator_truediv" 1074 SPARK_ANSI_SQL_MODE=false ./python/run-tests --python-executables=python3.11 --testnames "pyspark.pandas.tests.computation.test_binary_ops FrameBinaryOpsTests.test_binary_operator_truediv" 1007 SPARK_ANSI_SQL_MODE=true ./python/run-tests --python-executables=python3.11 --testnames "pyspark.pandas.tests.data_type_ops.test_num_mod NumModTests.test_mod" 1008 SPARK_ANSI_SQL_MODE=false ./python/run-tests --python-executables=python3.11 --testnames "pyspark.pandas.tests.data_type_ops.test_num_mod NumModTests.test_mod" ``` ### Was this patch authored or co-authored using generative AI tooling? No Closes #52166 from xinrong-meng/ari_test2. Authored-by: Xinrong Meng <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent 59b34dc commit eca8c62

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

python/pyspark/pandas/tests/computation/test_binary_ops.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def test_binary_operator_truediv(self):
196196
pser = pd.Series([1.1, 2.2, 3.3], dtype=np.float32)
197197
psser = ps.from_pandas(pser)
198198
self.assert_eq(psser / 1, pser / 1)
199+
self.assert_eq(psser / 0, pser / 0)
199200

200201
# Negative
201202
psdf = ps.DataFrame({"a": ["x"], "b": [1]})

python/pyspark/pandas/tests/data_type_ops/test_boolean_ops.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def test_truediv(self):
103103
pdf, psdf = self.pdf, self.psdf
104104

105105
b_pser, b_psser = pdf["bool"], psdf["bool"]
106+
self.assert_eq(b_pser / 0, b_psser / 0)
106107
self.assert_eq(b_pser / 1, b_psser / 1)
107108
self.assert_eq(b_pser / 0.1, b_psser / 0.1)
108109
self.assert_eq(b_pser / b_pser.astype(int), b_psser / b_psser.astype(int))
@@ -121,6 +122,7 @@ def test_floordiv(self):
121122

122123
# float is always returned in pandas-on-Spark
123124
self.assert_eq((b_pser // 1).astype("float"), b_psser // 1)
125+
self.assert_eq((b_pser // 0).astype("float"), b_psser // 0)
124126

125127
# in pandas, 1 // 0.1 = 9.0; in pandas-on-Spark, 1 // 0.1 = 10.0
126128
# self.assert_eq(b_pser // 0.1, b_psser // 0.1)
@@ -138,6 +140,7 @@ def test_mod(self):
138140
pdf, psdf = self.pdf, self.psdf
139141

140142
b_pser, b_psser = pdf["bool"], psdf["bool"]
143+
self.assert_eq(b_pser % 0, b_psser % 0)
141144
self.assert_eq(b_pser % 1, b_psser % 1)
142145
self.assert_eq(b_pser % 0.1, b_psser % 0.1)
143146
self.assert_eq(b_pser % b_pser.astype(float), b_psser % b_psser.astype(float))

python/pyspark/pandas/tests/data_type_ops/test_num_mod.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def test_mod(self):
4242
self.assert_eq(pser % pser.astype(bool), psser % psser.astype(bool), check_exact=False)
4343
self.assert_eq(pser % True, psser % True, check_exact=False)
4444
self.assert_eq(pser % 1, psser % 1, check_exact=False)
45+
if not col.startswith("decimal"):
46+
self.assert_eq(pser % 0, psser % 0, check_exact=False)
4547
if col in ["int", "int32"]:
4648
self.assert_eq(
4749
pd.Series([np.nan, np.nan, np.nan], dtype=float, name=col), psser % False

0 commit comments

Comments
 (0)