From 33081fa49239c0a716d72625d880e8e65a9a3b94 Mon Sep 17 00:00:00 2001 From: Zhenyong Zhu Date: Wed, 24 Apr 2019 08:13:20 -0400 Subject: [PATCH] fix preferoptions in frame.readcsv from stream --- src/Deedle/FrameExtensions.fs | 3 ++- tests/Deedle.CSharp.Tests/Frame.cs | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Deedle/FrameExtensions.fs b/src/Deedle/FrameExtensions.fs index 717cff6e..f5d15841 100644 --- a/src/Deedle/FrameExtensions.fs +++ b/src/Deedle/FrameExtensions.fs @@ -130,7 +130,7 @@ type Frame = static member ReadCsv ( stream:Stream, [] hasHeaders:Nullable, [] inferTypes:Nullable, [] inferRows:Nullable, [] schema, [] separators, [] culture, [] maxRows:Nullable, - [] missingValues) = + [] missingValues, [] preferOptions:Nullable) = FrameUtils.readCsv (new StreamReader(stream)) (if hasHeaders.HasValue then Some hasHeaders.Value else None) @@ -139,6 +139,7 @@ type Frame = (Some schema) (Some missingValues) (if separators = null then None else Some separators) (Some culture) (if maxRows.HasValue then Some maxRows.Value else None) + (if preferOptions.HasValue then Some preferOptions.Value else None) // Note: The following is also used from F# diff --git a/tests/Deedle.CSharp.Tests/Frame.cs b/tests/Deedle.CSharp.Tests/Frame.cs index 373d2ee4..1515a99f 100644 --- a/tests/Deedle.CSharp.Tests/Frame.cs +++ b/tests/Deedle.CSharp.Tests/Frame.cs @@ -22,14 +22,31 @@ public static Frame LoadMSFT([CallerFilePath] string source = "") return Frame.ReadCsv(file, inferRows:10); } - [Test] + public static Frame LoadMSFTStream([CallerFilePath] string source = "") + { + var file = Path.Combine(Path.GetDirectoryName(source), "..", "Deedle.Tests", "data", "MSFT.csv"); + var sr = new StreamReader(file); + var csv = Frame.ReadCsv(sr.BaseStream); + sr.Close(); + return csv; + } + + [Test] public static void CanSubtractNumericalValues() { var df = LoadMSFT(); var actual = df.Zip(df, (n1, n2) => n1 - n2).GetAllValues().Sum(); Assert.AreEqual(0.0, actual); } - } + + [Test] + public static void CanSubtractNumericalValuesStream() + { + var df = LoadMSFTStream(); + var actual = df.Zip(df, (n1, n2) => n1 - n2).GetAllValues().Sum(); + Assert.AreEqual(0.0, actual); + } + } /* ---------------------------------------------------------------------------------- * Creating frames and getting frame data @@ -182,5 +199,5 @@ public static void CanGetColumnDynamically() Assert.AreEqual(11.1, s1[1]); } } - } + } }