internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: sktime/sktime

Issue:
[BUG] High memory consumption in `get_cutoff` when using a `DataFrame` with `MultiIndex`
**Describe the bug**
The method `get_cutoff` when applied to a `DataFrame` dataset with hierarchical index performs a lot of redundant computations. This results in OOM errors and crashes when training on very large datasets. For example, I cannot train `AutoETS` model on the `electricity` dataset from the Monash repository on a machine with 300GB of RAM.

The problem lies in the following line of code in [`sktime.datatypes._utilities.py`](https://github.com/alan-turing-institute/sktime/blob/5767dbaac759ed6ac43a8977f4c46beb93d0f18c/sktime/datatypes/_utilities.py#L299) 
```python
series_idx = [obj.loc[x].index.get_level_values(-1) for x in idx.droplevel(-1)]
```
Suppose our dataset consists of 300 time series each of length 20000, stacked into a `DataFrame` with `MultiIndex` (level 0 = time series ID, level 1 = timestamp). The above line of code will try to create an array with 20000 * 20000 entries, even though we actually only need an array with 300 * 20000 entries.

**To Reproduce**
```python
from sktime.datatypes import get_cutoff
from sktime.utils._testing.hierarchical import _make_hierarchical

df = _make_hierarchical((300,), max_timepoints=20000, min_timepoints=20000)
get_cutoff(df)  # program gets stuck and eventually crashes with in an OOM error
```

**Expected behavior**
The code shouldn't result in an OOM error.

**Additional context**
An easy solution to this problem is to replace L299 in [`sktime.datatypes._utilities.py`](https://github.com/alan-turing-institute/sktime/blob/5767dbaac759ed6ac43a8977f4c46beb93d0f18c/sktime/datatypes/_utilities.py#L299) 
```python
series_idx = [obj.loc[x].index.get_level_values(-1) for x in idx.droplevel(-1)]
```
with
```python
series_idx = [obj.loc[x].index.get_level_values(-1) for x in idx.droplevel(-1).unique()]
```

**Versions**
```
Python dependencies:
          pip: 22.1.2
   setuptools: 63.2.0
      sklearn: 1.1.1
       sktime: 0.13.0
  statsmodels: 0.13.2
        numpy: 1.22.4
        scipy: 1.8.1
       pandas: 1.4.3
   matplotlib: None
       joblib: 1.1.0
        numba: 0.55.2
     pmdarima: None
      tsfresh: None
```



Discussion:

Resolving patch:
diff --git a/sktime/datatypes/_utilities.py b/sktime/datatypes/_utilities.py
--- a/sktime/datatypes/_utilities.py
+++ b/sktime/datatypes/_utilities.py
@@ -296,7 +296,9 @@ def sub_idx(idx, ix, return_index=True):
     # pd-multiindex (Panel) and pd_multiindex_hier (Hierarchical)
     if isinstance(obj, pd.DataFrame) and isinstance(obj.index, pd.MultiIndex):
         idx = obj.index
-        series_idx = [obj.loc[x].index.get_level_values(-1) for x in idx.droplevel(-1)]
+        series_idx = [
+            obj.loc[x].index.get_level_values(-1) for x in idx.droplevel(-1).unique()
+        ]
         cutoffs = [sub_idx(x, ix, return_index) for x in series_idx]
         return agg(cutoffs)
 


Test patch:
Repository: sktime/sktime

Issue:
[ENH] check override/defaulting of "prediction intervals" adders
From the presentation of @bethrice44:

if we take a "prediction intervals adder" wrapper, e.g., one adding `predict_intervals`, to add prediction intervals to an estimator that already has a *different* probabilistic prediction method implemented, this may lead to unexpected behaviour.

For example, assume the inner method has `predict_quantiles` implemented, and `predict_intervals` uses the default method which calls `predict_quantiles`. 

The wrapper overwrites `predict_intervals`, and it might not overwrite `predict_quantiles`. Then, the predictoins from `predict_intervals` and `predict_quantiles` will be inconsistent.

Instead, the wrapper perhaps should (?) overwrite `predict_quantiles` with the base class default?


Discussion:

Resolving patch:
diff --git a/sktime/forecasting/conformal.py b/sktime/forecasting/conformal.py
--- a/sktime/forecasting/conformal.py
+++ b/sktime/forecasting/conformal.py
@@ -244,6 +244,36 @@ def _predict_interval(self, fh, X=None, coverage=None):
 
         return pred_int.convert_dtypes()
 
+    def _predict_quantiles(self, fh, X, alpha):
+        """Compute/return prediction quantiles for a forecast.
+
+        private _predict_quantiles containing the core logic,
+            called from predict_quantiles and default _predict_interval
+
+        Parameters
+        ----------
+        fh : guaranteed to be ForecastingHorizon
+            The forecasting horizon with the steps ahead to to predict.
+        X : optional (default=None)
+            guaranteed to be of a type in self.get_tag("X_inner_mtype")
+            Exogeneous time series to predict from.
+        alpha : list of float, optional (default=[0.5])
+            A list of probabilities at which quantile forecasts are computed.
+
+        Returns
+        -------
+        quantiles : pd.DataFrame
+            Column has multi-index: first level is variable name from y in fit,
+                second level being the values of alpha passed to the function.
+            Row index is fh, with additional (upper) levels equal to instance levels,
+                    from y seen in fit, if y_inner_mtype is Panel or Hierarchical.
+            Entries are quantile forecasts, for var in col index,
+                at quantile probability in second col index, for the row index.
+        """
+        pred_int = BaseForecaster._predict_quantiles(self, fh, X, alpha)
+
+        return pred_int
+
     def _compute_sliding_residuals(self, y, X, forecaster, initial_window, sample_frac):
         """Compute sliding residuals used in uncertainty estimates.
 


Test patch:
Repository: sktime/sktime

Issue:
[ENH] Allow lists as `cutoff` argument in `CutoffSplitter`
Currently, `CutoffSplitter` accepts only `np.array` or `pd.Index` as a `cutoff` argument. I do not see why it can not be a list similar to `fh` argument.


Discussion:
Yes, agreed.

Would the best solution involve factoring out coercion functionality and using them in both places?
Or, internally, putting the `cutoffs` argument in a `ForecastingHorizon` too?

Resolving patch:
diff --git a/sktime/forecasting/model_selection/_split.py b/sktime/forecasting/model_selection/_split.py
--- a/sktime/forecasting/model_selection/_split.py
+++ b/sktime/forecasting/model_selection/_split.py
@@ -684,7 +684,7 @@ class CutoffSplitter(BaseSplitter):
 
     Parameters
     ----------
-    cutoffs : np.array or pd.Index
+    cutoffs : list or np.array or pd.Index
         Cutoff points, positive and integer- or datetime-index like.
         Type should match the type of `fh` input.
     fh : int, timedelta, list or np.ndarray of ints or timedeltas
diff --git a/sktime/utils/validation/forecasting.py b/sktime/utils/validation/forecasting.py
--- a/sktime/utils/validation/forecasting.py
+++ b/sktime/utils/validation/forecasting.py
@@ -34,7 +34,7 @@
 )
 from sktime.utils.validation.series import check_equal_time_index, check_series
 
-ACCEPTED_CUTOFF_TYPES = np.ndarray, pd.Index
+ACCEPTED_CUTOFF_TYPES = list, np.ndarray, pd.Index
 VALID_CUTOFF_TYPES = Union[ACCEPTED_CUTOFF_TYPES]
 
 


Test patch:
diff --git a/sktime/forecasting/tests/_config.py b/sktime/forecasting/tests/_config.py
--- a/sktime/forecasting/tests/_config.py
+++ b/sktime/forecasting/tests/_config.py
@@ -27,14 +27,15 @@
 from sktime.utils._testing.series import _make_series
 
 # We here define the parameter values for unit testing.
-TEST_CUTOFFS_INT = [np.array([21, 22]), np.array([3, 7, 10])]
+TEST_CUTOFFS_INT_LIST = [[21, 22], [3, 7, 10]]
+TEST_CUTOFFS_INT_ARR = [np.array([21, 22]), np.array([3, 7, 10])]
 # The following timestamps correspond
 # to the above integers for `_make_series(all_positive=True)`
 TEST_CUTOFFS_TIMESTAMP = [
     pd.to_datetime(["2000-01-22", "2000-01-23"]),
     pd.to_datetime(["2000-01-04", "2000-01-08", "2000-01-11"]),
 ]
-TEST_CUTOFFS = [*TEST_CUTOFFS_INT, *TEST_CUTOFFS_TIMESTAMP]
+TEST_CUTOFFS = [*TEST_CUTOFFS_INT_LIST, *TEST_CUTOFFS_INT_ARR, *TEST_CUTOFFS_TIMESTAMP]
 
 TEST_WINDOW_LENGTHS_INT = [1, 5]
 TEST_WINDOW_LENGTHS_TIMEDELTA = [pd.Timedelta(1, unit="D"), pd.Timedelta(5, unit="D")]
Repository: sktime/sktime

Issue:
[BUG] changelog generator picks up merges into branches other than `main`
The changelog generator seems to pick up PR that were not merged into `main` but into another branch.

Current example for 0.13.0 release at pre-0.13.0 state: #2941, #2952.

FYI @lmmentel 


Discussion:
I think there is an option to only get changes against main, need to look into it.

Resolving patch:
diff --git a/build_tools/changelog.py b/build_tools/changelog.py
--- a/build_tools/changelog.py
+++ b/build_tools/changelog.py
@@ -23,6 +23,7 @@
 def fetch_merged_pull_requests(page: int = 1) -> List[Dict]:  # noqa
     "Fetch a page of pull requests"
     params = {
+        "base": "main",
         "state": "closed",
         "page": page,
         "per_page": 50,
@@ -160,6 +161,6 @@ def render_changelog(prs, assigned):  # noqa
     if diff["total_commits"] != len(pulls):
         raise ValueError(
             "Something went wrong and not all PR were fetched. "
-            f'There is {len(pulls)} PRs but {diff["total_commits"]} in the diff'
+            f'There are {len(pulls)} PRs but {diff["total_commits"]} in the diff. '
             "Please verify that all PRs are included in the changelog."
         )  # noqa


Test patch:
Repository: sktime/sktime

Issue:
[BUG] `DrCIF` failure due to single class in sub-sample
`DrCIF` fails stochastically under windows, on `test_contracted_drcif`, the line `assert len(drcif.estimators_) > 1`, because `drcif.estimators_` ends up having length 1.

Do you have an idea what is going on here, @MatthewMiddlehurst?

We are fixing the random seed, but the resulting samples might change with versions of the underlying packages or the operating system.

Example here: https://github.com/alan-turing-institute/sktime/runs/7706482325?check_suite_focus=true


Discussion:

Resolving patch:
diff --git a/sktime/classification/sklearn/_continuous_interval_tree.py b/sktime/classification/sklearn/_continuous_interval_tree.py
--- a/sktime/classification/sklearn/_continuous_interval_tree.py
+++ b/sktime/classification/sklearn/_continuous_interval_tree.py
@@ -126,8 +126,10 @@ def fit(self, X, y):
         for index, classVal in enumerate(self.classes_):
             self._class_dictionary[classVal] = index
 
+        # escape if only one class seen
         if self.n_classes_ == 1:
-            raise ValueError("fit input y must contain more than one class")
+            self._is_fitted = True
+            return self
 
         le = preprocessing.LabelEncoder()
         y = le.fit_transform(y)
@@ -196,6 +198,12 @@ def predict_proba(self, X):
                 f"This instance of {self.__class__.__name__} has not "
                 f"been fitted yet; please call `fit` first."
             )
+
+        # treat case of single class seen in fit
+        if self.n_classes_ == 1:
+            n_instances = len(X)
+            return np.repeat([[1]], n_instances, axis=0)
+
         if isinstance(X, np.ndarray) and len(X.shape) == 3 and X.shape[1] == 1:
             X = np.reshape(X, (X.shape[0], -1))
         elif not isinstance(X, np.ndarray) or len(X.shape) > 2:
diff --git a/sktime/classification/sklearn/_rotation_forest.py b/sktime/classification/sklearn/_rotation_forest.py
--- a/sktime/classification/sklearn/_rotation_forest.py
+++ b/sktime/classification/sklearn/_rotation_forest.py
@@ -170,8 +170,10 @@ def fit(self, X, y):
         for index, classVal in enumerate(self.classes_):
             self._class_dictionary[classVal] = index
 
+        # escape if only one class seen
         if self.n_classes_ == 1:
-            raise ValueError("fit input y must contain more than one class")
+            self._is_fitted = True
+            return self
 
         time_limit = self.time_limit_in_minutes * 60
         start_time = time.time()
@@ -279,6 +281,12 @@ def predict_proba(self, X):
                 f"This instance of {self.__class__.__name__} has not "
                 f"been fitted yet; please call `fit` first."
             )
+
+        # treat case of single class seen in fit
+        if self.n_classes_ == 1:
+            n_instances = len(X)
+            return np.repeat([[1]], n_instances, axis=0)
+
         if isinstance(X, np.ndarray) and len(X.shape) == 3 and X.shape[1] == 1:
             X = np.reshape(X, (X.shape[0], -1))
         elif isinstance(X, pd.DataFrame) and len(X.shape) == 2:


Test patch:
Repository: sktime/sktime

Issue:
[BUG] pmdarima 2.0.0 incompatibility - return indices
Soft dependency `pmdarima` 2.0.0 was released a few hours ago, and it seems to break our `ARIMA` interface.

Suspicion: return indices are now absolute and no longer relative to the cutoff.


Discussion:

Resolving patch:
diff --git a/sktime/forecasting/base/adapters/_pmdarima.py b/sktime/forecasting/base/adapters/_pmdarima.py
--- a/sktime/forecasting/base/adapters/_pmdarima.py
+++ b/sktime/forecasting/base/adapters/_pmdarima.py
@@ -171,10 +171,12 @@ def _predict_in_sample(
                 pred_int.loc[fh_abs] = result[1][fh_idx, :]
                 pred_ints.append(pred_int)
             # unpack results
-            y_pred.loc[fh_abs] = result[0][fh_idx]
+            result = pd.Series(result[0]).iloc[fh_idx]
+            y_pred.loc[fh_abs] = result
             return y_pred, pred_ints
         else:
-            y_pred.loc[fh_abs] = result[fh_idx]
+            result = pd.Series(result).iloc[fh_idx]
+            y_pred.loc[fh_abs] = result
             return y_pred
 
     def _predict_fixed_cutoff(
@@ -220,7 +222,9 @@ def _predict_fixed_cutoff(
                 pred_ints.append(pred_int)
             return result[0], pred_ints
         else:
-            return pd.Series(result[fh_idx], index=fh_abs)
+            result = pd.Series(result).iloc[fh_idx]
+            result.index = fh_abs
+            return result
 
     def _predict_interval(self, fh, X=None, coverage=0.90):
         """Compute/return prediction quantiles for a forecast.


Test patch:
Repository: sktime/sktime

Issue:
[DOC] Docstring lists wrong default for `SlidingWindowSplitter` parameter `start_with_window`
Default for this argument is actually True.

https://github.com/alan-turing-institute/sktime/blob/824804c785fb97e20c29045ee058181ceeb9418b/sktime/forecasting/model_selection/_split.py#L1107


Discussion:
Thanks for reporting - should be a really easy fix (good first issue)
Hi, I am a beginner in Open Source, and I would love to start contributing to sktime with this issue. I have looked at the code base and figured out that this error is in the documentation of the SlidingWindowSplitter function. Am i right?

> Hi, I am a beginner in Open Source, and I would love to start contributing to sktime with this issue. I have looked at the code base and figured out that this error is in the documentation of the SlidingWindowSplitter function. Am i right?

Yes, happy bugslaying!

Resolving patch:
diff --git a/sktime/forecasting/model_selection/_split.py b/sktime/forecasting/model_selection/_split.py
--- a/sktime/forecasting/model_selection/_split.py
+++ b/sktime/forecasting/model_selection/_split.py
@@ -1106,7 +1106,7 @@ class SlidingWindowSplitter(BaseWindowSplitter):
         Step length between windows
     initial_window : int or timedelta or pd.DateOffset, optional (default=None)
         Window length of first window
-    start_with_window : bool, optional (default=False)
+    start_with_window : bool, optional (default=True)
         - If True, starts with full window.
         - If False, starts with empty window.
 
diff --git a/sktime/transformations/series/boxcox.py b/sktime/transformations/series/boxcox.py
--- a/sktime/transformations/series/boxcox.py
+++ b/sktime/transformations/series/boxcox.py
@@ -265,6 +265,7 @@ def _transform(self, X, y=None):
         y : ignored argument for interface compatibility
             Additional data, e.g., labels for transformation
 
+
         Returns
         -------
         Xt : 2D np.ndarray
@@ -285,6 +286,7 @@ def _inverse_transform(self, X, y=None):
         y : ignored argument for interface compatibility
             Additional data, e.g., labels for transformation
 
+
         Returns
         -------
         Xt : 2D np.ndarray


Test patch:
Repository: sktime/sktime

Issue:
[BUG] TapNet test failures and long test times
TapNet is currently failing the macOS 3.7 test (`Install and test / test-unix (3.7, macOS-11) (pull_request)`) in PR #3523. The PR makes no changes relevant to TapNet or DL estimators, and the test times are extremely high.

https://github.com/sktime/sktime/actions/runs/3174214839/jobs/5170841022

![image](https://user-images.githubusercontent.com/25731235/193617763-fe72fe51-8338-47c6-947f-0f03173aa204.png)




Discussion:
FYI @achieveordie, you added these recently, no?
https://github.com/sktime/sktime/pull/3386
can verify this on another branch. The classifier needs a get_test_params method with a faster configuration

@classmethod
    def get_test_params(cls, parameter_set="default"):
        """Return testing parameter settings for the estimator.


Resolving patch:
diff --git a/sktime/classification/deep_learning/tapnet.py b/sktime/classification/deep_learning/tapnet.py
--- a/sktime/classification/deep_learning/tapnet.py
+++ b/sktime/classification/deep_learning/tapnet.py
@@ -3,6 +3,8 @@
 
 __author__ = [
     "Jack Russon",
+    "TonyBagnall",
+    "achieveordie",
 ]
 __all__ = [
     "TapNetClassifier",
@@ -230,3 +232,33 @@ def _fit(self, X, y):
         )
 
         return self
+
+    @classmethod
+    def get_test_params(cls, parameter_set="default"):
+        """Return testing parameter settings for the estimator.
+
+        Parameters
+        ----------
+        parameter_set : str, default="default"
+            Name of the set of test parameters to return, for use in tests. If no
+            special parameters are defined for a value, will return `"default"` set.
+            For classifiers, a "default" set of parameters should be provided for
+            general testing, and a "results_comparison" set for comparing against
+            previously recorded results if the general set does not produce suitable
+            probabilities to compare against.
+
+        Returns
+        -------
+        params : dict or list of dict, default={}
+            Parameters to create testing instances of the class.
+            Each dict are parameters to construct an "interesting" test instance, i.e.,
+            `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance.
+            `create_test_instance` uses the first (or only) dictionary in `params`.
+        """
+        return {
+            "n_epochs": 50,
+            "batch_size": 32,
+            "filter_sizes": (128, 128, 64),
+            "dilation": 2,
+            "layers": (200, 100),
+        }


Test patch:
Repository: sktime/sktime

Issue:
[BUG] check_estimator tests_to_exclude doesn't exclude the specified tests
**Describe the bug**
<!--
A clear and concise description of what the bug is.
-->
Specifying a list of tests in the `tests_to_exclude` variable in `check_estimator` doesn't exclude the specified tests.

**To Reproduce**
<!--
Add a Minimal, Complete, and Verifiable example (for more details, see e.g. https://stackoverflow.com/help/mcve

If the code is too long, feel free to put it in a public gist and link it in the issue: https://gist.github.com
-->

```python
from sktime.utils.estimator_checks import check_estimator
from sktime.forecasting.naive import NaiveForecaster

log = check_estimator(
    NaiveForecaster, return_exceptions=True, tests_to_exclude=["test_predict_residuals"]
)

should_be_empty = [key for key in log.keys() if "test_predict_residuals" in key]

assert len(should_be_empty) == 0
```

**Expected behavior**
<!--
A clear and concise description of what you expected to happen.
-->
Any tests in the tests_to_excluded should be actually excluded!
(FYI for whoever takes this on. The problem is somewhere [here](https://github.com/sktime/sktime/blob/fe6f43c2e06e586c2dd16102aef5eef4bd4b6ce6/sktime/tests/test_all_estimators.py#L378))

**Versions**
<details>

<!--
Please run the following code snippet and paste the output here:
 
from sktime import show_versions; show_versions()
-->
sktime==0.13.4  
python==3.8.5
</details>  

<!-- Thanks for contributing! -->



Discussion:

Resolving patch:
diff --git a/sktime/utils/estimator_checks.py b/sktime/utils/estimator_checks.py
--- a/sktime/utils/estimator_checks.py
+++ b/sktime/utils/estimator_checks.py
@@ -133,6 +133,8 @@ def is_estimator(obj):
             return_exceptions=return_exceptions,
             tests_to_run=tests_to_run,
             fixtures_to_run=fixtures_to_run,
+            tests_to_exclude=tests_to_exclude,
+            fixtures_to_exclude=fixtures_to_exclude,
         )
         results.update(results_scitype)
 


Test patch:
diff --git a/sktime/utils/tests/test_check_estimator.py b/sktime/utils/tests/test_check_estimator.py
--- a/sktime/utils/tests/test_check_estimator.py
+++ b/sktime/utils/tests/test_check_estimator.py
@@ -37,8 +37,15 @@ def test_check_estimator_does_not_raise(estimator_class):
 
 def test_check_estimator_subset_tests():
     """Test that subsetting by tests_to_run and tests_to_exclude works as intended."""
-    tests_to_run = ["test_get_params", "test_set_params", "test_clone", "test_repr"]
-    tests_to_exclude = ["test_repr"]
+    tests_to_run = [
+        "test_get_params",
+        "test_set_params",
+        "test_clone",
+        "test_repr",
+        "test_capability_inverse_tag_is_correct",
+        "test_remember_data_tag_is_correct",
+    ]
+    tests_to_exclude = ["test_repr", "test_remember_data_tag_is_correct"]
 
     expected_tests = set(tests_to_run).difference(tests_to_exclude)
Repository: sktime/sktime

Issue:
[DOC] sktime docs should link clearly to example notebooks
It seems that the sktime doc user journey does not lead clearly to the example notebooks when starting on the doc page.

This should be investigated and reworked.

Related issue: https://github.com/alan-turing-institute/sktime/issues/2127




Discussion:
@fkiraly Can I work on this issue.
sure! I would suggest starting to pick up sth in #2127
@fkiraly According to sth #2127 I think tutorials on the metrics, distances, and kernels
and algorithms have not been done.I would start working on any one of these tutorials.
I have already been working on a transformers tutorial, this issue is about making sure that the notebooks appear in the right places and are linked to. Let us know if you need an explanation of how the sktime doc sources are structured, you could attend one of the Fri sessions.
@fkiraly  I guess on Friday there are many sessions held .In which session will the doc structure be discussed?Also is there any calendar invite for sktime. Meetings so that I don't miss them

there is no dedicated doc structure meeting, the community collab meetings are usually the entry point.
Re calendar invites, I don´t know how to get them, but someone else might know.
@fkiraly From where can I know how the sktime doc sources are structured?
You should look into the `docs/source` folder, in there it is following basic `rst` patterns, see here: https://docutils.sourceforge.io/rst.html

Resolving patch:
diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -55,6 +55,11 @@
 # Recommended by sphinx_design when using the MyST Parser
 myst_enable_extensions = ["colon_fence"]
 
+# Notebook thumbnails
+nbsphinx_thumbnails = {
+    "examples/02_classification": "examples/img/tsc.png",
+}
+
 # Use bootstrap CSS from theme.
 panels_add_bootstrap_css = False
 


Test patch: