I cannot understand why resmplU
in the code below is an empty series.
I suspect the problem is I do not understand the role of the parameter nextKey
in the signature of resampleUniform
. The help says it "is used to generate all keys in the range," but I could not figure out what that means.
open Deedle
let dateRange skip (startDate: System.DateTime) endDate =
Seq.initInfinite float
|> Seq.map (fun i -> startDate.AddDays (skip * i))
|> Seq.takeWhile (fun dt -> dt <= endDate)
let dt3 = DateTime(2017,4,1)
let dt4 = DateTime(2017,4,30)
let dt5 = DateTime(2017,4,15)
let dateR = dateRange 2.0 dt3 dt4
let valsR = [1..dateR |> Seq.length]
let tseries = Series(dateR, valsR)
let resmplU =
tseries
|> Series.resampleUniform Lookup.ExactOrGreater (fun x -> x < dt5) id
After running this code I get:
val dt3 : DateTime = 4/1/2017 12:00:00 AM
val dt4 : DateTime = 4/30/2017 12:00:00 AM
val dt5 : DateTime = 4/15/2017 12:00:00 AM
val dateR : seq<DateTime>
val valsR : int list = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15]
val tseries : Series<DateTime,int> =
series [ 4/1/2017 12:00:00 AM => 1; 4/3/2017 12:00:00 AM => 2; 4/5/2017 12:00:00 AM => 3; 4/7/2017 12:00:00 AM => 4; 4/9/2017 12:00:00 AM => 5; ... ; 4/29/2017 12:00:00 AM => 15]
val resmplU : Series<bool,Series<DateTime,int>> = series [ ]
Any insights?
The Series.resampleUniform
function lets you rescale values in a series to a new set of keys. For example, given your series:
01/04/2017 -> 1
03/04/2017 -> 2
05/04/2017 -> 3
07/04/2017 -> 4
09/04/2017 -> 5
11/04/2017 -> 6
13/04/2017 -> 7
15/04/2017 -> 8
17/04/2017 -> 9
19/04/2017 -> 10
21/04/2017 -> 11
23/04/2017 -> 12
25/04/2017 -> 13
27/04/2017 -> 14
29/04/2017 -> 15
You can resample the series so that the keys are days in the month from 1 to 29. For each key (day), you will get values on that specific day, or values on the next day for which they are available:
tseries
|> Series.resampleUniform Lookup.ExactOrGreater (fun dt -> dt.Day) (fun d -> d + 1)
The first function dt -> dt.Day
turns keys from the original series into keys in the new series (to illustrate how this works, I'm using int
as keys for the returned series) and the second function d -> d + 1
calculates the next key of the target series.
EDIT I think the problem with your idea of using bool
as the key is that the resampling function needs to calculate one more key after the two keys in the series you want to get - so that it can make sure it reached the end. This does not work for bool
as there are only two values. The following works though:
tseries
|> Series.resampleUniform Lookup.ExactOrGreater
(fun x -> if x < dt5 then 0 else 1) (fun n -> n + 1)