Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jbrockmendel opened this issue Oct 24, 2022 · 0 comments
Labels
API - Consistency Internal Consistency of API/Behavior Astype Bug Constructors Series/DataFrame/Index/pd.array Constructors Timeseries

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Oct 24, 2022

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

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member Constructors Series/DataFrame/Index/pd.array Constructors API - Consistency Internal Consistency of API/Behavior Astype labels Oct 24, 2022
@jbrockmendel jbrockmendel added Timeseries and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Astype Bug Constructors Series/DataFrame/Index/pd.array Constructors Timeseries
Projects
None yet
Development

No branches or pull requests

1 participant