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

ENH add time to DatetimeIndex #3180

Closed
wants to merge 1 commit into from

Conversation

@hayd
Copy link
Contributor

commented Mar 26, 2013

This adds a convenience property (.time) to DatetimeIndex, implementation is not very clever, but it means you can extract an array of time objects similar to .hour et al.

Thoughts?

@jreback

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2013

can you put up a usecase?

@hayd

This comment has been minimized.

Copy link
Contributor Author

commented Mar 26, 2013

In this SO question someone is trying to plot by time of the day, and this seems like a reasonable thing to do. I think I have seen quite a few similar cases, and have been confused that it doesn't exist before.

week/weekofyear/dayhour/minute/nanosecond work in this way...

Also I think if time is available for Timestamp it would be consistent to have it in DatetimeIndex... Saying that, there are a few others also not in DatetimeIndex but in Timestamp, perhaps they should be available as well? (or maybe it's just strange that the above things work in this way...). Hmmm.

@jreback

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2013

I saw that question....but sort of asking whether it might be worthwhile to give back a Timestamp like object here (e.g. a different sub-class, rather than a datetime), or is this overkillish...?

@hayd

This comment has been minimized.

Copy link
Contributor Author

commented Mar 26, 2013

It's a fair point, the other attributes return integer arrays, this would be an object and the implementation won't be efficient on big DatetimeIndexes.

I don't really think it's a problem in the use cases I was be thinking of (e.g. plotting), and you can groupby (or something...) to do "time of day" analysis... (?)

At the moment when you subtract a timestamp from another you get a datetime.timedelta... The delta would be an easier thing to do something like this with, since probably modulo "nanoseconds in a day" is hopelessly naive to get the time... (it probably is overkillage anyways.)

@jreback

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2013

actually I was sort of thinking of timedeltas
in 0.11 we r fully supporting timedelta64[ns] types
not yet a scalar that wraps timedelta64 nor a dedicated index (it's a int64 for now)
just search for timedeltas on issues

in any event I am not that is what u r after here

@jreback

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2013

see #3009 for example

@wesm

This comment has been minimized.

Copy link
Member

commented Apr 8, 2013

Cherry-picked. Thanks

@wesm wesm closed this Apr 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.