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: dt64.astype(period) allowed but not vice-versa #45038

Closed
jbrockmendel opened this issue Dec 24, 2021 · 4 comments · Fixed by #45055
Closed

BUG: dt64.astype(period) allowed but not vice-versa #45038

jbrockmendel opened this issue Dec 24, 2021 · 4 comments · Fixed by #45055
Labels
API - Consistency Internal Consistency of API/Behavior Dtype Conversions Unexpected or buggy dtype conversions Period Period data type
Milestone

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Dec 24, 2021

import pandas as pd

dti = pd.date_range("2016-01-01", periods=3)
pi = dti.to_period("D")

dti.astype(pi.dtype)  # <- OK
pi.astype(dti.dtype)  # <- works but deprecated in #44398

pd.Series(dti).astype(pi.dtype)  # <- OK
pd.Series(pi).astype(dti.dtype)  # <- raises

In #44398 we deprecated PeriodIndex.astype(dt64). The motivation was that PeriodIndex.astype should be consistent with Series[Period].astype. I chose to deprecate the PeriodIndex behavior instead of allow it in Series.astype bc there's an optional keyword in PeriodIndex.astype that we're deprecating anyway.

I'm having seconds thoughts based on the fact that we do support Series[dt64].astype(period), and it seems like these should be able to round-trip.

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member Blocker for rc Blocking issue or pull request for release candidate labels Dec 24, 2021
@jbrockmendel
Copy link
Member Author

Added blocker label bc if we want to un-deprecate it will need to be before the release.

@jbrockmendel jbrockmendel added Dtype Conversions Unexpected or buggy dtype conversions Period Period data type API - Consistency Internal Consistency of API/Behavior and removed Needs Triage Issue that has not been reviewed by a pandas team member Bug labels Dec 24, 2021
@jreback
Copy link
Contributor

jreback commented Dec 24, 2021

i think fine to undeprecate and match the series behavior here.

@jbrockmendel
Copy link
Member Author

i think fine to undeprecate and match the series behavior here.

So we're clear: the existing deprecation, when enforced, will change the PeriodIndex behavior to match the Series[Period] behavior. This issue is suggesting we 1) un-deprecate and 2) change the Series[Period] behavior to match the PeriodIndex behavior.

@jbrockmendel
Copy link
Member Author

putting together a branch now to Just Do It.

@jreback jreback added this to the 1.4 milestone Dec 27, 2021
@simonjayhawkins simonjayhawkins removed the Blocker for rc Blocking issue or pull request for release candidate label Jan 4, 2022
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 Dtype Conversions Unexpected or buggy dtype conversions Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants