There's a problem reading the last line of data
Description: Read this file that has a comma at the end of each line, and the last line is one column less than the others.
The first 36 rows are 11 columns and the last one is only 10 columns.
How to reproduce it:
Environment: Visual Studio 2015
- Version: latest
- OS / distro: Windows 10
Hi @sotex - could you please share a small code example showing the issue?
I put together a small test program, and it is able to read all data rows in the last column:
#include <iostream>
#include <vector>
#include "rapidcsv.h"
int main()
{
rapidcsv::Document doc("small.csv");
std::vector<float> colvals = doc.GetColumn<float>(9);
std::cout << "Read " << colvals.size() << " values:" << std::endl;
for (const auto& colval : colvals)
{
std::cout << colval << "\n";
}
}
Also, please help specify the version number, as "latest" may be ambiguous (latest from some package manager, latest from git master branch, latest github release, etc) and also requires extra work to decipher when revisiting old bug reports. You can find the version number at the top (line 5) of your copy of rapidcsv.h. Thanks!
Sorry, I uploaded the file with an extra space in the last line. small.csv
The version I tested was: Version: 8.83 My test code is as follows.
int main()
{
rapidcsv::LabelParams pLabelParams = rapidcsv::LabelParams(-1, -1);
rapidcsv::SeparatorParams pSeparatorParams = rapidcsv::SeparatorParams(',', true, true, false, false);
rapidcsv::ConverterParams pConverterParams = rapidcsv::ConverterParams();
rapidcsv::LineReaderParams pLineReaderParams = rapidcsv::LineReaderParams();
rapidcsv::Document doc("D:\\下载\\small.csv");
for (int i = 0; i < doc.GetRowCount(); ++i) {
std::cout << "Row " << i << " : " << doc.GetRow<std::string>(i).size() << std::endl;
}
return 0;
}
The Output:
Row 0 : 11
Row 1 : 11
Row 2 : 11
Row 3 : 11
Row 4 : 11
Row 5 : 11
Row 6 : 11
Row 7 : 11
Row 8 : 11
Row 9 : 11
Row 10 : 11
Row 11 : 11
Row 12 : 11
Row 13 : 11
Row 14 : 11
Row 15 : 11
Row 16 : 11
Row 17 : 11
Row 18 : 11
Row 19 : 11
Row 20 : 11
Row 21 : 11
Row 22 : 11
Row 23 : 11
Row 24 : 11
Row 25 : 11
Row 26 : 11
Row 27 : 11
Row 28 : 11
Row 29 : 11
Row 30 : 11
Row 31 : 11
Row 32 : 11
Row 33 : 11
Row 34 : 11
Row 35 : 10
Thank you 👍 I can see the issue now too. I will look into preparing a fix + test case and update here again.
Hi again - thanks for reporting the bug and providing all details. The issue should be fixed now with above commit. Please let me know if it's not.