Skip to content

[SPARK-57964][PYSPARK] Fix DataFrame.dropna VALUE_NOT_ANY_OR_ALL parameter name mismatch#57135

Closed
marcuslin123 wants to merge 2 commits into
apache:masterfrom
marcuslin123:SPARK-57964-fix-dropna-error
Closed

[SPARK-57964][PYSPARK] Fix DataFrame.dropna VALUE_NOT_ANY_OR_ALL parameter name mismatch#57135
marcuslin123 wants to merge 2 commits into
apache:masterfrom
marcuslin123:SPARK-57964-fix-dropna-error

Conversation

@marcuslin123

@marcuslin123 marcuslin123 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Fix the messageParameters key in DataFrame.dropna validation from arg_type to arg_value, matching the VALUE_NOT_ANY_OR_ALL error template which interpolates <arg_value>.

Also fix the Spark Connect dropna implementation which used the wrong error class (CANNOT_BE_EMPTY instead of VALUE_NOT_ANY_OR_ALL) with mismatched parameters, making both classic and Connect paths consistent.

Why are the changes needed?

df.dropna(how="foo") is meant to raise a clear PySparkValueError saying "Value for how must be 'any' or 'all', got 'foo'." Instead, the mismatch between the template placeholder (<arg_value>) and the provided parameter key (arg_type) causes an internal assertion failure, surfacing an opaque AssertionError to the user.

The Connect path had a similar issue — it used CANNOT_BE_EMPTY (which expects <item>) but passed {"arg_name": ..., "arg_value": ...}, also resulting in an AssertionError.

Does this PR introduce any user-facing change?

Yes. Users who pass an invalid how argument to DataFrame.dropna will now see (in both classic and Connect modes):

PySparkValueError: [VALUE_NOT_ANY_OR_ALL] Value for `how` must be 'any' or 'all', got 'foo'.

Instead of the previous opaque AssertionError.

How was this patch tested?

Added a regression test in test_stat.py within the existing test_dropna method that verifies dropna(how="foo") raises PySparkValueError with the correct error class and parameters.

Was this patch authored or co-authored using generative AI tooling?

Generative AI tooling (Claude Code) was used as an assistive tool for implementation guidance.

},
)

# 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.

@zhengruifeng zhengruifeng requested a review from HyukjinKwon July 9, 2026 04:59
zhengruifeng pushed a commit that referenced this pull request Jul 10, 2026
…eter name mismatch

### What changes were proposed in this pull request?

Fix the `messageParameters` key in `DataFrame.dropna` validation from `arg_type` to `arg_value`, matching the `VALUE_NOT_ANY_OR_ALL` error template which interpolates `<arg_value>`.

Also fix the Spark Connect `dropna` implementation which used the wrong error class (`CANNOT_BE_EMPTY` instead of `VALUE_NOT_ANY_OR_ALL`) with mismatched parameters, making both classic and Connect paths consistent.

### Why are the changes needed?

`df.dropna(how="foo")` is meant to raise a clear `PySparkValueError` saying "Value for `how` must be 'any' or 'all', got 'foo'." Instead, the mismatch between the template placeholder (`<arg_value>`) and the provided parameter key (`arg_type`) causes an internal assertion failure, surfacing an opaque `AssertionError` to the user.

The Connect path had a similar issue — it used `CANNOT_BE_EMPTY` (which expects `<item>`) but passed `{"arg_name": ..., "arg_value": ...}`, also resulting in an `AssertionError`.

### Does this PR introduce _any_ user-facing change?

Yes. Users who pass an invalid `how` argument to `DataFrame.dropna` will now see (in both classic and Connect modes):

```
PySparkValueError: [VALUE_NOT_ANY_OR_ALL] Value for `how` must be 'any' or 'all', got 'foo'.
```

Instead of the previous opaque `AssertionError`.

### How was this patch tested?

Added a regression test in `test_stat.py` within the existing `test_dropna` method that verifies `dropna(how="foo")` raises `PySparkValueError` with the correct error class and parameters.

### Was this patch authored or co-authored using generative AI tooling?

Generative AI tooling (Claude Code) was used as an assistive tool for implementation guidance.

Closes #57135 from marcuslin123/SPARK-57964-fix-dropna-error.

Lead-authored-by: Marcus Lin <193166030+marcuslin123@users.noreply.github.com>
Co-authored-by: marcus <marcuslin@berkeley.edu>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
(cherry picked from commit 8e13ddb)
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
@zhengruifeng

Copy link
Copy Markdown
Contributor

Merge Summary:

Posted by merge_spark_pr.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants