Skip to content

ENH: Add use_nullable_dtypes to to_numeric #50505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 10, 2023
Merged

Conversation

phofl
Copy link
Member

@phofl phofl commented Dec 30, 2022

I think to_numeric should be able to return nullable dtypes as well, similar to our I/O functions

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

  1. Could you add tests that exercises the errors keyword argument?

@mroeschke mroeschke added the NA - MaskedArrays Related to pd.NA and nullable extension arrays label Jan 3, 2023
@phofl
Copy link
Member Author

phofl commented Jan 4, 2023

Thx, this found a couple of bugs

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Can you add a test where use_nullable_dtype=True is specified but the input already is a nullable array?

Comment on lines +252 to +253
if mask is None:
mask = new_mask
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if mask is None:
mask = new_mask
if mask is None:
mask = new_mask
else:
mask = mask.copy()

and then remove the .copy() below when constructing the array (right now the mask is always copied, but assuming this newly generated mask doesn't need that)

Copy link
Member Author

Choose a reason for hiding this comment

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

DOne

@phofl
Copy link
Member Author

phofl commented Jan 6, 2023

Added a test and found a problem for BooleanArray

@mroeschke mroeschke added this to the 2.0 milestone Jan 9, 2023
@phofl
Copy link
Member Author

phofl commented Jan 10, 2023

Merging for now, happy to address additional comments in a follow up

@phofl phofl merged commit bad3774 into pandas-dev:main Jan 10, 2023
@phofl phofl deleted the to_numeric branch January 10, 2023 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Cast string dtype to nullable numeric types in to_numeric
3 participants