Skip to content

API/ENH/COMPAT: compat for datetime.time via Timedelta #8343

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 Sep 21, 2014 · 3 comments
Closed

API/ENH/COMPAT: compat for datetime.time via Timedelta #8343

jreback opened this issue Sep 21, 2014 · 3 comments
Labels
API Design Compat pandas objects compatability with Numpy or Python functions Dtype Conversions Unexpected or buggy dtype conversions Internals Related to non-user accessible pandas implementation Timedelta Timedelta data type

Comments

@jreback
Copy link
Contributor

jreback commented Sep 21, 2014

Now that Timedelta is a full fledged type. It is quite trivial to convert a datetime.time to a Timedelta.

pros:

  • highly performant
  • very similar output
  • no need to create a TimeBlock

cons:

  • no longer a datetime.time instance (instead its a sub-class of datetime.timedelta)
  • doesn't support tz(anyone actually use this 'feature')?
  • negative times would be allowed (eg. I think this is not allowed for datetime.time).

So either we go full-fledged and create a Time scalar and TimeBlock (though TimeIndex could work w/o these.). Its possible to also create a TimeBlock and NOT create a Time scalar.

That said creating a Time scalar is very easy and much simpler than Timedelta and shares a lot of code.

In [28]: s = Series([datetime.time(12,0,0),datetime.time(14,1,2),datetime.time(2,0,1)])

In [29]: s
Out[29]: 
0    12:00:00
1    14:01:02
2    02:00:01
dtype: object

In [30]: pd.lib.infer_dtype(s)
Out [30]: 'time'

In [31]: s.iloc[0]
Out[31]: datetime.time(12, 0)

In [32]: s.apply(lambda x: pd.Timedelta(seconds=x.hour*3600+x.minute*60+x.second,microseconds=x.microsecond))
Out[32]: 
0   12:00:00
1   14:01:02
2   02:00:01
dtype: timedelta64[ns]

In [32]: s.apply(lambda x: pd.Timedelta(seconds=x.hour*3600+x.minute*60+x.second,microseconds=x.microsecond)).iloc[0]
Out[32]: Timedelta('0 days 12:00:00')

thoughts?

Is datetime.time really THAT different from datetime.timedelta that it SHOULD be a full-fledged type?

@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions API Design Internals Related to non-user accessible pandas implementation Timedelta Timedelta data type Compat pandas objects compatability with Numpy or Python functions labels Sep 21, 2014
@jreback jreback added this to the 0.15.1 milestone Sep 21, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jorisvandenbossche
Copy link
Member

I am not in favor of this. Although datetime.time can maybe seem as not that useful, it is a different type as timedelta. And if we want to integrate in better into pandas, it should be as a new kind of TimeBlock I think (or we can leave it as object for now ..)

@jreback
Copy link
Contributor Author

jreback commented Jun 11, 2015

ok, this will be very very low priority though. I have never seen a datetime.time in the wild, nor an actual issue involving one (except the one you just posted).

@TomAugspurger
Copy link
Contributor

An ExtensionArray makes more sense for this.

Not clear whether it should go inside pandas or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Compat pandas objects compatability with Numpy or Python functions Dtype Conversions Unexpected or buggy dtype conversions Internals Related to non-user accessible pandas implementation Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

3 participants