From a65fce5d932bd7b61d66870b44629e57e66b2ca4 Mon Sep 17 00:00:00 2001 From: Adrien GAUCHE <36842113+adriengauche@users.noreply.github.com> Date: Wed, 19 Jun 2024 18:42:53 +0200 Subject: [PATCH] add: datetime instead of date for plot_multistep --- learntools/time_series/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/learntools/time_series/utils.py b/learntools/time_series/utils.py index 8aa805169..7e20feebf 100644 --- a/learntools/time_series/utils.py +++ b/learntools/time_series/utils.py @@ -245,7 +245,10 @@ def plot_multistep(y, every=1, ax=None, palette_kwargs=None): if ax is None: fig, ax = plt.subplots() ax.set_prop_cycle(plt.cycler('color', palette)) - for date, preds in y[::every].iterrows(): - preds.index = pd.period_range(start=date, periods=len(preds)) + freq = y.index.freq + if freq is None: + freq = pd.infer_freq(y.index) + for datetime, preds in y[::every].iterrows(): + preds.index = pd.period_range(start=datetime, periods=len(preds), freq=freq) preds.plot(ax=ax) - return ax + return ax \ No newline at end of file