/// <summary> /// Reads a seekable stream of CSV data into a DataFrame. /// </summary> /// <param name="csvStream">stream of CSV data to be read in</param> /// <param name="separator">column separator</param> /// <param name="header">has a header or not</param> /// <param name="columnNames">column names (can be empty)</param> /// <param name="dataTypes">column types (can be empty)</param> /// <param name="numberOfRowsToRead">number of rows to read not including the header(if present)</param> /// <param name="guessRows">number of rows used to guess types</param> /// <param name="addIndexColumn">add one column with the row index</param> /// <param name="encoding">The character encoding. Defaults to UTF8 if not specified</param> /// <returns><see cref="DataFrame"/></returns> public static DataFrame LoadCsv(Stream csvStream, char separator = ',', bool header = true, string[] columnNames = null, Type[] dataTypes = null, long numberOfRowsToRead = -1, int guessRows = 10, bool addIndexColumn = false, Encoding encoding = null) { if (!csvStream.CanSeek) { throw new ArgumentException(Strings.NonSeekableStream, nameof(csvStream)); } if (dataTypes == null && guessRows <= 0) { throw new ArgumentException(string.Format(Strings.ExpectedEitherGuessRowsOrDataTypes, nameof(guessRows), nameof(dataTypes))); } using (var streamReader = new StreamReader(csvStream, encoding ?? Encoding.UTF8, detectEncodingFromByteOrderMarks: true, DefaultStreamReaderBufferSize, leaveOpen: true)) { CsvLineEnumerator linesEnumerator = new CsvLineEnumerator(streamReader); IEnumerable <string> lines = new CsvLines(linesEnumerator); return(ReadCsvLinesIntoDataFrame(lines, separator, header, columnNames, dataTypes, numberOfRowsToRead, guessRows, addIndexColumn)); } }
public CsvLines(CsvLineEnumerator csvLineEnumerator) { enumerator = csvLineEnumerator; }