Skip to content

Commit 1e4750e

Browse files
zhengruifengHyukjinKwon
authored andcommitted
[SPARK-47500][PYTHON][CONNECT][FOLLOWUP] Restore error message for DataFrame.select(None)
### What changes were proposed in this pull request? the refactor PR #45636 changed the error message of `DataFrame.select(None)` from `PySparkTypeError` to `AssertionError`, this PR restore the previous error message ### Why are the changes needed? error message improvement ### Does this PR introduce _any_ user-facing change? yes, error message improvement ### How was this patch tested? added test ### Was this patch authored or co-authored using generative AI tooling? no Closes #46930 from zhengruifeng/py_restore_select_error. Authored-by: Ruifeng Zheng <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent 3fe6abd commit 1e4750e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

python/pyspark/sql/connect/dataframe.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ def select(self, __cols: Union[List[Column], List[str]]) -> ParentDataFrame:
223223
def select(self, *cols: "ColumnOrName") -> ParentDataFrame: # type: ignore[misc]
224224
if len(cols) == 1 and isinstance(cols[0], list):
225225
cols = cols[0]
226+
if any(not isinstance(c, (str, Column)) for c in cols):
227+
raise PySparkTypeError(
228+
error_class="NOT_LIST_OF_COLUMN_OR_STR",
229+
message_parameters={"arg_name": "columns"},
230+
)
226231
return DataFrame(
227232
plan.Project(self._plan, [F._to_col(c) for c in cols]),
228233
session=self._session,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from pyspark.errors.exceptions.base import SessionNotSameException
2222
from pyspark.sql.types import Row
2323
from pyspark.testing.connectutils import should_test_connect
24+
from pyspark.errors import PySparkTypeError
2425
from pyspark.errors.exceptions.connect import AnalysisException
2526
from pyspark.sql.tests.connect.test_connect_basic import SparkConnectSQLTestCase
2627

@@ -214,6 +215,16 @@ def test_column_cannot_be_constructed_from_string(self):
214215
with self.assertRaises(TypeError):
215216
Column("col")
216217

218+
def test_select_none(self):
219+
with self.assertRaises(PySparkTypeError) as e1:
220+
self.connect.range(1).select(None)
221+
222+
self.check_error(
223+
exception=e1.exception,
224+
error_class="NOT_LIST_OF_COLUMN_OR_STR",
225+
message_parameters={"arg_name": "columns"},
226+
)
227+
217228

218229
if __name__ == "__main__":
219230
from pyspark.sql.tests.connect.test_connect_error import * # noqa: F401

0 commit comments

Comments
 (0)