Repository: sktime/sktime

Issue:
[DOC] ColumnEnsembleForecaster example not correctly formatted
#### Describe the issue linked to the documentation

The examples in the documentation of the `ColumnEnsembleForecaster` are not well formatted.
[Documentation](https://www.sktime.net/en/v0.17.0/api_reference/auto_generated/sktime.forecasting.compose.ColumnEnsembleForecaster.html)





Discussion:

Resolving patch:
diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -51,6 +51,7 @@
     "sphinx_design",
     "sphinx_issues",
     "versionwarning.extension",
+    "sphinx.ext.doctest",
 ]
 
 # Recommended by sphinx_design when using the MyST Parser
diff --git a/sktime/forecasting/compose/_column_ensemble.py b/sktime/forecasting/compose/_column_ensemble.py
--- a/sktime/forecasting/compose/_column_ensemble.py
+++ b/sktime/forecasting/compose/_column_ensemble.py
@@ -40,43 +40,51 @@ class ColumnEnsembleForecaster(_HeterogenousEnsembleForecaster, _ColumnEstimator
 
     Examples
     --------
-    >>> import pandas as pd
-    >>> from sktime.forecasting.compose import ColumnEnsembleForecaster
-    >>> from sktime.forecasting.naive import NaiveForecaster
-    >>> from sktime.forecasting.trend import PolynomialTrendForecaster
-    >>> from sktime.datasets import load_longley
+    .. Doctest::
+
+        >>> import pandas as pd
+        >>> from sktime.forecasting.compose import ColumnEnsembleForecaster
+        >>> from sktime.forecasting.naive import NaiveForecaster
+        >>> from sktime.forecasting.trend import PolynomialTrendForecaster
+        >>> from sktime.datasets import load_longley
 
     Using integers (column iloc references) for indexing:
 
-    >>> y = load_longley()[1][["GNP", "UNEMP"]]
-    >>> forecasters = [
-    ...     ("trend", PolynomialTrendForecaster(), 0),
-    ...     ("naive", NaiveForecaster(), 1),
-    ... ]
-    >>> forecaster = ColumnEnsembleForecaster(forecasters=forecasters)
-    >>> forecaster.fit(y, fh=[1, 2, 3])
-    ColumnEnsembleForecaster(...)
-    >>> y_pred = forecaster.predict()
+    .. Doctest::
+
+        >>> y = load_longley()[1][["GNP", "UNEMP"]]
+        >>> forecasters = [
+        ...     ("trend", PolynomialTrendForecaster(), 0),
+        ...     ("naive", NaiveForecaster(), 1),
+        ... ]
+        >>> forecaster = ColumnEnsembleForecaster(forecasters=forecasters)
+        >>> forecaster.fit(y, fh=[1, 2, 3])
+        ColumnEnsembleForecaster(...)
+        >>> y_pred = forecaster.predict()
 
     Using strings for indexing:
 
-    >>> df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
-    >>> fc = ColumnEnsembleForecaster(
-    ...     [("foo", NaiveForecaster(), "a"), ("bar", NaiveForecaster(), "b")]
-    ... )
-    >>> fc.fit(df, fh=[1, 42])
-    ColumnEnsembleForecaster(...)
-    >>> y_pred = fc.predict()
+    .. Doctest::
+
+        >>> df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
+        >>> fc = ColumnEnsembleForecaster(
+        ...     [("foo", NaiveForecaster(), "a"), ("bar", NaiveForecaster(), "b")]
+        ... )
+        >>> fc.fit(df, fh=[1, 42])
+        ColumnEnsembleForecaster(...)
+        >>> y_pred = fc.predict()
 
     Applying one forecaster to multiple columns, multivariate:
 
-    >>> df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]})
-    >>> fc = ColumnEnsembleForecaster(
-    ...    [("ab", NaiveForecaster(), ["a", 1]), ("c", NaiveForecaster(), 2)]
-    ... )
-    >>> fc.fit(df, fh=[1, 42])
-    ColumnEnsembleForecaster(...)
-    >>> y_pred = fc.predict()
+    .. Doctest::
+
+        >>> df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]})
+        >>> fc = ColumnEnsembleForecaster(
+        ...    [("ab", NaiveForecaster(), ["a", 1]), ("c", NaiveForecaster(), 2)]
+        ... )
+        >>> fc.fit(df, fh=[1, 42])
+        ColumnEnsembleForecaster(...)
+        >>> y_pred = fc.predict()
     """
 
     _tags = {
diff --git a/sktime/transformations/compose/_column.py b/sktime/transformations/compose/_column.py
--- a/sktime/transformations/compose/_column.py
+++ b/sktime/transformations/compose/_column.py
@@ -81,6 +81,42 @@ class ColumnEnsembleTransformer(
         ``remainder`` parameter. If there are remaining columns, then
         ``len(transformers_)==len(transformations)+1``, otherwise
         ``len(transformers_)==len(transformations)``.
+
+    Examples
+    --------
+    .. Doctest::
+
+        >>> import pandas as pd
+        >>> from sktime.transformations.compose import ColumnEnsembleTransformer
+        >>> from sktime.transformations.series.detrend import Detrender
+        >>> from sktime.transformations.series.difference import Differencer
+        >>> from sktime.datasets import load_longley
+
+    Using integers (column iloc references) for indexing:
+
+    .. Doctest::
+
+        >>> y = load_longley()[1][["GNP", "UNEMP"]]
+        >>> transformer = ColumnEnsembleTransformer([("difference", Differencer(), 1),
+        ...                                 ("trend", Detrender(), 0),
+        ...                                 ])
+        >>> y_transformed = transformer.fit_transform(y)
+
+    Using strings for indexing:
+
+    >>> df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
+    >>> transformer = ColumnEnsembleTransformer(
+    ...     [("foo", Differencer(), "a"), ("bar", Detrender(), "b")]
+    ... )
+    >>> transformed_df = transformer.fit_transform(df)
+
+    Applying one transformer to multiple columns, multivariate:
+
+    >>> df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]})
+    >>> transformer = ColumnEnsembleTransformer(
+    ...    [("ab", Differencer(), ["a", 1]), ("c", Detrender(), 2)]
+    ... )
+    >>> transformed_df = transformer.fit_transform(df)
     """
 
     _tags = {


Test patch: