Skip to content

Commit

Permalink
REF: Revert daa1da9 and 52eb813 into something that works
Browse files Browse the repository at this point in the history
  • Loading branch information
kernc committed Sep 22, 2019
1 parent 05a18d0 commit 3deee42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 5 additions & 1 deletion backtesting/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def _as_list(value):

def _data_period(df):
"""Return data index period as pd.Timedelta"""
return df.index[:100].to_series(keep_tz=True).diff().median()
if df.index.is_all_dates:
values = df.index[:100].to_series(keep_tz=True)
else:
values = df.index[:100].to_series()
return values.diff().median()


class _Array(np.ndarray):
Expand Down
3 changes: 1 addition & 2 deletions backtesting/backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,7 @@ def _drawdown_duration_peaks(dd, index):
df['Drawdown Duration'] = dd_dur
dd_dur = df['Drawdown Duration']

# Strip timezone info, otherwise pandas 0.24.2 errors when filling `s` ahead
df.index = data.index.tz_convert(None)
df.index = data.index

def _round_timedelta(value, _period=_data_period(df)):
if not isinstance(value, pd.Timedelta):
Expand Down

0 comments on commit 3deee42

Please sign in to comment.