Series.hasNot中是否有错误?

Sol*_*lma 3 f# series deedle

对于功能帮助Series.hasNotDeedle说:

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

在以下示例中,该函数似乎没有以这种方式工作:

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 = ()
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

rmu*_*unn 5

我只是看了Deedle的来源,看到了以下内容:

let has key (series:Series<'K, 'T>) = series.TryGet(key).HasValue
let hasNot key (series:Series<'K, 'T>) = series.TryGet(key).HasValue
Run Code Online (Sandbox Code Playgroud)

是的,你发现了一个错误.该hasNot功能应该看起来像not (series.TryGet(key).HasValue).

解决方法:在修复此错误之前,您可以通过替换Series.hasNot key代码中的所有实例来解决此问题Series.has key,然后通过该not函数进行管道处理.例如,

let bhnt =
    election
    |> Series.has "Party A"
    |> not
Run Code Online (Sandbox Code Playgroud)

或者,如果您认为它看起来更好,您也可以将其写为:

let bhnt =
    election
    |> (not << Series.has "Party A")
Run Code Online (Sandbox Code Playgroud)

这两种写作方式是等价的; 你喜欢哪一个取决于你对函数式编程的舒适程度.有些人发现<<语法更自然,而有些人则觉得它很奇怪,只想坚持使用|>.这一切都取决于你对函数式编程的经验; 选择这两者中哪一个对你来说最自然.

  • 我已经提交了https://github.com/BlueMountainCapital/Deedle/pull/361来修复这个bug. (2认同)