Skip to content
Permalink
Browse files

Merge pull request #406 from zyzhu/issue-364

Avoid iterating seq multiple times in Frame.ofRecords
  • Loading branch information...
zyzhu committed Mar 21, 2019
2 parents 4afb105 + c05321b commit 3d055db997ee7435b917294e862da456cd10d56b
Showing with 14 additions and 1 deletion.
  1. +2 −1 src/Deedle/FrameUtils.fs
  2. +12 −0 tests/Deedle.Tests/Frame.fs
@@ -215,10 +215,11 @@ module internal Reflection =
[| for _, (input, body) in convertors ->
let cast = Expression.Convert(body, typeof<IVector>)
Expression.Lambda<Func<seq<'T>, IVector>>(cast, input).Compile() |]
let data = data |> Array.ofSeq
let frameData =
[| for convFunc in convertors -> convFunc.Invoke(data) |]
|> vectorBuilder.Create
Frame<int, string>(Index.ofKeys [0 .. (Seq.length data) - 1], colIndex, frameData, IndexBuilder.Instance, VectorBuilder.Instance)
Frame<int, string>(Index.ofKeys [0 .. data.Length - 1], colIndex, frameData, IndexBuilder.Instance, VectorBuilder.Instance)

/// Helper that makes it possible to call convertRecordSequence on untyped enumerable
type ConvertRecordHelper =
@@ -353,6 +353,18 @@ let ``Can read simple sequence of records using a specified column as index`` ()
set df.ColumnKeys |> shouldEqual (set ["Volume"; "Price"])
df.RowKeys |> Seq.head |> shouldEqual rows.[0].Date

[<Test>]
let ``Can read simple sequence of records deterministically `` () =
let mutable n = 0
let values =
seq {
yield n, n
n <- n + 1
yield n, n
n <- n + 1 }
let expected = [|0, 0; 1, 1|] |> Frame.ofRecords
values |> Frame.ofRecords |> shouldEqual expected

[<Test>]
let ``Can expand properties of a simple record sequence`` () =
let df = frame [ "MSFT" => Series.ofValues (typedRows ()) ]

0 comments on commit 3d055db

Please sign in to comment.
You can’t perform that action at this time.