closest_time addition to DatetimeIndex (original) (raw)

What do people think of adding a closest_time method to the DatetimeIndex, which will behave a bit like asof but will return the row of the DataFrame (or element of the Series) which is closest to the given time.

I have written code to do this manually (and discussed some Pandas bugs I found while doing this in #2948), but thought it would be a good idea to include it as a built-in method, as it is something which is often needed when dealing with time-series data.

I have a number of questions:

  1. Do you think this is a good idea - and would it be likely to be accepted into Pandas?
  2. Is closest_time a good name? If not, what should it be called?
  3. I was planning to allow closest_time to take an argument of almost any type of date-time (pandas Timestamp, datetime instance, string which can then be processed through dateutil.parser.parse) - does that sound sensible, and within the Pandas design philosophy?

If people think this is a good idea then I'll get started on adapting my code to a proper Pandas method - and writing the appropriate tests etc.