Skip to content

Commit 78aa3e0

Browse files
committed
[SPARK-58214][PYTHON] Consolidate VALUE_NOT_PEARSON into VALUE_NOT_ALLOWED
### What changes were proposed in this pull request? Consolidate the specialized PySpark `VALUE_NOT_PEARSON` error condition into `VALUE_NOT_ALLOWED`. Classic and Spark Connect `DataFrame.stat.corr` now report the generic condition when `method` is not `pearson`. The Spark Connect statistics test asserts the new condition. ### Why are the changes needed? `VALUE_NOT_PEARSON` only represents a single allowed argument value and duplicates the generic allowed-values condition. Removing it reduces narrowly scoped error conditions and aligns the validation with other PySpark APIs. ### Does this PR introduce _any_ user-facing change? Yes. Invalid `DataFrame.stat.corr(..., method=...)` calls now use `VALUE_NOT_ALLOWED` and its generic message. The exception type remains `PySparkValueError`. ### How was this patch tested? Updated the Spark Connect statistics test assertion. The focused PySpark test suite was not run. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Codex (GPT-5) Closes #57366 from zhengruifeng/value-not-allowed-dev1. Authored-by: Ruifeng Zheng <ruifengz@apache.org> Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
1 parent 2347165 commit 78aa3e0

4 files changed

Lines changed: 12 additions & 16 deletions

File tree

python/pyspark/errors/error-conditions.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,11 +1208,6 @@
12081208
"Value for `<arg_name>` must be a non-empty string, got '<arg_value>'."
12091209
]
12101210
},
1211-
"VALUE_NOT_PEARSON": {
1212-
"message": [
1213-
"Value for `<arg_name>` only supports 'pearson', got '<arg_value>'."
1214-
]
1215-
},
12161211
"VALUE_NOT_PLAIN_COLUMN_REFERENCE": {
12171212
"message": [
12181213
"Value `<val>` in `<field_name>` should be a plain column reference such as `df.col` or `col('column')`."

python/pyspark/sql/classic/dataframe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,8 +1693,8 @@ def corr(self, col1: str, col2: str, method: Optional[str] = None) -> float:
16931693
method = "pearson"
16941694
if not method == "pearson":
16951695
raise PySparkValueError(
1696-
errorClass="VALUE_NOT_PEARSON",
1697-
messageParameters={"arg_name": "method", "arg_value": method},
1696+
errorClass="VALUE_NOT_ALLOWED",
1697+
messageParameters={"arg_name": "method", "allowed_values": "['pearson']"},
16981698
)
16991699
return self._jdf.stat().corr(col1, col2, method)
17001700

python/pyspark/sql/connect/dataframe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,8 +1663,8 @@ def corr(self, col1: str, col2: str, method: Optional[str] = None) -> float:
16631663
method = "pearson"
16641664
if not method == "pearson":
16651665
raise PySparkValueError(
1666-
errorClass="VALUE_NOT_PEARSON",
1667-
messageParameters={"arg_name": "method", "arg_value": method},
1666+
errorClass="VALUE_NOT_ALLOWED",
1667+
messageParameters={"arg_name": "method", "allowed_values": "['pearson']"},
16681668
)
16691669
table, _ = DataFrame(
16701670
plan.StatCorr(child=self._plan, col1=col1, col2=col2, method=method),

python/pyspark/sql/tests/connect/test_connect_stat.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,14 @@ def test_stat_corr(self):
214214
"arg_type": "int",
215215
},
216216
)
217-
with self.assertRaises(ValueError) as context:
218-
(self.connect.read.table(self.tbl_name2).stat.corr("col1", "col3", "spearman"),)
219-
self.assertTrue(
220-
"Currently only the calculation of the Pearson Correlation "
221-
+ "coefficient is supported."
222-
in str(context.exception)
223-
)
217+
with self.assertRaises(PySparkValueError) as pe:
218+
self.connect.read.table(self.tbl_name2).stat.corr("col1", "col3", "spearman")
219+
220+
self.check_error(
221+
exception=pe.exception,
222+
errorClass="VALUE_NOT_ALLOWED",
223+
messageParameters={"arg_name": "method", "allowed_values": "['pearson']"},
224+
)
224225

225226
def test_stat_approx_quantile(self):
226227
# SPARK-41069: Test the stat.approxQuantile method

0 commit comments

Comments
 (0)