statsforecast icon indicating copy to clipboard operation
statsforecast copied to clipboard

ETS model fails due to numba error

Open jdegene opened this issue 2 years ago • 4 comments

Describe the bug If I run the ets model as described in the references (exact same code, same data), I get the error below. Main gist is from these lines:

TypingError: Failed in nopython mode pipeline (step: nopython frontend) No implementation of function Function(<ufunc 'isnan'>) found for signature:

>>> isnan(OptionalType(float64) i.e. the type 'float64 or None')

So I suspect this is a numba (version) issue, but I have no idea how to debug this. I have tried using different model settings and datasets but the error remains.

---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_33604\716268395.py in <cell line: 17>()
     15 # For some models like ARIMA, include confidence intervals
     16 # For the moment confidence intervals for ETS are unavailable
---> 17 Y_hat_df = model.forecast(horizon).reset_index()
     18 Y_hat_df.head()

~\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\statsforecast\core.py in forecast(self, h, xreg, fitted, level)
    223         )
    224         if self.n_jobs == 1:
--> 225             res_fcsts = self._sequential(**forecast_kwargs)
    226         else:
    227             res_fcsts = self._data_parallel(**forecast_kwargs)

~\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\statsforecast\core.py in _sequential(self, h, test_size, step_size, input_size, xreg, fitted, level, mode)
    299             model_name = _build_forecast_name(model, *args)
    300             if mode == 'forecast':
--> 301                 res_fcsts = self.ga.compute_forecasts(h, model, xreg, fitted, level, *args)
    302                 values = res_fcsts['forecasts']
    303                 keys = res_fcsts['keys']

~\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\statsforecast\core.py in compute_forecasts(self, h, func, xreg, fitted, level, *args)
     63             if xreg is not None:
     64                 xr = xreg[i]
---> 65             res_fn = func(grp, h, xr, fitted, *args)
     66             if has_level:
     67                 if keys is None:

~\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\statsforecast\models.py in ets(X, h, future_xreg, fitted, season_length, model)
    380     y = X[:, 0] if X.ndim == 2 else X
    381     xreg = X[:, 1:] if (X.ndim == 2 and X.shape[1] > 1) else None
--> 382     mod = ets_f(y, m=season_length, model=model)
    383     fcst = forecast_ets(mod, h)
    384     keys = ['mean']

~\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\statsforecast\ets.py in ets_f(y, m, model, damped, alpha, beta, gamma, phi, additive_only, blambda, biasadj, lower, upper, opt_crit, nmse, bounds, ic, restrict, allow_multiplicative_trend, use_initial_values, maxit)
    994                     if stype != 'N' and m == 1:
    995                         continue
--> 996                     fit = etsmodel(y, m, etype, ttype, stype, dtype,
    997                                    alpha, beta, gamma, phi,
    998                                    lower=lower, upper=upper, opt_crit=opt_crit,

~\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\statsforecast\ets.py in etsmodel(y, m, errortype, trendtype, seasontype, damped, alpha, beta, gamma, phi, lower, upper, opt_crit, nmse, bounds, maxit, control, seed, trace)
    862             phi = fit_par[j]
    863 
--> 864     amse, e, states, lik = pegelsresid_C(
    865         y, m, init_state,
    866         errortype, trendtype, seasontype, damped,

~\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\numba\core\dispatcher.py in _compile_for_args(self, *args, **kws)
    418                 e.patch_message(msg)
    419 
--> 420             error_rewrite(e, 'typing')
    421         except errors.UnsupportedError as e:
    422             # Something unsupported is present in the user code, add help info

~\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\numba\core\dispatcher.py in error_rewrite(e, issue_type)
    359                 raise e
    360             else:
--> 361                 raise e.with_traceback(None)
    362 
    363         argtypes = []

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<ufunc 'isnan'>) found for signature:
 
 >>> isnan(OptionalType(float64) i.e. the type 'float64 or None')
 
There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload in function 'Numpy_rules_ufunc.generic': File: numba\core\typing\npydecl.py: Line 96.
    With argument(s): '(OptionalType(float64) i.e. the type 'float64 or None')':
   Rejected as the implementation raised a specific error:
     TypingError: can't resolve ufunc isnan for types (OptionalType(float64),)
  raised from C:\Users\firstname.lastname\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\numba\core\typing\npydecl.py:102

During: resolving callee type: Function(<ufunc 'isnan'>)
During: typing of call at C:\Users\firstname.lastname\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\statsforecast\ets.py (487)


File "..\..\..\..\AppData\Local\miniforge3\envs\py38_ts\lib\site-packages\statsforecast\ets.py", line 487:
def pegelsresid_C(y: np.ndarray,
    <source elided>
    x = x.reshape((n + 1, p))
    if not np.isnan(lik):
    ^

To Reproduce Use example code/steps in references. Error should appear after running the codeblock in part 3)

Desktop (please complete the following information):

  • OS: Win11
  • Version statsforecast: 0.7.1

Installed packages and versions

Name Version jupyter 1.0.0 jupyter_client 7.3.4 jupyter_console 6.4.4 jupyter_core 4.11.1 jupyterlab_pygments 0.2.2 jupyterlab_widgets 1.1.1 matplotlib-base 3.5.2 matplotlib-inline 0.1.3 nb_conda_kernels 2.3.1 notebook 6.4.12 numba 0.53.0 numpy 1.23.1 pandas 1.2.5 prophet 1.1 scikit-learn 1.1.1 scipy 1.9.0 statsforecast 0.7.1 statsmodels 0.13.2

jdegene avatar Aug 02 '22 12:08 jdegene

Hi @jdegene! Thank you very much for letting us know about the issue. Yes, the problem arises due to the numba version. Using numba==0.56.0 works. You can use:

pip install numba==0.56.0

To install the required version. Or

pip install -U numba

To update numba to the most recent version.

We will include the minimum required version of numba in the next release to avoid the issue from the installation.

Let me know if the problem persists.

AzulGarza avatar Aug 02 '22 16:08 AzulGarza

@all-contributors please add @jdegene for bug

mergenthaler avatar Aug 03 '22 01:08 mergenthaler

@mergenthaler

I've put up a pull request to add @jdegene! :tada:

allcontributors[bot] avatar Aug 03 '22 01:08 allcontributors[bot]

Thx for the update on this. jfyi, I've tried with numba versions 0.54.0 and 0.55.0 and both work as well

jdegene avatar Aug 03 '22 07:08 jdegene