'Missing data error on adfuller test although I cleaned for inf and nans

Currently I am working on a data set which has many time-dependent variables. I ran adfuller for all and changed the non-stationary ones to percentage change (thinking about using diff()) with:

dfnstpct = dfnst.pct_change

Because I have some zeros I ran some cleaning afterwards:

dfnstpct.replace([np.inf, -np.inf], np.nan, inplace=True)
dfnstpct.fillna(0)

Then I run adf on these variables again to check:

from statsmodels.tsa.stattools import adfuller
print("Observations of Dickey-fuller test \n")
print("stationary columns \n")

adf_results = {}
col_list2 = []
for col in dfnstpct.columns.values:
    dftest = adfuller(dfnstpct[col],autolag='AIC')
    if dftest[1] < 0.05:
        print(col + " is stationary")

Although I cleaned the data it gives me an error message: MissingDataError: exog contains inf or nans

Complete error message:

Observations of Dickey-fuller test 

stationary columns 

---------------------------------------------------------------------------
MissingDataError                          Traceback (most recent call last)
<ipython-input-41-42aac72bbc14> in <module>
      7 col_list2 = []
      8 for col in dfnstpct.columns.values:
----> 9     dftest = adfuller(dfnstpct['VLCC Fleet Development'],autolag='AIC')
     10     if dftest[1] < 0.05:
     11         col_list2.append(col)

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/tsa/stattools.py in adfuller(x, maxlag, regression, autolag, store, regresults)
    265 
    266         if not regresults:
--> 267             icbest, bestlag = _autolag(OLS, xdshort, fullRHS, startlag,
    268                                        maxlag, autolag)
    269         else:

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/tsa/stattools.py in _autolag(mod, endog, exog, startlag, maxlag, method, modargs, fitargs, regresults)
     93     method = method.lower()
     94     for lag in range(startlag, startlag + maxlag + 1):
---> 95         mod_instance = mod(endog, exog[:, :lag], *modargs)
     96         results[lag] = mod_instance.fit()
     97 

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/regression/linear_model.py in __init__(self, endog, exog, missing, hasconst, **kwargs)
    856     def __init__(self, endog, exog=None, missing='none', hasconst=None,
    857                  **kwargs):
--> 858         super(OLS, self).__init__(endog, exog, missing=missing,
    859                                   hasconst=hasconst, **kwargs)
    860         if "weights" in self._init_keys:

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/regression/linear_model.py in __init__(self, endog, exog, weights, missing, hasconst, **kwargs)
    699         else:
    700             weights = weights.squeeze()
--> 701         super(WLS, self).__init__(endog, exog, missing=missing,
    702                                   weights=weights, hasconst=hasconst, **kwargs)
    703         nobs = self.exog.shape[0]

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/regression/linear_model.py in __init__(self, endog, exog, **kwargs)
    188     """
    189     def __init__(self, endog, exog, **kwargs):
--> 190         super(RegressionModel, self).__init__(endog, exog, **kwargs)
    191         self._data_attr.extend(['pinv_wexog', 'wendog', 'wexog', 'weights'])
    192 

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/base/model.py in __init__(self, endog, exog, **kwargs)
    234 
    235     def __init__(self, endog, exog=None, **kwargs):
--> 236         super(LikelihoodModel, self).__init__(endog, exog, **kwargs)
    237         self.initialize()
    238 

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/base/model.py in __init__(self, endog, exog, **kwargs)
     74         missing = kwargs.pop('missing', 'none')
     75         hasconst = kwargs.pop('hasconst', None)
---> 76         self.data = self._handle_data(endog, exog, missing, hasconst,
     77                                       **kwargs)
     78         self.k_constant = self.data.k_constant

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/base/model.py in _handle_data(self, endog, exog, missing, hasconst, **kwargs)
     98 
     99     def _handle_data(self, endog, exog, missing, hasconst, **kwargs):
--> 100         data = handle_data(endog, exog, missing, hasconst, **kwargs)
    101         # kwargs arrays could have changed, easier to just attach here
    102         for key in kwargs:

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/base/data.py in handle_data(endog, exog, missing, hasconst, **kwargs)
    669 
    670     klass = handle_data_class_factory(endog, exog)
--> 671     return klass(endog, exog=exog, missing=missing, hasconst=hasconst,
    672                  **kwargs)

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/base/data.py in __init__(self, endog, exog, missing, hasconst, **kwargs)
     85         self.const_idx = None
     86         self.k_constant = 0
---> 87         self._handle_constant(hasconst)
     88         self._check_integrity()
     89         self._cache = {}

/anaconda/envs/azureml_py38/lib/python3.8/site-packages/statsmodels/base/data.py in _handle_constant(self, hasconst)
    131             exog_max = np.max(self.exog, axis=0)
    132             if not np.isfinite(exog_max).all():
--> 133                 raise MissingDataError('exog contains inf or nans')
    134             exog_min = np.min(self.exog, axis=0)
    135             const_idx = np.where(exog_max == exog_min)[0].squeeze()

MissingDataError: exog contains inf or nans


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source