From 230ac7aa80372257dde94a9d41d854c6cafcffa2 Mon Sep 17 00:00:00 2001 From: old-bear Date: Mon, 20 Aug 2018 11:43:03 +0800 Subject: [PATCH] [tune] Compatibility fix under py2 on str condition (#2673) * * Compatibility fix under py2 on ray.tune * + Fix compatibility * + Use package six to achieve str compatibility --- python/ray/tune/config_parser.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/ray/tune/config_parser.py b/python/ray/tune/config_parser.py index f19f98029..a49fcb2fb 100644 --- a/python/ray/tune/config_parser.py +++ b/python/ray/tune/config_parser.py @@ -6,6 +6,9 @@ import argparse import json import os +# For compatibility under py2 to consider unicode as str +from six import string_types + from ray.tune import TuneError from ray.tune.result import DEFAULT_RESULTS_DIR from ray.tune.trial import Resources, Trial @@ -15,7 +18,7 @@ from ray.tune.logger import _SafeFallbackEncoder def json_to_resources(data): if data is None or data == "null": return None - if type(data) is str: + if isinstance(data, string_types): data = json.loads(data) for k in data: if k in ["driver_cpu_limit", "driver_gpu_limit"]: @@ -144,7 +147,7 @@ def to_argv(config): if "-" in k: raise ValueError("Use '_' instead of '-' in `{}`".format(k)) argv.append("--{}".format(k.replace("_", "-"))) - if isinstance(v, str): + if isinstance(v, string_types): argv.append(v) else: argv.append(json.dumps(v, cls=_SafeFallbackEncoder))