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

Cannot create DatetimeIndex using Period #6780

Closed
jseabold opened this issue Apr 3, 2014 · 7 comments
Closed

Cannot create DatetimeIndex using Period #6780

jseabold opened this issue Apr 3, 2014 · 7 comments
Labels
Error Reporting Incorrect or improved errors from pandas Frequency DateOffsets Period Period data type
Milestone

Comments

@jseabold
Copy link
Contributor

jseabold commented Apr 3, 2014

This doesn't work. Looks like start and end should try a bit harder to convert to timestamp?

from datetime import datetime
pd.DatetimeIndex(start=pd.Period('1990q1'), end=datetime(1992, 12, 31), freq='Q')

This does.

pd.DatetimeIndex(start=pd.Period('1990q1').to_timestamp(), end=datetime(1992, 12, 31), freq='Q')
@jseabold
Copy link
Contributor Author

jseabold commented Apr 3, 2014

I think the real issue is that Timestamp(period_instance) should work right?

@jreback
Copy link
Contributor

jreback commented Apr 3, 2014

yes it could work
just need to check if it's a Period then do to_timestamp

keeping in mind that it's defaulted to a start of the period

it could be that's why it's not automatic
as it's implicitly do a certain type of conversion eg start of period

@jseabold
Copy link
Contributor Author

jseabold commented Apr 3, 2014

Yeah, I'm not sure what's best there actually. I just ran into another issue comparing datetime to period doesn't work, but it's not clear to me how it should actually work. End vs beginning of period defaults for Period are bound to be controversial.

Maybe it should just raise though maybe with a more informative error message? I don't like it (more work for me), but our code really should be more careful here and there's no real reason to assume beginning vs end of period mapping.

@jreback jreback added this to the 0.15.0 milestone Apr 3, 2014
@jreback
Copy link
Contributor

jreback commented Apr 3, 2014

actually this does report a ValueError that it cannot convert. You think it should have a more informative message....ok..i'll bite (maybe noting that you can use to_timestamp)

@jreback jreback removed the Dtypes label Apr 3, 2014
@jseabold
Copy link
Contributor Author

jseabold commented Apr 3, 2014

Yeah, I was just thinking something like

"Cannot convert Period to Timestamp unambiguously. Use to_timestamp"

@jreback
Copy link
Contributor

jreback commented Apr 3, 2014

sounds good to me

@jreback
Copy link
Contributor

jreback commented Sep 29, 2014

closed by #8405

@jreback jreback closed this as completed Sep 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Frequency DateOffsets Period Period data type
Projects
None yet
Development

No branches or pull requests

2 participants