Skip to content

Commit c2c3343

Browse files
committed
REF: Avoid deprecated pandas.Index.is_all_dates
1 parent a261999 commit c2c3343

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

backtesting/_plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def plot(*, results: pd.Series,
174174
plot_equity = plot_equity and not trades.empty
175175
plot_return = plot_return and not trades.empty
176176
plot_pl = plot_pl and not trades.empty
177-
is_datetime_index = df.index.is_all_dates
177+
is_datetime_index = isinstance(df.index, pd.DatetimeIndex)
178178

179179
from .lib import OHLCV_AGG
180180
# ohlc df may contain many columns. We're only interested in, and pass on to Bokeh, these

backtesting/backtesting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ def __init__(self,
10391039
data = data.copy(deep=False)
10401040

10411041
# Convert index to datetime index
1042-
if (not data.index.is_all_dates and
1042+
if (not isinstance(data.index, pd.DatetimeIndex) and
10431043
not isinstance(data.index, pd.RangeIndex) and
10441044
# Numeric index with most large numbers
10451045
(data.index.is_numeric() and
@@ -1070,7 +1070,7 @@ def __init__(self,
10701070
warnings.warn('Data index is not sorted in ascending order. Sorting.',
10711071
stacklevel=2)
10721072
data = data.sort_index()
1073-
if not data.index.is_all_dates:
1073+
if not isinstance(data.index, pd.DatetimeIndex):
10741074
warnings.warn('Data index is not datetime. Assuming simple periods, '
10751075
'but `pd.DateTimeIndex` is advised.',
10761076
stacklevel=2)
@@ -1556,7 +1556,7 @@ def geometric_mean(returns):
15561556

15571557
day_returns = gmean_day_return = np.array(np.nan)
15581558
annual_trading_days = np.nan
1559-
if index.is_all_dates:
1559+
if isinstance(index, pd.DatetimeIndex):
15601560
day_returns = equity_df['Equity'].resample('D').last().dropna().pct_change()
15611561
gmean_day_return = geometric_mean(day_returns)
15621562
annual_trading_days = float(

backtesting/lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def wrap_func(resampled, *args, **kwargs):
282282
elif result.ndim == 2:
283283
result = pd.DataFrame(result.T)
284284
# Resample back to data index
285-
if not result.index.is_all_dates:
285+
if not isinstance(result.index, pd.DatetimeIndex):
286286
result.index = resampled.index
287287
result = result.reindex(index=series.index | resampled.index,
288288
method='ffill').reindex(series.index)

0 commit comments

Comments
 (0)