ENH: Add errors='coerce' to DataFrame.astype / Series.astype (GH#48781)#65851
Open
berasaikat wants to merge 4 commits into
Open
ENH: Add errors='coerce' to DataFrame.astype / Series.astype (GH#48781)#65851berasaikat wants to merge 4 commits into
berasaikat wants to merge 4 commits into
Conversation
Dr-Irv
requested changes
Jun 10, 2026
Dr-Irv
left a comment
Contributor
There was a problem hiding this comment.
I only reviewed pandas/_typing.py
|
|
||
| # Shared by functions such as drop and astype | ||
| IgnoreRaise: TypeAlias = Literal["ignore", "raise"] | ||
| IgnoreRaiseCoerce: TypeAlias = Literal["ignore", "raise", "coerce"] |
Contributor
There was a problem hiding this comment.
Suggested change
| IgnoreRaiseCoerce: TypeAlias = Literal["ignore", "raise", "coerce"] | |
| IgnoreRaiseCoerce: TypeAlias = IgnoreRaise | Literal["coerce"] |
Dr-Irv
approved these changes
Jun 10, 2026
Dr-Irv
left a comment
Contributor
There was a problem hiding this comment.
I approve the changes to pandas/_typing.py. Others will need to approve the rest of this.
Member
|
Possible xref #45588. Can you see if this helps accomplish that? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #48781
Add
errors='coerce'as a option. Unconvertible values are replaced with the dtype's NA sentinel instead of raising:Files changed
pandas/_typing.py— addIgnoreRaiseCoercepandas/core/dtypes/astype.py—astype_array_safecoerce branch +_coerce_to_nahelperpandas/core/generic.py— widenerrorstype + docstring + examplespandas/core/internals/blocks.py— widenerrorstypepandas/tests/frame/methods/test_astype.py—TestAstypeCoercepandas/tests/series/methods/test_astype.py—TestSeriesAstypeCoercedoc/source/whatsnew/v3.1.0.rst— enhancement entryChecklist
TestAstypeCoerce(DataFrame) andTestSeriesAstypeCoerce(Series) covering: float coerce, nullableFloat64/Int64, datetime, dict-dtype, all-valid parity witherrors='raise', and invaliderrors=kwargerrorsoption description and examples