Open
Description
import pandas as pd
dti = pd.date_range("2016-01-01", periods=3)
dtype = dti.tz_localize("US/Pacific").dtype
ser = pd.Series(dti.values, dtype=dtype) # <- does not raise
pd.Series(dti.values).astype(dtype) # <- raises
As a general rule, we want Series(data, dtype=dtype)
to behave like Series(data).astype(dtype)
, but that does not hold for datetime64 data with a DatetimeTZDtype.
Options are
a) live with this inconsistency
b) deprecate Series constructor behavior to disallow this (and DatetimeIndex/DatetimeArray along with it)
c) re-allow the .astype casting