From 1cb3bead328e530d8307e77dcb2126f049f2f574 Mon Sep 17 00:00:00 2001 From: yanghaitao Date: Mon, 27 Apr 2020 14:54:26 +0800 Subject: [PATCH] skip black line for TextFileDataset --- .../ccsrc/dataset/engine/datasetops/source/text_file_op.cc | 7 ++++++- tests/ut/data/dataset/testTextFileDataset/1.txt | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mindspore/ccsrc/dataset/engine/datasetops/source/text_file_op.cc b/mindspore/ccsrc/dataset/engine/datasetops/source/text_file_op.cc index 2b626163669..17bb65233d0 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/source/text_file_op.cc +++ b/mindspore/ccsrc/dataset/engine/datasetops/source/text_file_op.cc @@ -143,6 +143,9 @@ Status TextFileOp::LoadFile(const std::string &file, const int64_t start_offset, std::unique_ptr tensor_table = std::make_unique(); 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; diff --git a/tests/ut/data/dataset/testTextFileDataset/1.txt b/tests/ut/data/dataset/testTextFileDataset/1.txt index 9d911eacc07..a5ffab4fdce 100644 --- a/tests/ut/data/dataset/testTextFileDataset/1.txt +++ b/tests/ut/data/dataset/testTextFileDataset/1.txt @@ -1,3 +1,4 @@ This is a text file. + Be happy every day. Good luck to everyone.