Repository: sktime/sktime (Python)

Issue:
[BUG] sktime 0.17.1 breaks in-sample `predict_quantiles` in `pmdarima` adapter
**Describe the bug**
The latest release of sktime breaks in-sample predictions for ARIMA models

**To Reproduce**

```python
from sktime.datasets import load_airline
from sktime.forecasting.arima import ARIMA

y = load_airline()
forecaster = ARIMA(order=(1, 1, 0), seasonal_order=(0, 1, 0, 12), suppress_warnings=True)
forecaster.fit(y)
forecaster.predict_quantiles(fh=y.index, X=None, alpha=[0.05, 0.95])
```

```python-traceback
'numpy.ndarray' object has no attribute 'to_pandas'
  File "C:\Users\Nikhil\.conda\envs\pycaret_dev_sktime_17p1\Lib\site-packages\sktime\forecasting\base\adapters\_pmdarima.py", line 169, in _predict_in_sample
    index=fh_abs.to_pandas(), columns=["lower", "upper"]
  File "C:\Users\Nikhil\.conda\envs\pycaret_dev_sktime_17p1\Lib\site-packages\sktime\forecasting\base\adapters\_pmdarima.py", line 293, in _predict_interval
    _, y_pred_int = self._predict_in_sample(fh_ins, **kwargs)
  File "C:\Users\Nikhil\.conda\envs\pycaret_dev_sktime_17p1\Lib\site-packages\sktime\forecasting\base\_base.py", line 2079, in _predict_quantiles
    pred_a = self._predict_interval(fh=fh, X=X, coverage=[coverage])
  File "C:\Users\Nikhil\.conda\envs\pycaret_dev_sktime_17p1\Lib\site-packages\sktime\forecasting\base\_base.py", line 559, in predict_quantiles
    quantiles = self._predict_quantiles(fh=fh, X=X_inner, alpha=alpha)
  File "C:\Users\Nikhil\OneDrive\my_libraries\my_python_libraries\pycaret\pycaret_dev\time_series_debug.py", line 28, in <module>
    forecaster.predict_quantiles(fh=y.index, X=None, alpha=[0.05, 0.95])
  File "C:\Users\Nikhil\.conda\envs\pycaret_dev_sktime_17p1\Lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\Nikhil\.conda\envs\pycaret_dev_sktime_17p1\Lib\runpy.py", line 196, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
AttributeError: 'numpy.ndarray' object has no attribute 'to_pandas'
```

**Expected behavior**
This was working in sktime 0.16.x and also works in 0.17.0

**Additional context**
pycaret tests failing due to sktime 0.17.1 upgrade: https://github.com/pycaret/pycaret/actions/runs/4674814052/jobs/8279339435#logs


**Versions**
<details>
System:
    python: 3.10.10 | packaged by Anaconda, Inc. | (main, Mar 21 2023, 18:39:17) [MSC v.1916 64 bit (AMD64)]
executable: C:\Users\Nikhil\.conda\envs\pycaret_dev_sktime_17p1\python.exe
   machine: Windows-10-10.0.19044-SP0

Python dependencies:
          pip: 23.0.1
       sktime: 0.17.1
      sklearn: 1.2.2
        numpy: 1.23.5
        scipy: 1.10.1
       pandas: 1.5.3
   matplotlib: 3.7.1
       joblib: 1.2.0
  statsmodels: 0.13.5
        numba: 0.56.4
     pmdarima: 2.0.3
      tsfresh: None
   tensorflow: None
tensorflow_probability: None
</details>

<!-- Thanks for contributing! -->



Discussion:
Thanks for reporting!

This is a consequence of the `pandas 2` upgrade, and it seems like in-sample predictions of `predict_quantiles` were not tested.

Fix is here, but we will also need to add tests.
https://github.com/sktime/sktime/pull/4469 
FYI @yarnabrina
@ngupta23, on the bright side, out-of-sample it's `pandas 2` compatible now 😐
new tests for all proba forecasters in-sample here: https://github.com/sktime/sktime/pull/4470
also present in `_StatsForecastAdapter` which looks like copy-paste from `_PmdArimaAdapter`



Patch:
diff --git a/sktime/forecasting/base/adapters/_pmdarima.py b/sktime/forecasting/base/adapters/_pmdarima.py
index e32332fd124..cf72aff50e4 100644
--- a/sktime/forecasting/base/adapters/_pmdarima.py
+++ b/sktime/forecasting/base/adapters/_pmdarima.py
@@ -165,9 +165,7 @@ def _predict_in_sample(
         if return_pred_int:
             pred_ints = []
             for a in alpha:
-                pred_int = pd.DataFrame(
-                    index=fh_abs.to_pandas(), columns=["lower", "upper"]
-                )
+                pred_int = pd.DataFrame(index=fh_abs, columns=["lower", "upper"])
                 result = self._forecaster.predict_in_sample(
                     start=start,
                     end=end,
diff --git a/sktime/forecasting/base/adapters/_statsforecast.py b/sktime/forecasting/base/adapters/_statsforecast.py
index 8b0d61a3457..7209e5637e0 100644
--- a/sktime/forecasting/base/adapters/_statsforecast.py
+++ b/sktime/forecasting/base/adapters/_statsforecast.py
@@ -145,9 +145,7 @@ def _predict_in_sample(
         if return_pred_int:
             pred_ints = []
             for a in alpha:
-                pred_int = pd.DataFrame(
-                    index=fh_abs.to_pandas(), columns=["lower", "upper"]
-                )
+                pred_int = pd.DataFrame(index=fh_abs, columns=["lower", "upper"])
                 result = self._forecaster.predict_in_sample(level=int(100 * a))
                 pred_int.loc[fh_abs] = result.drop("mean", axis=1).values[fh_idx, :]
                 pred_ints.append(pred_int)


Test patch:
diff --git a/sktime/forecasting/tests/test_pmdarima.py b/sktime/forecasting/tests/test_pmdarima.py
new file mode 100644
index 00000000000..f01914447b5
--- /dev/null
+++ b/sktime/forecasting/tests/test_pmdarima.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+"""Tests for the ARIMA estimator and _PmdArimaAdapter."""
+
+import pytest
+
+from sktime.datasets import load_airline
+from sktime.forecasting.arima import ARIMA
+from sktime.utils.validation._dependencies import _check_estimator_deps
+
+
+@pytest.mark.skipif(
+    not _check_estimator_deps(ARIMA, severity="none"),
+    reason="skip test if required soft dependency not available",
+)
+def test_ARIMA_pred_quantiles_insample():
+    """Test ARIMA predict_quantiles with in-sample fh. Failure condition of #4468."""
+    y = load_airline()
+    forecaster = ARIMA(order=(1, 1, 0), seasonal_order=(0, 1, 0, 12))
+    forecaster.fit(y)
+    forecaster.predict_quantiles(fh=y.index, X=None, alpha=[0.05, 0.95])