Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There's a problem reading the last line of data #168

Closed
sotex opened this issue Aug 27, 2024 · 4 comments
Closed

There's a problem reading the last line of data #168

sotex opened this issue Aug 27, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@sotex
Copy link

sotex commented Aug 27, 2024

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.

small.csv

How to reproduce it:

Environment: Visual Studio 2015

  • Version: latest
  • OS / distro: Windows 10
@sotex sotex added the bug Something isn't working label Aug 27, 2024
@d99kris
Copy link
Owner

d99kris commented Aug 28, 2024

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!

@sotex
Copy link
Author

sotex commented Aug 30, 2024

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

@d99kris
Copy link
Owner

d99kris commented Aug 30, 2024

Thank you 👍
I can see the issue now too. I will look into preparing a fix + test case and update here again.

@d99kris
Copy link
Owner

d99kris commented Aug 31, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants