Skip to content

Commit

Permalink
Add workaround to std::getline bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasColthurst committed Aug 5, 2024
1 parent bb58176 commit 027b484
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 10 additions & 1 deletion cxx/pclean/csv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ DataFrame DataFrame::from_csv(
df.data[col_names[i++]].push_back(part);
}
if (!first_line) {
assert(i == col_names.size());
if (i != col_names.size()) {
if (line.back() == ',') {
// std::getline is broken and won't let the last field be empty.
df.data[col_names[i++]].push_back("");
} else {
printf("Only found %ld out of %ld expected columns in line\n%s\n",
i, col_names.size(), line.c_str());
assert(false);
}
}
}
first_line = false;
}
Expand Down
7 changes: 4 additions & 3 deletions cxx/pclean/pclean_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
T_observations translate_observations(
const DataFrame& df, const T_schema &schema) {
T_observations obs;
int uniq = 0;

for (const auto& col : df.data) {
const std::string& col_name = col.first;
Expand All @@ -32,8 +31,10 @@ T_observations translate_observations(

std::vector<std::string> entities;
for (size_t j = 0; j < num_domains; ++j) {
// Give each entity in every domain its own unique value.
entities.push_back(std::to_string(uniq++));
// Give every row it's own universe of unique id's.
// TODO(thomaswc): Correctly handle the case when a row makes
// references to two or more different entities of the same type.
entities.push_back(std::to_string(i));
}
obs[col_name].push_back(std::make_tuple(entities, val));
}
Expand Down

0 comments on commit 027b484

Please sign in to comment.