Skip to content

BUG: Series dtype not as specified when values are missing #46782

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

Closed
2 of 3 tasks
emmanuelito opened this issue Apr 15, 2022 · 4 comments
Closed
2 of 3 tasks

BUG: Series dtype not as specified when values are missing #46782

emmanuelito opened this issue Apr 15, 2022 · 4 comments
Labels
Constructors Series/DataFrame/Index/pd.array Constructors Dtype Conversions Unexpected or buggy dtype conversions

Comments

@emmanuelito
Copy link

emmanuelito commented Apr 15, 2022

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

# In 1.4.2
import pandas as pd
s = pd.Series( index=[1, 2, 3 ], dtype=int)
s.dtype
# -> dtype('float64') *ouch*

# ---- vs in 1.3.5
s = pd.Series( index=[1, 2, 3 ], dtype=int)
s.dtype
# -> dtype('int64') *correct*

Issue Description

pd.Series() does not respect the specified dtype and breaks compatibility with previous (1.3.5) version.

Expected Behavior

Should be backward compatible with 1.3.5: the result should have the dtype specified by the caller.

This issue seems (I'm not sure) related to #46672

The problem is that missing values (unspecified in the constructor) are initialized to NaNs, and thus floats, whereas in Pandas 1.3.5 they were initialized with zeroes.

Installed Versions

@emmanuelito emmanuelito added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 15, 2022
@jreback
Copy link
Contributor

jreback commented Apr 15, 2022

this was incorrect before and is now fixed

@jreback
Copy link
Contributor

jreback commented Apr 15, 2022

this incorrect before and is now fixed

int cannot hold missing values

@emmanuelito
Copy link
Author

emmanuelito commented Apr 15, 2022

But this modification badly breaks code. Isn't Pandas supposed to be backward compatible ?
IMHO raising an exception would be better than changing the dtype.

@jreback
Copy link
Contributor

jreback commented Apr 15, 2022

the usage has always been wrong

@jreback jreback added this to the No action milestone Apr 15, 2022
@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions Constructors Series/DataFrame/Index/pd.array Constructors and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 15, 2022
@jreback jreback closed this as completed Apr 15, 2022
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
Projects
None yet
Development

No branches or pull requests

2 participants