Skip to content

Commit

Permalink
Fix #1722: TypeError: Expected str for time_str, got datetime (PR #1723)
Browse files Browse the repository at this point in the history
  • Loading branch information
trentmc authored Jan 28, 2025
1 parent 8aee57b commit b848bfa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pdr_backend/ppss/lake_ss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion pdr_backend/ppss/ppss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b848bfa

Please sign in to comment.