Unverified Commit 274f340a authored by Guolin Ke's avatar Guolin Ke Committed by GitHub
Browse files

allow passing empty value in parameters (#2289)

parent 207bb3ef
......@@ -850,7 +850,7 @@ struct Config {
inline bool Config::GetString(
const std::unordered_map<std::string, std::string>& params,
const std::string& name, std::string* out) {
if (params.count(name) > 0) {
if (params.count(name) > 0 && !params.at(name).empty()) {
*out = params.at(name);
return true;
}
......@@ -860,7 +860,7 @@ inline bool Config::GetString(
inline bool Config::GetInt(
const std::unordered_map<std::string, std::string>& params,
const std::string& name, int* out) {
if (params.count(name) > 0) {
if (params.count(name) > 0 && !params.at(name).empty()) {
if (!Common::AtoiAndCheck(params.at(name).c_str(), out)) {
Log::Fatal("Parameter %s should be of type int, got \"%s\"",
name.c_str(), params.at(name).c_str());
......@@ -873,7 +873,7 @@ inline bool Config::GetInt(
inline bool Config::GetDouble(
const std::unordered_map<std::string, std::string>& params,
const std::string& name, double* out) {
if (params.count(name) > 0) {
if (params.count(name) > 0 && !params.at(name).empty()) {
if (!Common::AtofAndCheck(params.at(name).c_str(), out)) {
Log::Fatal("Parameter %s should be of type double, got \"%s\"",
name.c_str(), params.at(name).c_str());
......@@ -886,7 +886,7 @@ inline bool Config::GetDouble(
inline bool Config::GetBool(
const std::unordered_map<std::string, std::string>& params,
const std::string& name, bool* out) {
if (params.count(name) > 0) {
if (params.count(name) > 0 && !params.at(name).empty()) {
std::string value = params.at(name);
std::transform(value.begin(), value.end(), value.begin(), Common::tolower);
if (value == std::string("false") || value == std::string("-")) {
......
......@@ -14,9 +14,12 @@ namespace LightGBM {
void Config::KV2Map(std::unordered_map<std::string, std::string>& params, const char* kv) {
std::vector<std::string> tmp_strs = Common::Split(kv, '=');
if (tmp_strs.size() == 2) {
if (tmp_strs.size() == 2 || tmp_strs.size() == 1) {
std::string key = Common::RemoveQuotationSymbol(Common::Trim(tmp_strs[0]));
std::string value = Common::RemoveQuotationSymbol(Common::Trim(tmp_strs[1]));
std::string value = "";
if (tmp_strs.size() == 2) {
value = Common::RemoveQuotationSymbol(Common::Trim(tmp_strs[1]));
}
if (!Common::CheckASCII(key) || !Common::CheckASCII(value)) {
Log::Fatal("Do not support non-ascii characters in config.");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment