Improve naming of default hyperopt serializer

This commit is contained in:
Matthias 2021-06-30 19:48:34 +02:00
parent 0809225a0a
commit 15e36a20e1
2 changed files with 5 additions and 4 deletions

View File

@ -28,7 +28,7 @@ from freqtrade.optimize.backtesting import Backtesting
from freqtrade.optimize.hyperopt_auto import HyperOptAuto from freqtrade.optimize.hyperopt_auto import HyperOptAuto
from freqtrade.optimize.hyperopt_interface import IHyperOpt # noqa: F401 from freqtrade.optimize.hyperopt_interface import IHyperOpt # noqa: F401
from freqtrade.optimize.hyperopt_loss_interface import IHyperOptLoss # noqa: F401 from freqtrade.optimize.hyperopt_loss_interface import IHyperOptLoss # noqa: F401
from freqtrade.optimize.hyperopt_tools import HyperoptTools, hyperopt_parser from freqtrade.optimize.hyperopt_tools import HyperoptTools, hyperopt_serializer
from freqtrade.optimize.optimize_reports import generate_strategy_stats from freqtrade.optimize.optimize_reports import generate_strategy_stats
from freqtrade.resolvers.hyperopt_resolver import HyperOptLossResolver, HyperOptResolver from freqtrade.resolvers.hyperopt_resolver import HyperOptLossResolver, HyperOptResolver
@ -167,7 +167,7 @@ class Hyperopt:
""" """
epoch[FTHYPT_FILEVERSION] = 2 epoch[FTHYPT_FILEVERSION] = 2
with self.results_file.open('a') as f: with self.results_file.open('a') as f:
rapidjson.dump(epoch, f, default=hyperopt_parser, rapidjson.dump(epoch, f, default=hyperopt_serializer,
number_mode=rapidjson.NM_NATIVE | rapidjson.NM_NAN) number_mode=rapidjson.NM_NATIVE | rapidjson.NM_NAN)
f.write("\n") f.write("\n")

View File

@ -22,7 +22,7 @@ logger = logging.getLogger(__name__)
NON_OPT_PARAM_APPENDIX = " # value loaded from strategy" NON_OPT_PARAM_APPENDIX = " # value loaded from strategy"
def hyperopt_parser(x): def hyperopt_serializer(x):
if isinstance(x, np.integer): if isinstance(x, np.integer):
return int(x) return int(x)
return str(x) return str(x)
@ -60,7 +60,8 @@ class HyperoptTools():
} }
logger.info(f"Dumping parameters to {filename}") logger.info(f"Dumping parameters to {filename}")
rapidjson.dump(final_params, filename.open('w'), indent=2, rapidjson.dump(final_params, filename.open('w'), indent=2,
default=hyperopt_parser, number_mode=rapidjson.NM_NATIVE | rapidjson.NM_NAN default=hyperopt_serializer,
number_mode=rapidjson.NM_NATIVE | rapidjson.NM_NAN
) )
@staticmethod @staticmethod