-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Closed
Labels
ConstructorsSeries/DataFrame/Index/pd.array ConstructorsSeries/DataFrame/Index/pd.array ConstructorsDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversions
Description
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
Metadata
Metadata
Assignees
Labels
ConstructorsSeries/DataFrame/Index/pd.array ConstructorsSeries/DataFrame/Index/pd.array ConstructorsDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversions