Skip to content

API/ENH: support datetime.time in a Timedelta #8698

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
jreback opened this issue Oct 31, 2014 · 7 comments
Closed

API/ENH: support datetime.time in a Timedelta #8698

jreback opened this issue Oct 31, 2014 · 7 comments
Labels
API Design Enhancement Timedelta Timedelta data type Timezones Timezone data dtype

Comments

@jreback
Copy link
Contributor

jreback commented Oct 31, 2014

So this as expected. Though I its pretty straightforward to add support for this directly to a Timedelta, after the notion is the same, though a time object can support a time-zone so not sure if this is odd (or maybe we should add an optional tz to Timedelta).

In [5]: from datetime import time

In [6]: time(secIn [8]: pd.Timedelta(time(second=1))
ValueError: Value must be Timedelta, string, integer, float, timedelta or convertible

In [9]: pd.Timedelta('1s')          
Out[9]: Timedelta('0 days 00:00:01')
@jreback jreback added Enhancement API Design Timedelta Timedelta data type Timezones Timezone data dtype labels Oct 31, 2014
@jreback jreback added this to the 0.16.0 milestone Oct 31, 2014
@jreback
Copy link
Contributor Author

jreback commented Oct 31, 2014

cc @rockg

@shoyer
Copy link
Member

shoyer commented Oct 31, 2014

Hmm... not so sure this is desirable. This would be assuming that midnight is always zero? And that times are always positive? I think it would probably be better to require users to do this conversion explicitly.

side note: adding time-zones to Timedelta sounds awful!

@jreback
Copy link
Contributor Author

jreback commented Oct 31, 2014

@shoyer hah! just putting it out there if anyone sees a need for this. I added a tests to test that this is not supported, otherwise leaving for now.

@jorisvandenbossche
Copy link
Member

What is the best way to convert a column of times to a timedelta? As

pd.to_timedelta(hours=df['time'].dt.hour, minutes=df['time'].dt.minute, seconds=df['time'].dt.second)

or

df['time'].apply(lambda x: datetime.timedelta(hours=x.hour, minutes=x.minute, seconds=x.second))

seems not very concise

@jreback
Copy link
Contributor Author

jreback commented Jun 11, 2015

actually this is a dupe of #8343

@jreback jreback closed this as completed Jun 11, 2015
@jreback
Copy link
Contributor Author

jreback commented Jun 11, 2015

as I said, I think this type is useless. Those solns's are fine for the very limited amount this comes up. An in-between soln is to allow conversion directly to Timedelta which is not that hard.

@jorisvandenbossche
Copy link
Member

@jreback I think it are two different things, how I understand it.

In this issue, it is proposed that you can provide a datetime.time object to pd.to_timedelta to convert it to a timedelta (just as you can also provide strings, ints, ..). But so, always something a user explicitly does.
#8343 is about integrating datetime.time in the pandas internals as a timedelta (which will lead to automatic conversion of datetime.time to timedeltas), which is a much more profound question (and not something I am in favor of)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Enhancement Timedelta Timedelta data type Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

3 participants