MissingDataError: exog contains inf or nans in adfuller test

  python-3.x, statistics, statsmodels

I am trying to conclude if a dataset is stationary or not. To do this i have this:

import pandas as pd
import pandas_datareader.data as web
from statsmodels.tsa.stattools import coint, adfuller

def stationarity_test(X, cutoff=0.01):
    # H_0 in adfuller is unit root exists (non-stationary)
    # We must observe significant p-value to convince ourselves that the series is stationary
    pvalue = adfuller(X)[1]
    if pvalue < cutoff:
        print('p-value = ' + str(pvalue) + ' The series ' + X.name +' is likely stationary.')
    else:
        print('p-value = ' + str(pvalue) + ' The series ' + X.name +' is likely non-stationary.')

df = web.DataReader('goog', 'yahoo')
df.dropna()
a = df['Close'].pct_change() 
stationarity_test(a)

However this is producing this error:

MissingDataError: exog contains inf or nans

This is odd since :

stationarity_test(df['Close'])

produces:

p-value = 1.0 The series Close is likely non-stationary.

There are no inf or nan in the data and just to be sure i have df.dropna Why am i getting this error?

Source: Python-3x Questions

LEAVE A COMMENT