From b848bfac04882d54a74bdae118889f5c4d4fc4a8 Mon Sep 17 00:00:00 2001 From: Trent McConaghy Date: Tue, 28 Jan 2025 08:29:14 +0100 Subject: [PATCH] Fix #1722: TypeError: Expected str for time_str, got datetime (PR #1723) --- pdr_backend/ppss/lake_ss.py | 12 +++++++++--- pdr_backend/ppss/ppss.py | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pdr_backend/ppss/lake_ss.py b/pdr_backend/ppss/lake_ss.py index a5b0eb25b..72097a9f2 100644 --- a/pdr_backend/ppss/lake_ss.py +++ b/pdr_backend/ppss/lake_ss.py @@ -51,15 +51,21 @@ def lake_dir(self) -> str: @property def st_timestr(self) -> str: - return self.d["st_timestr"] # eg "2019-09-13_04:00" (earliest) + s = self.d["st_timestr"] # eg "2019-09-13_04:00" (earliest) + assert isinstance(s, str) + return s @property def fin_timestr(self) -> str: - return self.d["fin_timestr"] # eg "now","2023-09-23_17:55","2023-09-23" + s = self.d["fin_timestr"] # eg "now","2023-09-23_17:55","2023-09-23" + assert isinstance(s, str) + return s @property def api(self) -> str: - return self.d.get("api", "ccxt") + s = self.d.get("api", "ccxt") + assert isinstance(s, str) + return s # feeds defined in base diff --git a/pdr_backend/ppss/ppss.py b/pdr_backend/ppss/ppss.py index 23c257e49..082390786 100644 --- a/pdr_backend/ppss/ppss.py +++ b/pdr_backend/ppss/ppss.py @@ -3,6 +3,7 @@ from typing import Optional, Tuple import yaml +import yaml.constructor from enforce_typing import enforce_types from pdr_backend.cli.predict_train_feedsets import PredictTrainFeedsets @@ -81,8 +82,12 @@ def constructor_dict( yaml_filename or yaml_str and not (yaml_filename and yaml_str) ), "need to set yaml_filename_ or yaml_str but not both" + # Specify yaml.safe_load to _not_ convert strings to timestamps + c = yaml.constructor.SafeConstructor.yaml_constructors + c["tag:yaml.org,2002:timestamp"] = c["tag:yaml.org,2002:str"] + # get d - if yaml_filename is not None: + if yaml_filename: with open(yaml_filename, "r") as f: d = yaml.safe_load(f) else: