Skip to content

DEPR: Series and Index shouldn't do inference on pandas objects #56012

Closed
@phofl

Description

@phofl

The following changes the dtype, which is unexpected:

idx = pd.Index(pd.date_range("2015-01-01 10:00", freq="D", periods=3), dtype=object)
pd.Index(idx).dtype

this returns datetime64[ns]

Doing inference on a pandas object is pretty weird, this makes stuff very complicated with the new string option. Set_Index can change the dtype, e.g.

df = pd.DataFrame({"a": pd.Series(pd.date_range("2015-01-01 10:00", freq="D", periods=3), dtype=object), "b": 1})
df.dtypes

a    object
b     int64
dtype: object


df.set_index("a").index.dtype
datetime64[ns]

Users can just call infer_objects if they want to do inference. We should keep the inference logic for non-pandas objects

cc @jbrockmendel

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeprecateFunctionality to remove in pandasNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions