Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Nitya-Choudhary
Copy link

This PR fixes a bug in pandas.api.types.pandas_dtype where invalid inputs sometimes raised exceptions other than TypeError (e.g., ValueError).

Changes in this PR:

  • Updated the try-except block around np.dtype(dtype) to catch all exceptions and always raise TypeError.

  • Preserves the existing warnings.catch_warnings() context.

  • Ensures consistent behavior for all invalid dtypes, matching pandas’ expected error handling.

  • Added/verified tests to confirm TypeError is raised for invalid dtype inputs.

Motivation / Background:
Previously, only SyntaxError was caught, allowing some invalid inputs to raise unexpected exceptions. This caused inconsistent behavior and test failures in downstream code. This change makes pandas_dtype behavior predictable and fully compliant with the documented TypeError expectation.

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