Browse Source

!736 Skip blank line for TextFileDataset

Merge pull request !736 from yanghaitao/yht_tftextfile_black_line
tags/v0.3.0-alpha
mindspore-ci-bot Gitee 5 years ago
parent
commit
e6473f0765
2 changed files with 7 additions and 1 deletions
  1. +6
    -1
      mindspore/ccsrc/dataset/engine/datasetops/source/text_file_op.cc
  2. +1
    -0
      tests/ut/data/dataset/testTextFileDataset/1.txt

+ 6
- 1
mindspore/ccsrc/dataset/engine/datasetops/source/text_file_op.cc View File

@@ -143,6 +143,9 @@ Status TextFileOp::LoadFile(const std::string &file, const int64_t start_offset,
std::unique_ptr<TensorQTable> tensor_table = std::make_unique<TensorQTable>();

while (getline(handle, line)) {
if (line.empty()) {
continue;
}
// If read to the end offset of this file, break.
if (rows_total >= end_offset) {
break;
@@ -425,7 +428,9 @@ int64_t TextFileOp::CountTotalRows(const std::string &file) {
std::string line;
int64_t count = 0;
while (getline(handle, line)) {
count++;
if (!line.empty()) {
count++;
}
}

return count;


+ 1
- 0
tests/ut/data/dataset/testTextFileDataset/1.txt View File

@@ -1,3 +1,4 @@
This is a text file.

Be happy every day.
Good luck to everyone.

Loading…
Cancel
Save