Skip to content

BUG: Series(dt64_data, dtype=tzaware) vs Series(dt64_data).astype(tzaware) #49281

Open
@jbrockmendel

Description

@jbrockmendel
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

No one assigned

    Labels

    API - ConsistencyInternal Consistency of API/BehaviorAstypeBugConstructorsSeries/DataFrame/Index/pd.array ConstructorsDatetimeDatetime data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions