Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/pyspark/sql/classic/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ def dropna(
if how is not None and how not in ["any", "all"]:
raise PySparkValueError(
errorClass="VALUE_NOT_ANY_OR_ALL",
messageParameters={"arg_name": "how", "arg_type": how},
messageParameters={"arg_name": "how", "arg_value": how},
)

if subset is None:
Expand Down
2 changes: 1 addition & 1 deletion python/pyspark/sql/connect/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ def dropna(
min_non_nulls = None
else:
raise PySparkValueError(
errorClass="CANNOT_BE_EMPTY",
errorClass="VALUE_NOT_ANY_OR_ALL",
messageParameters={"arg_name": "how", "arg_value": str(how)},
)

Expand Down
11 changes: 11 additions & 0 deletions python/pyspark/sql/tests/test_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from pyspark.errors import (
AnalysisException,
PySparkTypeError,
PySparkValueError,
)
from pyspark.testing.sqlutils import ReusedSQLTestCase

Expand Down Expand Up @@ -127,6 +128,16 @@ def test_dropna(self):
},
)

# Regression test: invalid 'how' should raise PySparkValueError, not AssertionError

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the 'not AssertionError' here mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this fix, invalid 'how' values would raise an AssertionError instead of the intended PySparkValueError.

with self.assertRaises(PySparkValueError) as pe:
self.spark.createDataFrame([("Alice", 50, 80.1)], schema).dropna(how="foo")

self.check_error(
exception=pe.exception,
errorClass="VALUE_NOT_ANY_OR_ALL",
messageParameters={"arg_name": "how", "arg_value": "foo"},
)

def test_fillna(self):
schema = StructType(
[
Expand Down