Is there a bug in Series.hasNot?

The reference for the function Series.hasNot

in Deedle

says:

Returns true when the series does not contains value for the specified key

The function doesn't seem to work 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 = ()

      

Did I miss something?

+3


source to share


1 answer


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 found a bug. The function hasNot

should look like not (series.TryGet(key).HasValue)

.

Workaround: Until this bug is fixed, you can work around it by replacing all occurrences Series.hasNot key

in your code with Series.has key

and then routing through the function not

. For example.



let bhnt =
    election
    |> Series.has "Party A"
    |> not

      

Or, if you think it looks better, you can also write it like:

let bhnt =
    election
    |> (not << Series.has "Party A")

      

These two ways of writing 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 odd and just want to stick with it |>

. It all depends on how experienced you are with functional programming; choose which of these two feels most natural to you.

+5


source







All Articles