Deedle 1.0.7帧行索引不强制使用唯一键

时间:2015-01-30 09:29:35

标签: indexing f# duplicates deedle

自Deedle 1.0.7发布以来,索引行函数不再验证用作键的列是否包含唯一值。这种行为与评论所暗示的不同。如何确保只能将唯一值用作列键?

在以前的版本中,以下代码将触发错误,因为用作索引的列包含重复项。但是在Deedle 1.0.7中不再是这种情况,代码将起作用,框架将包含指向记录数组的1个索引条目。这是设计的吗?

type t1 = {d:DateTime; v:double}

let s1 =[{d=DateTime.Now.Date; v= 1.0};
          {d=DateTime.Now.Date; v= 2.0};
          {d=DateTime.Now.Date; v= 3.0};
         ]

let f1 = Frame.ofRecords s1 |> Frame.indexRowsDate "d"


 type t2 = {d:int; v:double}

 let s2 =[{d=1; v= 1.0};
          {d=1; v= 2.0};
           {d=1; v= 3.0};
         ]

 let f2 = Frame.ofRecords s2 |> Frame.indexRowsInt "d"

但是,如果我尝试访问由重复键索引的系列,则Deedle会给出错误

let cv = f2.GetColumn<double> "v"

let item = cv.Get(1)

val cv : Series<int,double> = series [ 1 => 1; 1 => 2; 1 => 3]

> 
System.ArgumentException: Duplicate key '1'. Duplicate keys are not     allowed in the index.
 Parameter name: keys
   at Deedle.Indices.Linear.LinearIndex`1.makeLookup() in     c:\Tomas\Public\Deedle\src\Deedle\Indices\LinearIndex.fs:line 53

at Deedle.Indices.Linear.LinearIndex 1.get_lookupMap() in c:\Tomas\Public\Deedle\src\Deedle\Indices\LinearIndex.fs:line 63 at Deedle.Indices.Linear.LinearIndex 1.Deedle-Indices-IIndex 1-Locate(K key) in c:\Tomas\Public\Deedle\src\Deedle\Indices\LinearIndex.fs:line 101 at Deedle.Series 2.获取(K键)c:\ Tomas \ Public \ Deedle \ src \ Deedle \ Series .fs:第291行        在。$ FSI_0046.main @()在C:\ Users \ win8dev \ Documents \ Visual Studio 2013 \ Projects \ DeedleTake2 \ Deedle107 \ Script.fsx:第40行      因错误而停止

更新

根据Tomas的建议,Github门票已经提出

https://github.com/BlueMountainCapital/Deedle/issues/294

0 个答案:

没有答案