Skip to content

API: Series[dt64].astype(dt64tz) vs Datetime(Array|Index)[naive].astype(dt64tz) #37085

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

Closed
jbrockmendel opened this issue Oct 12, 2020 · 2 comments
Labels
API - Consistency Internal Consistency of API/Behavior API Design

Comments

@jbrockmendel
Copy link
Member

dti = pd.date_range("2016-01-01", periods=2)
dtype = dti.tz_localize("US/Pacific").dtype

dta = dti._data
ser = pd.Series(dta)

>>> dta.astype(dtype)   # matches dti.astype(dtype)
<DatetimeArray>
['2016-01-01 00:00:00-08:00', '2016-01-02 00:00:00-08:00']
Length: 2, dtype: datetime64[ns, US/Pacific]

>>> ser.astype(dtype)._values
<DatetimeArray>
['2015-12-31 16:00:00-08:00', '2016-01-01 16:00:00-08:00']
Length: 2, dtype: datetime64[ns, US/Pacific]

Series.astype behavior is defined in DatetimeBlock.astype, is equivalent to dta.tz_localize("UTC").tz_convert(dtype.tz)

@jbrockmendel jbrockmendel added API Design API - Consistency Internal Consistency of API/Behavior labels Oct 12, 2020
@mroeschke
Copy link
Member

xref #33401?

@jbrockmendel
Copy link
Member Author

Yep, good catch. Let's close as duplicate this evening, hopefully get some more eyeballs on this in the interim

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 API Design
Projects
None yet
Development

No branches or pull requests

2 participants