The help for function Series.hasNot
in Deedle
says:
Returns true when the series does not contains value for the specified key
The function does not seem to be working this way in the following example:
let election =
[ "Party A", 304
"Party B", 25
"Party C", 570
"Party Y", 2
"Party Z", 258 ]
|> series
let bhnt =
election
|> Series.hasNot "Party A"
printfn "%A" <| bhnt
// true
// val bhnt : bool = true
// val it : unit = ()
Am I missing something?
I just looked at the Deedle source and saw the following:
let has key (series:Series<'K, 'T>) = series.TryGet(key).HasValue
let hasNot key (series:Series<'K, 'T>) = series.TryGet(key).HasValue
Yes, you've found a bug. The hasNot
function should have looked like not (series.TryGet(key).HasValue)
.
Workaround: Until this bug is fixed, you can work around it by replacing all occurrences of Series.hasNot key
in your code by Series.has key
and then piping through the not
function. E.g.,
let bhnt =
election
|> Series.has "Party A"
|> not
Or, if you think it looks better, you could also write that as:
let bhnt =
election
|> (not << Series.has "Party A")
These two ways of writing it are equivalent; which one you prefer to use will depend on how comfortable you are with functional programming. Some people find the <<
syntax more natural to read, while others find it completely weird and want to stick to using only |>
. It all depends on how experienced you are with functional programming; pick whichever of these two feels the most natural to you.