Skip to content
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

BUG: mix of int and pd.NA defaults to object dtype #33662

Open
2 tasks done
eddy-geek opened this issue Apr 19, 2020 · 1 comment
Open
2 tasks done

BUG: mix of int and pd.NA defaults to object dtype #33662

eddy-geek opened this issue Apr 19, 2020 · 1 comment
Labels
Constructors Series/DataFrame/Index/pd.array Constructors Dtype Conversions Unexpected or buggy dtype conversions Enhancement ExtensionArray Extending pandas with custom dtypes or arrays. NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Discussion Requires discussion from core team before further action PDEP missing values Issues that would be addressed by the Ice Cream Agreement from the Aug 2023 sprint

Comments

@eddy-geek
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.


Code Sample, a copy-pastable example

On pandas 1.0.3:

df = pd.DataFrame([7,8,9,pd.NA])
print(df.dtypes) 
# 0    object
# dtype: object

Problem description

Creating a DataFrame with mixed int and pd.NA defaults to object instead of Int64

According to @simonjayhawkins in #32931

since pd.NA is experimental, changing the constructor to default to the best possible dtypes using dtypes supporting pd.NA seems reasonable.

Expected Output

pd.DataFrame([7,8,9,pd.NA]).dtypes
# 0    Int64
# dtype: object
@eddy-geek eddy-geek added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 19, 2020
@simonjayhawkins simonjayhawkins added ExtensionArray Extending pandas with custom dtypes or arrays. NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Discussion Requires discussion from core team before further action Constructors Series/DataFrame/Index/pd.array Constructors and removed Needs Triage Issue that has not been reviewed by a pandas team member Bug labels Apr 20, 2020
@TomAugspurger
Copy link
Contributor

We'll need to be a bit careful with this. We don't infer one of the nullable dtypes anywhere other than pd.array yet.

Personally, I'd rather wait for the global option for Series([1, 2]) to return a nullable integer. Then all of Series([1, 2]), Series([1, np.nan]), Series([1, pd.NA]) would return nullable integer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Constructors Series/DataFrame/Index/pd.array Constructors Dtype Conversions Unexpected or buggy dtype conversions Enhancement ExtensionArray Extending pandas with custom dtypes or arrays. NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Discussion Requires discussion from core team before further action PDEP missing values Issues that would be addressed by the Ice Cream Agreement from the Aug 2023 sprint
Projects
None yet
Development

No branches or pull requests

5 participants