Dealing with Missing Values ββin Deedle Time Series in F # (3)
This is another follow-up to Working with Missing Values ββin Deedle Time Series in F # (2)
I wrote this function for the map2 series, returning a missing value when any input is missing.
let map2series (f:'T1->'T2->'R)(series1:Series<'K,'T1 opt>)(series2:Series<'K,'T2 opt>):Series<'K,'R opt>=
let S = series1.Zip(series2,JoinKind.Outer) //Series<'K,('T1 opt opt * 'T2 opt opt)>
S |> Series.mapValues (fun (a,b) -> match (a,b) with
| (OptionalValue.Present(a'), OptionalValue.Present(b')) -> OptionalValue.map2 f a' b'
| _ -> OptionalValue.Missing)
since it Series<'K,'T opt>
naturally appears in Deedle after using the methods .Zip
or .Join
.
However, as seen earlier, it Series<'K,'V>
already supports missing values, so I would like to rewrite the above function that will basically do the same, except that it accepts Series<'K,'V>
as inputs
let map2series1 (f:'T1->'T2->'R)(series1:Series<'K,'T1>)(series2:Series<'K,'T2>):Series<'K,'R>=
let S = series1.Zip(series2,JoinKind.Outer) //Series<'K,('T1 opt * 'T2 opt)>
S |> Series.mapValues (fun (a,b) -> match (a,b) with
| (OptionalValue.Present(a'), OptionalValue.Present(b')) -> f a' b'
| _ -> None)
However this doesn't work, I don't have the correct syntax in the second case of the concatenation when one value is missing ...
basically instead of the latter None
, I need to assign a value that matches <missing>
, but I can't find it.
I also looked at something like
Option.bind OptionalValue.asOption OptionalValue.Missing
but cannot find the correct expression
source to share