From d4e25533254f3b5df232ec82262a17f967d08222 Mon Sep 17 00:00:00 2001 From: Maisa Ben Salah <76703998+MaiBe-ctrl@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:27:03 -0700 Subject: [PATCH] Fix frequency inference if NaT (#1590) --- neuralprophet/df_utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/neuralprophet/df_utils.py b/neuralprophet/df_utils.py index 428f78908..42fd30a39 100644 --- a/neuralprophet/df_utils.py +++ b/neuralprophet/df_utils.py @@ -1272,6 +1272,13 @@ def _infer_frequency(df, freq, min_freq_percentage=0.7): frequencies, distribution = get_freq_dist(df["ds"]) argmax_frequency = frequencies[np.argmax(distribution)] + if np.isnan(argmax_frequency): + if freq == "auto" or freq is None: + log.warning("The auto-frequency feature is not able to detect the frequency. Please define it manually.") + raise ValueError("Cannot infer frequency") + else: + return freq + # exception - monthly df (28, 29, 30 or 31 days freq) MONTHLY_FREQUENCIES = [2.4192e15, 2.5056e15, 2.5920e15, 2.6784e15] if argmax_frequency in MONTHLY_FREQUENCIES: