[mlpack-git] master: Don't issue a warning for one-column CSVs. (29b89eb)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Oct 22 13:47:04 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/d1dfaa8e0978e01c240660a3217e68c4fa7c3e0a...29b89eb8aec5dcab6a5291bdd5b24b49bbe13f7e
>---------------------------------------------------------------
commit 29b89eb8aec5dcab6a5291bdd5b24b49bbe13f7e
Author: ryan <ryan at ratml.org>
Date: Thu Oct 22 13:46:39 2015 -0400
Don't issue a warning for one-column CSVs.
>---------------------------------------------------------------
29b89eb8aec5dcab6a5291bdd5b24b49bbe13f7e
src/mlpack/core/data/load_impl.hpp | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/src/mlpack/core/data/load_impl.hpp b/src/mlpack/core/data/load_impl.hpp
index 369f8bf..e374611 100644
--- a/src/mlpack/core/data/load_impl.hpp
+++ b/src/mlpack/core/data/load_impl.hpp
@@ -15,6 +15,7 @@
#include <mlpack/core/util/timers.hpp>
#include <boost/serialization/serialization.hpp>
+#include <boost/algorithm/string/trim.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
@@ -91,8 +92,27 @@ bool Load(const std::string& filename,
else if (loadType == arma::raw_ascii) // .csv file can be tsv.
{
if (extension == "csv")
- Log::Warn << "'" << filename << "' is not a standard csv file."
- << std::endl;
+ {
+ // We should issue a warning, but we don't want to issue the warning if
+ // there is only one column in the CSV (since there will be no commas
+ // anyway, and it will be detected as arma::raw_ascii).
+ const std::streampos pos = stream.tellg();
+ std::string line;
+ std::getline(stream, line, '\n');
+ boost::trim(line);
+
+ // Reset stream position.
+ stream.seekg(pos);
+
+ // If there are no spaces or whitespace in the line, then we shouldn't
+ // print the warning.
+ if ((line.find(' ') != std::string::npos) ||
+ (line.find('\t') != std::string::npos))
+ {
+ Log::Warn << "'" << filename << "' is not a standard csv file."
+ << std::endl;
+ }
+ }
stringType = "raw ASCII formatted data";
}
else
More information about the mlpack-git
mailing list