Skip to content

[SPARK-54770][PYTHON] Replace dead assert with proper error in _create_converter#56051

Open
shrirangmhalgi wants to merge 1 commit into
apache:masterfrom
shrirangmhalgi:SPARK-54770-remove-dead-code
Open

[SPARK-54770][PYTHON] Replace dead assert with proper error in _create_converter#56051
shrirangmhalgi wants to merge 1 commit into
apache:masterfrom
shrirangmhalgi:SPARK-54770-remove-dead-code

Conversation

@shrirangmhalgi
Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Replace the unreachable else: assert False branch in LocalDataToArrowConversion._create_converter with a raise AssertionError at function level.

Why are the changes needed?

The else branch was dead code (marked # pragma: no cover) because _need_converter guards entry to the function and every type it returns True for has a corresponding handler in the if/elif chain. The bare assert False inside an else is silently disabled by Python's -O flag. A raise at function level is always active and serves as a safety net if a new type is added to _need_converter without a matching converter branch.

Does this PR introduce any user-facing change?

No. The removed code was unreachable.

How was this patch tested?

Existing Arrow test suite (62 tests pass). The changed code path is unreachable by design.

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

No

…e_converter

The else branch in _create_converter was unreachable (marked pragma: no cover) because _need_converter guards entry and every type it returns True for has a corresponding handler. Replace with a raise at function level that works even with Python -O flag.
@shrirangmhalgi shrirangmhalgi force-pushed the SPARK-54770-remove-dead-code branch from 89c53bd to db1e202 Compare May 22, 2026 02:39
@shrirangmhalgi
Copy link
Copy Markdown
Contributor Author

@gaogaotiantian could you please review the following PR

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.

1 participant