Frame.denseCols中有错误吗?

时间:2017-03-20 19:27:22

标签: f# deedle

Frame.denseCols的Visual Studio 2017快速信息工具提示说"它会跳过任何行中包含缺失值的列。"以下示例似乎暗示:

let dateRange (first:System.DateTime) count frac =
    seq {for i in 0..(count - 1) -> first.AddDays(float i + frac)}

let fifth = Series(dateRange (DateTime(2013,1,1)) 10 0.0, rand 10)
let sixth = Series(dateRange (DateTime(2013,1,1)) 5 0.0, [10.0; 20.0; 30.0; 40.0; 50.0])
let dfR10 = Frame(["fifth"; "sixth"], [fifth; sixth])

let sR1 =
    dfR10
    |> Frame.denseCols
sR1.Keys
// val it : seq<string> = seq ["fifth"; "sixth"]

&#34;第六&#34;列是空的:

sR1.["sixth"]
(* Deedle.MissingValueException: Value at the key sixth is missing
   at Deedle.Series`2.Get(K key) in C:\code\deedle\src\Deedle\Series.fs:line 311
   at <StartupCode$FSI_0167>.$FSI_0167.main@()
Stopped due to error *)

因此,存在包含缺失值的列的键,但相应的系列为空。

另一方面Frame.denseRows似乎工作正常:

let sR2 =
    dfR10
    |> Frame.denseRows
sR2.Keys
// keys from 1/1/2013 to 1/5/2013

因此,包含缺失值的行的键不会显示。

这两个命令之间是否存在不对称,Frame.denseCols的快速信息不正确或我遗失了什么?

1 个答案:

答案 0 :(得分:2)

根据Deedle source code

/// We use the terms _sparse_ and _dense_ to denote series that contain some missing values
/// or do not contain any missing values, respectively. The functions `denseCols` and 
/// `denseRows` return a series that contains only dense columns or rows and all sparse
/// rows or columns are replaced with a missing value. The `dropSparseCols` and `dropSparseRows`
/// functions drop these missing values and return a frame with no missing values.

进一步挖掘denseCols简单来电frame.ColumnsDense

member frame.ColumnsDense = 
    let newData = data.Select(fun _ vect -> 
      // Assuming that the data has all values - which should be an invariant...
      let all = rowIndex.Mappings |> Seq.forall (fun (KeyValue(key, addr)) -> vect.Value.GetObject(addr).HasValue)
      if all then OptionalValue(ObjectSeries(rowIndex, boxVector vect.Value, vectorBuilder, indexBuilder))
      else OptionalValue.Missing )
ColumnSeries(Series(columnIndex, newData, vectorBuilder, indexBuilder))

对我而言,它看起来像所描述的那样 - 如果并非所有值都存在,则返回OptionalValue.Missing