Commit b18ad976 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

refactor: force_string -> force_string_and_int

parent d27a7df3
...@@ -7,7 +7,7 @@ from astropy import table, time ...@@ -7,7 +7,7 @@ from astropy import table, time
from ._dispatcher import Dispatcher from ._dispatcher import Dispatcher
from ..dag_utils import ( from ..dag_utils import (
force_string, force_string_and_int,
override_common_keys, override_common_keys,
generate_sha1_from_time, generate_sha1_from_time,
) )
...@@ -72,8 +72,8 @@ class BaseDAG: ...@@ -72,8 +72,8 @@ class BaseDAG:
) )
@staticmethod @staticmethod
def force_string(d: dict): def force_string_and_int(d: dict):
return force_string(d) return force_string_and_int(d)
class Level2DAG(BaseDAG): class Level2DAG(BaseDAG):
...@@ -364,5 +364,5 @@ class Level1DAG(BaseDAG): ...@@ -364,5 +364,5 @@ class Level1DAG(BaseDAG):
# It seems that the dag_run_template is already stringified, # It seems that the dag_run_template is already stringified,
# so we don't need to force_string here. # so we don't need to force_string here.
# force values to be string # force values to be string
dag_run = self.force_string(dag_run) dag_run = self.force_string_and_int(dag_run)
return dag_run return dag_run
...@@ -68,14 +68,16 @@ def generate_uuid(): ...@@ -68,14 +68,16 @@ def generate_uuid():
return str(uuid.uuid4()) return str(uuid.uuid4())
def force_string(d): def force_string_and_int(d):
"""更通用的递归字符串转换""" """更通用的递归字符串转换"""
if isinstance(d, dict): if isinstance(d, dict):
return {k: force_string(v) for k, v in d.items()} return {k: force_string_and_int(v) for k, v in d.items()}
elif isinstance(d, Iterable) and not isinstance(d, (str, bytes)): elif isinstance(d, Iterable) and not isinstance(d, (str, bytes)):
return [force_string(item) for item in d] return [force_string_and_int(item) for item in d]
elif isinstance(d, (str, bytes)): elif isinstance(d, (str, bytes)):
return str(d) return str(d)
elif type(d) in (np.int32, np.int64):
return int(d)
else: else:
return d return d
......
Supports Markdown
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