remove empty json keys
@@ -250,7 +250,9 @@ static TJsonValue GetFeaturesInfoJson(
const THashMap<int, TString>* catFeaturesHashToString
) {
TJsonValue jsonValue;
+ if (!obliviousTrees.FloatFeatures.empty()) {
jsonValue.InsertValue("float_features", TJsonValue());
+ }
for (const auto& floatFeature: obliviousTrees.FloatFeatures) {
jsonValue["float_features"].AppendValue(ToJson(floatFeature));
if (featureId) {
@@ -260,7 +262,7 @@ static TJsonValue GetFeaturesInfoJson(
}
}
}
-
+ if (!obliviousTrees.CatFeatures.empty()) {
jsonValue.InsertValue("categorical_features", TJsonValue());
THashMap<int, int> oneHotIndexes;
for (int idx = 0; idx < obliviousTrees.OneHotFeatures.ysize(); ++idx) {
@@ -283,12 +285,15 @@ static TJsonValue GetFeaturesInfoJson(
}
jsonValue["categorical_features"].AppendValue(catFeatureJsonValue);
}
+ }
+ if (!obliviousTrees.CtrFeatures.empty()) {
jsonValue.InsertValue("ctrs", TJsonValue());
+ }
for (const auto& ctr: obliviousTrees.CtrFeatures) {
jsonValue["ctrs"].AppendValue(ToJson(ctr));
}
- jsonValue.InsertValue("cat_features_hash", TJsonValue());
if (catFeaturesHashToString) {
+ jsonValue.InsertValue("cat_features_hash", TJsonValue());
for (const auto& key_value: *catFeaturesHashToString) {
TJsonValue catFeaturesHash;
catFeaturesHash.InsertValue("hash", key_value.first);
@@ -297,14 +302,15 @@ static TJsonValue GetFeaturesInfoJson(
}
}
return jsonValue;
-
}
static void GetFeaturesInfo(const TJsonValue& jsonValue, TObliviousTrees* obliviousTrees) {
+ if (jsonValue.Has("float_features")) {
for (const auto &value: jsonValue["float_features"].GetArray()) {
obliviousTrees->FloatFeatures.push_back(FloatFeatureFromJson(value));
}
-
+ }
+ if (jsonValue.Has("categorical_features")) {
for (const auto &value: jsonValue["categorical_features"].GetArray()) {
auto catFeature = CatFeatureFromJson(value);
obliviousTrees->CatFeatures.push_back(catFeature);
@@ -316,11 +322,13 @@ static void GetFeaturesInfo(const TJsonValue& jsonValue, TObliviousTrees* oblivi
obliviousTrees->OneHotFeatures.push_back(ohFeature);
}
}
-
+ }
+ if (jsonValue.Has("ctrs")) {
for (const auto &value: jsonValue["ctrs"].GetArray()) {
obliviousTrees->CtrFeatures.push_back(CtrFeatureFromJson(value));
}
}
+}
static TJsonValue GetObliviousTreesJson(const TObliviousTrees& obliviousTrees) {
int leafOffset = 0;
