-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Open
Labels
API - ConsistencyInternal Consistency of API/BehaviorInternal Consistency of API/BehaviorAstypeBugConstructorsSeries/DataFrame/Index/pd.array ConstructorsSeries/DataFrame/Index/pd.array ConstructorsDatetimeDatetime data dtypeDatetime data dtype
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
Metadata
Metadata
Assignees
Labels
API - ConsistencyInternal Consistency of API/BehaviorInternal Consistency of API/BehaviorAstypeBugConstructorsSeries/DataFrame/Index/pd.array ConstructorsSeries/DataFrame/Index/pd.array ConstructorsDatetimeDatetime data dtypeDatetime data dtype