[catboost/python] Fix load_model for model without 'params'
@@ -2553,17 +2553,14 @@ cdef class _CatBoost:
self.__model.Swap(tmp_model)
cpdef _get_params(self):
- if not self.__model.ModelInfo.contains("params"):
- return {}
- cdef const char* c_params_json = self.__model.ModelInfo["params"].c_str()
- cdef bytes py_params_json = c_params_json
- params_json = to_native_str(py_params_json)
- params = {}
- if params_json:
- for key, value in loads(params_json)["flat_params"].iteritems():
- if key != 'random_seed':
- params[str(key)] = value
+ try:
+ params_json = to_native_str(self.__model.ModelInfo["params"])
+ params_dict = loads(params_json)
+ flat_params = params_dict["flat_params"]
+ params = {str(key): value for key, value in iteritems(flat_params)}
return params
+ except Exception as e:
+ return {}
def _get_tree_count(self):
return self.__model.GetTreeCount()
