3

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?

Soldalma
  • 4,636
  • 3
  • 25
  • 38
  • 1
    Updated my comment with a workaround you can use until this bug is fixed in Deedle. – rmunn Mar 29 '17 at 02:44
  • The bugfix for this [has been merged into Deedle master](https://github.com/fslaborg/Deedle/issues/360#event-1720300141), so the next Deedle release should have this fixed. I don't have any information on when that release will be since I'm not part of the Deedle project, but you could check back at https://github.com/fslaborg/Deedle every so often to watch for a new release. – rmunn Jul 08 '18 at 07:56

1 Answers1

5

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.

rmunn
  • 34,942
  • 10
  • 74
  • 105