Skip to content

Commit 795f3be

Browse files
committed
change account status format to pickle
1 parent 79d9ecd commit 795f3be

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

demeter/core/actuator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def save_result(
524524
:type file_name: str
525525
:param decimals: decimals in csv
526526
:type decimals: int
527-
:param file_format: format of account status, csv | feather
527+
:param file_format: format of account status, csv | pickle
528528
:return: A list of saved file path
529529
:rtype: List[str]
530530
"""
@@ -538,10 +538,10 @@ def save_result(
538538
# save account file
539539
if file_format == "csv":
540540
account_file_path = os.path.join(path, file_name_head + ".account.csv")
541-
elif file_format == "feather":
542-
account_file_path = os.path.join(path, file_name_head + ".account.feather")
541+
elif file_format == "pickle":
542+
account_file_path = os.path.join(path, file_name_head + ".account.pkl")
543543
else:
544-
raise RuntimeError("File format should be csv or feather")
544+
raise RuntimeError("File format should be csv or pickle")
545545

546546
df_2_save: pd.DataFrame = self._account_status_df
547547
if decimals is not None:
@@ -550,8 +550,8 @@ def save_result(
550550
# df_2_save = df_2_save.map(lambda x: round(x, decimals) if pd.api.types.is_numeric_dtype(type(x)) else x)
551551
if file_format == "csv":
552552
df_2_save.to_csv(account_file_path)
553-
elif file_format == "feather":
554-
df_2_save.to_feather(account_file_path)
553+
elif file_format == "pickle":
554+
df_2_save.to_pickle(account_file_path, compression="gzip")
555555
file_list.append(account_file_path)
556556

557557
# save backtest file

demeter/utils/application.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,18 @@ def to_multi_index_df(df: pd.DataFrame, level0: str):
108108
df.columns = new_columns
109109

110110

111-
def load_account_status(path:str) -> pd.DataFrame:
111+
def load_account_status(path: str) -> pd.DataFrame:
112112
if path.endswith(".csv"):
113113
df = pd.read_csv(path, index_col=[0], header=[0, 1], parse_dates=[0])
114114
rename_dict = {}
115115
for column in df.columns:
116116
if "Unnamed" in column[1]:
117117
rename_dict[column[1]] = ""
118118
df = df.rename(columns=rename_dict, level=1)
119-
elif path.endswith(".feather"):
120-
df = pd.read_feather(path)
119+
elif path.endswith(".pkl"):
120+
df = pd.read_pickle(path, compression="gzip")
121121
else:
122-
raise RuntimeError("Unknown format, account status support csv and feather only")
122+
raise RuntimeError("Unknown format, account status support csv and pickle only")
123123
return df
124124

125125

@@ -133,4 +133,3 @@ def is_stable_coin(*token: TokenInfo):
133133
if t == USD or t.name in STABLE_COINS:
134134
return t
135135
return None
136-

0 commit comments

Comments
 (0)