Skip to content

Commit

Permalink
Revert FixBacktestMixin
Browse files Browse the repository at this point in the history
Does not fix all Pandas 2.1 errors. Need to come up with more maintainable way of guaranteeing backwards compatibility.
  • Loading branch information
edtechre committed Dec 10, 2023
1 parent 1c94717 commit f58ef39
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions src/pybroker/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,7 @@ def backtest_executions(
Returns:
:class:`.TestResult` of the backtest.
"""
# TODO pandas 2.1.0
try:
test_dates = test_data[DataCol.DATE.value].unique().to_numpy()
except AttributeError:
test_dates = test_data[DataCol.DATE.value].unique()
test_dates = test_data[DataCol.DATE.value].unique()
test_dates.sort()
test_syms = test_data[DataCol.SYMBOL.value].unique()
test_data = (
Expand Down Expand Up @@ -194,19 +190,10 @@ def backtest_executions(
)
if exec.fn is not None:
exec_fns[sym] = exec.fn
# TODO pandas 2.1.0
try:
sym_exec_dates = {
sym: frozenset(
test_data.loc[pd.IndexSlice[sym, :]].index.to_numpy()
)
for sym in exec_ctxs.keys()
}
except AttributeError:
sym_exec_dates = {
sym: frozenset(test_data.loc[pd.IndexSlice[sym, :]].index)
for sym in exec_ctxs.keys()
}
sym_exec_dates = {
sym: frozenset(test_data.loc[pd.IndexSlice[sym, :]].index.values)
for sym in exec_ctxs.keys()
}
cover_sched: dict[np.datetime64, list[ExecResult]] = defaultdict(list)
buy_sched: dict[np.datetime64, list[ExecResult]] = defaultdict(list)
sell_sched: dict[np.datetime64, list[ExecResult]] = defaultdict(list)
Expand Down Expand Up @@ -657,11 +644,7 @@ def walkforward_split(
raise ValueError("DataFrame is empty.")
date_col = DataCol.DATE.value
dates = df[[date_col]]
# TODO pandas 2.1.0
try:
window_dates = df[date_col].unique().to_numpy()
except AttributeError:
window_dates = df[date_col].unique()
window_dates = df[date_col].unique()
window_dates.sort()
error_msg = f"""
Invalid params for {len(window_dates)} dates:
Expand Down

0 comments on commit f58ef39

Please sign in to comment.