sryza/spark-timeseries

location at or before a certain date/time

Closed this issue · 3 comments

I have a requirement for finding the location in a DateTimeIndex that either matches a given date/time, or is the most recent date/time before the provided date/time. I use this, among other things, when taking lags of an irregular time series: I want to get the value that occurred the closest to, or equal to, 1 minute ago (for example) from a given sample.

I also have the "opposite" requirement, i.e. finding the location at or immediately after a certain date/time. In particular I use this to find the starting point of the new DateTimeIndex after truncation due to taking differences.

I noticed that you have an insertionLoc, but unfortunately this insertionLoc returns the first location that is strictly more recent than the provided date/time (rather than equal to or greater) -- which is not exactly what I need.

I implemented the solution to these 2 requirements and I propose adding them to the repository.

sryza commented

@souellette-faimdata adding a locAtOrBeforeDateTime function seems reasonable to me.

What about a locAtOrAfterDateTime? It does what insertionLoc does, but for "greater or equal" rather than "strictly greater".

sryza commented

That sounds reasonable as well.