DEPR: Series and Index shouldn't do inference on pandas objects (original) (raw)

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