Repository: statsmodels/statsmodels

Issue:
Revisit -> arma_order_select_ic function throw "IndexError: index 0 is out of bounds for axis 0 with size 0" #4727
Hi guys,

The issue is the same of [this link (closed).](https://github.com/statsmodels/statsmodels/issues/4727) I commented in here as well but not sure if it has follow up because it is closed.

Sorry to come back with this topic but I'm struggling a bit with the same scenario having the ` IndexError: index 0 is out of bounds for axis 0 with size 0` error.

 I'll paste the snippet of code here. Basically the data source comes from a `pandas Series` coming from a DataFrame which has been converted into `np.array` in order to avoid the error. 

Not sure why. I've tried to convert the data into arrays via few methods like the one in the example, the `.values`, `np.asarray`, etc and still giving the same error. Basically what I'm tring to get is the _SBIC and AIC_ for the series as you can imagine.

The version is `statsmodels            0.13.2`.

If you can give a hand with this would be really appreciated. As said, not sure if it is me doing something wrong or is a general issue.

Thanks in advance guys.

Input: 
```
print(type(data['dhp']))
y = np.array(data['dhp'])
print(y.shape)
print(type(y))
print(data['dhp'].tail())
sm.graphics.tsa.plot_acf(data['dhp'], lags=15)
plt.show()

res1 = smt.arma_order_select_ic(y , max_ar=5, max_ma=4, ic=['aic', 'bic'],fit_kw={'method':'css-mle','solver':'bfgs'})
```

Output:

```
PS C:\Users\javie\Desktop\Ejercicio Series Temporales ARIMA> & C:/Users/javie/miniconda3/python.exe "c:/Users/javie/Desktop/Ejercicio Series Temporales ARIMA/modelo.py"
<class 'pandas.core.series.Series'>
(326,)
<class 'numpy.ndarray'>
Month
2017-11-01   -0.519801
2017-12-01    0.556220
2018-01-01    0.284286
2018-02-01   -0.639190
2018-03-01    0.581234
Name: dhp, dtype: float64
Traceback (most recent call last):
  File "c:\Users\javie\Desktop\Ejercicio Series Temporales ARIMA\modelo.py", line 76, in <module>
    res1 = smt.arma_order_select_ic(y , max_ar=5, max_ma=4, ic=['aic', 'bic'],fit_kw={'method':'css-mle','solver':'bfgs'})
  File "C:\Users\javie\miniconda3\lib\site-packages\statsmodels\tsa\stattools.py", line 1866, in arma_order_select_ic
    min_res.update({i + "_min_order": (mins[0][0], mins[1][0])})
IndexError: index 0 is out of bounds for axis 0 with size 0
```



Discussion:
Can you post the data used to reproduce the error?

Resolving patch:
diff --git a/statsmodels/tsa/stattools.py b/statsmodels/tsa/stattools.py
--- a/statsmodels/tsa/stattools.py
+++ b/statsmodels/tsa/stattools.py
@@ -1881,8 +1881,10 @@ def arma_order_select_ic(
     # add the minimums to the results dict
     min_res = {}
     for i, result in res.items():
-        mins = np.where(result.min().min() == result)
-        min_res.update({i + "_min_order": (mins[0][0], mins[1][0])})
+        delta = np.ascontiguousarray(np.abs(result.min().min() - result))
+        ncols = delta.shape[1]
+        loc = np.argmin(delta)
+        min_res.update({i + "_min_order": (loc // ncols, loc % ncols)})
     res.update(min_res)
 
     return Bunch(**res)


Test patch: