Skip to content

CsvProvider: Incorrect truncation of sample file (by InferRows) #1439

@nikoyak

Description

@nikoyak
#r "nuget: FSharp.Data"
type TP = FSharp.Data.CsvProvider< @"C:\Temp\multiline.csv", InferRows = 2>

multiline.csv:

f1,f2
"multi-
line field",2

Error:

Error: input.fsx (1,11)-(1,76) typecheck error The type provider "ProviderImplementation.CsvProvider" reported an error: Cannot read sample CSV from 'C:\Temp\multiline.csv': Couldn't parse row 1 according to schema: Expected 2 columns, got 1

In the sample, one row of data occupies two lines of the file. InferRows pre-truncates file lines, not data rows:

match maxNumberOfRows with
| None -> reader.ReadToEnd()
| Some max ->
let sb = StringBuilder()
let max = ref max
while !max > 0 do
let line = reader.ReadLine()
if line = null then
max := 0
else
line |> sb.AppendLine |> ignore
decr max
sb.ToString()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions