We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[BUG]  `test_fit_does_not_overwrite_hyper_params[FeatureUnion]` failing
Update: the failure has been silenced in the tests to enable refactor work on CI/CD, but the bug is still there.
To reproduce, the test should be run manually, or with the silencing disabled (`tests._config.EXCLUDED_TESTS`)

---

**Describe the bug**

In the refactored CI pipeline based on github actions #1620, and is blocking the PR.

The test `test_fit_does_not_overwrite_hyper_params[FeatureUnion]` from `tests/test_all_estimators.py` fails on linux with python3.6-3.9 and macos 3.6-3.9 with the error below.

Curiously the test are passing in CI pipelines currently on `main` branch.

```
____________ test_fit_does_not_overwrite_hyper_params[FeatureUnion] ____________
[gw0] darwin -- Python 3.7.12 /Users/runner/hostedtoolcache/Python/3.7.12/x64/bin/python

estimator_instance = FeatureUnion(n_jobs=None, preserve_dataframe=True,
             transformer_list=[('transformer1',
                   ...                                                              with_std=True)))],
             transformer_weights=None)

    def test_fit_does_not_overwrite_hyper_params(estimator_instance):
        """Check that we do not overwrite hyper-parameters in fit."""
        estimator = estimator_instance
        set_random_state(estimator)
    
        # Make a physical copy of the original estimator parameters before fitting.
        params = estimator.get_params()
        original_params = deepcopy(params)
    
        # Fit the model
        fit_args = _make_args(estimator, "fit")
        estimator.fit(*fit_args)
    
        # Compare the state of the model parameters with the original parameters
        new_params = estimator.get_params()
        for param_name, original_value in original_params.items():
            new_value = new_params[param_name]
    
            # We should never change or mutate the internal state of input
            # parameters by default. To check this we use the joblib.hash function
            # that introspects recursively any subobjects to compute a checksum.
            # The only exception to this rule of immutable constructor parameters
            # is possible RandomState instance but in this check we explicitly
            # fixed the random_state params recursively to be integer seeds.
>           assert joblib.hash(new_value) == joblib.hash(original_value), (
                "Estimator %s should not change or mutate "
                " the parameter %s from %s to %s during fit."
                % (estimator.__class__.__name__, param_name, original_value, new_value)
            )
E           AssertionError: Estimator FeatureUnion should not change or mutate  the parameter transformer_list from [('transformer1', SeriesToSeriesRowTransformer(check_transformer=False,
E                                          transformer=StandardScaler(copy=True,
E                                                                     with_mean=True,
E                                                                     with_std=True))), ('transformer2', SeriesToSeriesRowTransformer(check_transformer=False,
E                                          transformer=StandardScaler(copy=True,
E                                                                     with_mean=True,
E                                                                     with_std=True)))] to [('transformer1', SeriesToSeriesRowTransformer(check_transformer=False,
E                                          transformer=StandardScaler(copy=True,
E                                                                     with_mean=True,
E                                                                     with_std=True))), ('transformer2', SeriesToSeriesRowTransformer(check_transformer=False,
E                                          transformer=StandardScaler(copy=True,
E                                                                     with_mean=True,
E                                                                     with_std=True)))] during fit.
E           assert '7f94d1fc7e1f...888be251ce7b2' == 'b03f493febd2...c60681b4af6e4'
E             - b03f493febd2f1d6da1c60681b4af6e4
E             + 7f94d1fc7e1f285e1e5888be251ce7b2

estimator  = FeatureUnion(n_jobs=None, preserve_dataframe=True,
             transformer_list=[('transformer1',
                   ...                                                              with_std=True)))],
             transformer_weights=None)
estimator_instance = FeatureUnion(n_jobs=None, preserve_dataframe=True,
             transformer_list=[('transformer1',
                   ...                                                              with_std=True)))],
             transformer_weights=None)
fit_args   = (                                                var_0
0   0    -0.116020
1     0.343339
2    -0.464066
3...
1   0    ...0
7     1
8     0
9     0
10    0
11    0
12    1
13    1
14    1
15    1
16    0
17    0
18    1
19    1
dtype: int64)
new_params = {'n_jobs': None, 'preserve_dataframe': True, 'transformer1': SeriesToSeriesRowTransformer(check_transformer=False,
   ...                                                        with_std=True)), 'transformer1__check_transformer': False, ...}
new_value  = [('transformer1', SeriesToSeriesRowTransformer(check_transformer=False,
                             transformer=Stand...                              with_mean=True,
                                                        with_std=True)))]
original_params = {'n_jobs': None, 'preserve_dataframe': True, 'transformer1': SeriesToSeriesRowTransformer(check_transformer=False,
   ...                                                        with_std=True)), 'transformer1__check_transformer': False, ...}
original_value = [('transformer1', SeriesToSeriesRowTransformer(check_transformer=False,
                             transformer=Stand...                              with_mean=True,
                                                        with_std=True)))]
param_name = 'transformer_list'
params     = {'n_jobs': None, 'preserve_dataframe': True, 'transformer1': SeriesToSeriesRowTransformer(check_transformer=False,
   ...                                                        with_std=True)), 'transformer1__check_transformer': False, ...}
```

**To Reproduce**

Run the test with:

```bash
pytest sktime/tests/test_all_estimators.py
```

**Expected behavior**

Test passes

**Additional context**

**Versions**

See github actions under #1620 

<!--
Please run the following code snippet and paste the output here:
 
from sktime import show_versions; show_versions()
-->

</details>

<!-- Thanks for contributing! -->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `sktime/series_as_features/compose/_pipeline.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 import numpy as np
3 import pandas as pd
4 from joblib import Parallel, delayed
5 from scipy import sparse
6 from sklearn.pipeline import FeatureUnion as _FeatureUnion
7 from sklearn.pipeline import _fit_transform_one, _transform_one
8 
9 from sktime.transformations.base import _PanelToPanelTransformer
10 
11 __all__ = ["FeatureUnion"]
12 __author__ = ["Markus Löning"]
13 
14 
15 class FeatureUnion(_FeatureUnion, _PanelToPanelTransformer):
16     """Concatenates results of multiple transformer objects.
17 
18     This estimator applies a list of transformer objects in parallel to the
19     input data, then concatenates the results. This is useful to combine
20     several feature extraction mechanisms into a single transformer.
21     Parameters of the transformations may be set using its name and the
22     parameter name separated by a '__'. A transformer may be replaced entirely by
23     setting the parameter with its name to another transformer,
24     or removed by setting to 'drop' or ``None``.
25 
26     Parameters
27     ----------
28     transformer_list : list of (string, transformer) tuples
29         List of transformer objects to be applied to the data. The first
30         half of each tuple is the name of the transformer.
31     n_jobs : int or None, optional (default=None)
32         Number of jobs to run in parallel.
33         ``None`` means 1 unless in a :obj:`joblib.parallel_backend`
34         context.
35         ``-1`` means using all processors.
36     transformer_weights : dict, optional
37         Multiplicative weights for features per transformer.
38         Keys are transformer names, values the weights.
39     preserve_dataframe : bool
40         Save constructed dataframe.
41     """
42 
43     _required_parameters = ["transformer_list"]
44 
45     def __init__(
46         self,
47         transformer_list,
48         n_jobs=None,
49         transformer_weights=None,
50         preserve_dataframe=True,
51     ):
52         self.preserve_dataframe = preserve_dataframe
53         super(FeatureUnion, self).__init__(
54             transformer_list, n_jobs=n_jobs, transformer_weights=transformer_weights
55         )
56 
57         # We need to add is-fitted state when inheriting from scikit-learn
58         self._is_fitted = False
59 
60     def fit_transform(self, X, y=None, **fit_params):
61         """Fit all transformations, transform the data and concatenate results.
62 
63         Parameters
64         ----------
65         X : pandas DataFrame
66             Input data to be transformed.
67         y : pandas Series, shape (n_samples, ...), optional
68             Targets for supervised learning.
69 
70         Returns
71         -------
72         Xt : pandas DataFrame
73             hstack of results of transformations. sum_n_components is the
74             sum of n_components (output dimension) over transformations.
75         """
76         self._validate_transformers()
77         result = Parallel(n_jobs=self.n_jobs)(
78             delayed(_fit_transform_one)(trans, X, y, weight, **fit_params)
79             for name, trans, weight in self._iter()
80         )
81 
82         if not result:
83             # All transformations are None
84             return np.zeros((X.shape[0], 0))
85 
86         Xs, transformers = zip(*result)
87         self._update_transformer_list(transformers)
88 
89         Xs = self._hstack(list(Xs))
90         self._is_fitted = True
91         return Xs
92 
93     def fit(self, X, y=None, **fit_params):
94         """Fit parameters."""
95         super(FeatureUnion, self).fit(X, y, **fit_params)
96         self._is_fitted = True
97         return self
98 
99     def transform(self, X):
100         """Transform X separately by each transformer, concatenate results.
101 
102         Parameters
103         ----------
104         X : pandas DataFrame
105             Input data to be transformed.
106 
107         Returns
108         -------
109         Xt : pandas DataFrame
110             hstack of results of transformations. sum_n_components is the
111             sum of n_components (output dimension) over transformations.
112         """
113         self.check_is_fitted()
114         Xs = Parallel(n_jobs=self.n_jobs)(
115             delayed(_transform_one)(trans, X, None, weight)
116             for name, trans, weight in self._iter()
117         )
118 
119         if not Xs:
120             # All transformations are None
121             return np.zeros((X.shape[0], 0))
122 
123         else:
124             return self._hstack(list(Xs))
125 
126     def _hstack(self, Xs):
127         """
128         Stacks X horizontally.
129 
130         Supports input types (X): list of
131             numpy arrays, sparse arrays and DataFrames.
132         """
133         if any(sparse.issparse(f) for f in Xs):
134             Xs = sparse.hstack(Xs).tocsr()
135 
136         types = set(type(X) for X in Xs)
137         if self.preserve_dataframe and (pd.Series in types or pd.DataFrame in types):
138             return pd.concat(Xs, axis=1)
139 
140         else:
141             return np.hstack(Xs)
142
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/sktime/series_as_features/compose/_pipeline.py b/sktime/series_as_features/compose/_pipeline.py
--- a/sktime/series_as_features/compose/_pipeline.py
+++ b/sktime/series_as_features/compose/_pipeline.py
@@ -1,10 +1,9 @@
 # -*- coding: utf-8 -*-
+
 import numpy as np
 import pandas as pd
-from joblib import Parallel, delayed
 from scipy import sparse
 from sklearn.pipeline import FeatureUnion as _FeatureUnion
-from sklearn.pipeline import _fit_transform_one, _transform_one
 
 from sktime.transformations.base import _PanelToPanelTransformer
 
@@ -57,71 +56,20 @@
         # We need to add is-fitted state when inheriting from scikit-learn
         self._is_fitted = False
 
-    def fit_transform(self, X, y=None, **fit_params):
-        """Fit all transformations, transform the data and concatenate results.
-
-        Parameters
-        ----------
-        X : pandas DataFrame
-            Input data to be transformed.
-        y : pandas Series, shape (n_samples, ...), optional
-            Targets for supervised learning.
-
-        Returns
-        -------
-        Xt : pandas DataFrame
-            hstack of results of transformations. sum_n_components is the
-            sum of n_components (output dimension) over transformations.
-        """
-        self._validate_transformers()
-        result = Parallel(n_jobs=self.n_jobs)(
-            delayed(_fit_transform_one)(trans, X, y, weight, **fit_params)
-            for name, trans, weight in self._iter()
-        )
-
-        if not result:
-            # All transformations are None
-            return np.zeros((X.shape[0], 0))
-
-        Xs, transformers = zip(*result)
-        self._update_transformer_list(transformers)
-
-        Xs = self._hstack(list(Xs))
-        self._is_fitted = True
-        return Xs
-
     def fit(self, X, y=None, **fit_params):
         """Fit parameters."""
-        super(FeatureUnion, self).fit(X, y, **fit_params)
+        super().fit(X, y, **fit_params)
         self._is_fitted = True
         return self
 
     def transform(self, X):
-        """Transform X separately by each transformer, concatenate results.
-
-        Parameters
-        ----------
-        X : pandas DataFrame
-            Input data to be transformed.
-
-        Returns
-        -------
-        Xt : pandas DataFrame
-            hstack of results of transformations. sum_n_components is the
-            sum of n_components (output dimension) over transformations.
-        """
+        """Transform X separately by each transformer, concatenate results."""
         self.check_is_fitted()
-        Xs = Parallel(n_jobs=self.n_jobs)(
-            delayed(_transform_one)(trans, X, None, weight)
-            for name, trans, weight in self._iter()
-        )
-
-        if not Xs:
-            # All transformations are None
-            return np.zeros((X.shape[0], 0))
+        return super().transform(X)
 
-        else:
-            return self._hstack(list(Xs))
+    def fit_transform(self, X, y, **fit_params):
+        """Transform X separately by each transformer, concatenate results."""
+        return self.fit(X, y, **fit_params).transform(X)
 
     def _hstack(self, Xs):
         """
@@ -133,7 +81,7 @@
         if any(sparse.issparse(f) for f in Xs):
             Xs = sparse.hstack(Xs).tocsr()
 
-        types = set(type(X) for X in Xs)
+        types = {type(X) for X in Xs}
         if self.preserve_dataframe and (pd.Series in types or pd.DataFrame in types):
             return pd.concat(Xs, axis=1)

{"golden_diff": "diff --git a/sktime/series_as_features/compose/_pipeline.py b/sktime/series_as_features/compose/_pipeline.py\n--- a/sktime/series_as_features/compose/_pipeline.py\n+++ b/sktime/series_as_features/compose/_pipeline.py\n@@ -1,10 +1,9 @@\n # -*- coding: utf-8 -*-\n+\n import numpy as np\n import pandas as pd\n-from joblib import Parallel, delayed\n from scipy import sparse\n from sklearn.pipeline import FeatureUnion as _FeatureUnion\n-from sklearn.pipeline import _fit_transform_one, _transform_one\n \n from sktime.transformations.base import _PanelToPanelTransformer\n \n@@ -57,71 +56,20 @@\n         # We need to add is-fitted state when inheriting from scikit-learn\n         self._is_fitted = False\n \n-    def fit_transform(self, X, y=None, **fit_params):\n-        \"\"\"Fit all transformations, transform the data and concatenate results.\n-\n-        Parameters\n-        ----------\n-        X : pandas DataFrame\n-            Input data to be transformed.\n-        y : pandas Series, shape (n_samples, ...), optional\n-            Targets for supervised learning.\n-\n-        Returns\n-        -------\n-        Xt : pandas DataFrame\n-            hstack of results of transformations. sum_n_components is the\n-            sum of n_components (output dimension) over transformations.\n-        \"\"\"\n-        self._validate_transformers()\n-        result = Parallel(n_jobs=self.n_jobs)(\n-            delayed(_fit_transform_one)(trans, X, y, weight, **fit_params)\n-            for name, trans, weight in self._iter()\n-        )\n-\n-        if not result:\n-            # All transformations are None\n-            return np.zeros((X.shape[0], 0))\n-\n-        Xs, transformers = zip(*result)\n-        self._update_transformer_list(transformers)\n-\n-        Xs = self._hstack(list(Xs))\n-        self._is_fitted = True\n-        return Xs\n-\n     def fit(self, X, y=None, **fit_params):\n         \"\"\"Fit parameters.\"\"\"\n-        super(FeatureUnion, self).fit(X, y, **fit_params)\n+        super().fit(X, y, **fit_params)\n         self._is_fitted = True\n         return self\n \n     def transform(self, X):\n-        \"\"\"Transform X separately by each transformer, concatenate results.\n-\n-        Parameters\n-        ----------\n-        X : pandas DataFrame\n-            Input data to be transformed.\n-\n-        Returns\n-        -------\n-        Xt : pandas DataFrame\n-            hstack of results of transformations. sum_n_components is the\n-            sum of n_components (output dimension) over transformations.\n-        \"\"\"\n+        \"\"\"Transform X separately by each transformer, concatenate results.\"\"\"\n         self.check_is_fitted()\n-        Xs = Parallel(n_jobs=self.n_jobs)(\n-            delayed(_transform_one)(trans, X, None, weight)\n-            for name, trans, weight in self._iter()\n-        )\n-\n-        if not Xs:\n-            # All transformations are None\n-            return np.zeros((X.shape[0], 0))\n+        return super().transform(X)\n \n-        else:\n-            return self._hstack(list(Xs))\n+    def fit_transform(self, X, y, **fit_params):\n+        \"\"\"Transform X separately by each transformer, concatenate results.\"\"\"\n+        return self.fit(X, y, **fit_params).transform(X)\n \n     def _hstack(self, Xs):\n         \"\"\"\n@@ -133,7 +81,7 @@\n         if any(sparse.issparse(f) for f in Xs):\n             Xs = sparse.hstack(Xs).tocsr()\n \n-        types = set(type(X) for X in Xs)\n+        types = {type(X) for X in Xs}\n         if self.preserve_dataframe and (pd.Series in types or pd.DataFrame in types):\n             return pd.concat(Xs, axis=1)\n", "issue": "[BUG]  `test_fit_does_not_overwrite_hyper_params[FeatureUnion]` failing\nUpdate: the failure has been silenced in the tests to enable refactor work on CI/CD, but the bug is still there.\r\nTo reproduce, the test should be run manually, or with the silencing disabled (`tests._config.EXCLUDED_TESTS`)\r\n\r\n---\r\n\r\n**Describe the bug**\r\n\r\nIn the refactored CI pipeline based on github actions #1620, and is blocking the PR.\r\n\r\nThe test `test_fit_does_not_overwrite_hyper_params[FeatureUnion]` from `tests/test_all_estimators.py` fails on linux with python3.6-3.9 and macos 3.6-3.9 with the error below.\r\n\r\nCuriously the test are passing in CI pipelines currently on `main` branch.\r\n\r\n```\r\n____________ test_fit_does_not_overwrite_hyper_params[FeatureUnion] ____________\r\n[gw0] darwin -- Python 3.7.12 /Users/runner/hostedtoolcache/Python/3.7.12/x64/bin/python\r\n\r\nestimator_instance = FeatureUnion(n_jobs=None, preserve_dataframe=True,\r\n             transformer_list=[('transformer1',\r\n                   ...                                                              with_std=True)))],\r\n             transformer_weights=None)\r\n\r\n    def test_fit_does_not_overwrite_hyper_params(estimator_instance):\r\n        \"\"\"Check that we do not overwrite hyper-parameters in fit.\"\"\"\r\n        estimator = estimator_instance\r\n        set_random_state(estimator)\r\n    \r\n        # Make a physical copy of the original estimator parameters before fitting.\r\n        params = estimator.get_params()\r\n        original_params = deepcopy(params)\r\n    \r\n        # Fit the model\r\n        fit_args = _make_args(estimator, \"fit\")\r\n        estimator.fit(*fit_args)\r\n    \r\n        # Compare the state of the model parameters with the original parameters\r\n        new_params = estimator.get_params()\r\n        for param_name, original_value in original_params.items():\r\n            new_value = new_params[param_name]\r\n    \r\n            # We should never change or mutate the internal state of input\r\n            # parameters by default. To check this we use the joblib.hash function\r\n            # that introspects recursively any subobjects to compute a checksum.\r\n            # The only exception to this rule of immutable constructor parameters\r\n            # is possible RandomState instance but in this check we explicitly\r\n            # fixed the random_state params recursively to be integer seeds.\r\n>           assert joblib.hash(new_value) == joblib.hash(original_value), (\r\n                \"Estimator %s should not change or mutate \"\r\n                \" the parameter %s from %s to %s during fit.\"\r\n                % (estimator.__class__.__name__, param_name, original_value, new_value)\r\n            )\r\nE           AssertionError: Estimator FeatureUnion should not change or mutate  the parameter transformer_list from [('transformer1', SeriesToSeriesRowTransformer(check_transformer=False,\r\nE                                          transformer=StandardScaler(copy=True,\r\nE                                                                     with_mean=True,\r\nE                                                                     with_std=True))), ('transformer2', SeriesToSeriesRowTransformer(check_transformer=False,\r\nE                                          transformer=StandardScaler(copy=True,\r\nE                                                                     with_mean=True,\r\nE                                                                     with_std=True)))] to [('transformer1', SeriesToSeriesRowTransformer(check_transformer=False,\r\nE                                          transformer=StandardScaler(copy=True,\r\nE                                                                     with_mean=True,\r\nE                                                                     with_std=True))), ('transformer2', SeriesToSeriesRowTransformer(check_transformer=False,\r\nE                                          transformer=StandardScaler(copy=True,\r\nE                                                                     with_mean=True,\r\nE                                                                     with_std=True)))] during fit.\r\nE           assert '7f94d1fc7e1f...888be251ce7b2' == 'b03f493febd2...c60681b4af6e4'\r\nE             - b03f493febd2f1d6da1c60681b4af6e4\r\nE             + 7f94d1fc7e1f285e1e5888be251ce7b2\r\n\r\nestimator  = FeatureUnion(n_jobs=None, preserve_dataframe=True,\r\n             transformer_list=[('transformer1',\r\n                   ...                                                              with_std=True)))],\r\n             transformer_weights=None)\r\nestimator_instance = FeatureUnion(n_jobs=None, preserve_dataframe=True,\r\n             transformer_list=[('transformer1',\r\n                   ...                                                              with_std=True)))],\r\n             transformer_weights=None)\r\nfit_args   = (                                                var_0\r\n0   0    -0.116020\r\n1     0.343339\r\n2    -0.464066\r\n3...\r\n1   0    ...0\r\n7     1\r\n8     0\r\n9     0\r\n10    0\r\n11    0\r\n12    1\r\n13    1\r\n14    1\r\n15    1\r\n16    0\r\n17    0\r\n18    1\r\n19    1\r\ndtype: int64)\r\nnew_params = {'n_jobs': None, 'preserve_dataframe': True, 'transformer1': SeriesToSeriesRowTransformer(check_transformer=False,\r\n   ...                                                        with_std=True)), 'transformer1__check_transformer': False, ...}\r\nnew_value  = [('transformer1', SeriesToSeriesRowTransformer(check_transformer=False,\r\n                             transformer=Stand...                              with_mean=True,\r\n                                                        with_std=True)))]\r\noriginal_params = {'n_jobs': None, 'preserve_dataframe': True, 'transformer1': SeriesToSeriesRowTransformer(check_transformer=False,\r\n   ...                                                        with_std=True)), 'transformer1__check_transformer': False, ...}\r\noriginal_value = [('transformer1', SeriesToSeriesRowTransformer(check_transformer=False,\r\n                             transformer=Stand...                              with_mean=True,\r\n                                                        with_std=True)))]\r\nparam_name = 'transformer_list'\r\nparams     = {'n_jobs': None, 'preserve_dataframe': True, 'transformer1': SeriesToSeriesRowTransformer(check_transformer=False,\r\n   ...                                                        with_std=True)), 'transformer1__check_transformer': False, ...}\r\n```\r\n\r\n**To Reproduce**\r\n\r\nRun the test with:\r\n\r\n```bash\r\npytest sktime/tests/test_all_estimators.py\r\n```\r\n\r\n**Expected behavior**\r\n\r\nTest passes\r\n\r\n**Additional context**\r\n\r\n**Versions**\r\n\r\nSee github actions under #1620 \r\n\r\n<!--\r\nPlease run the following code snippet and paste the output here:\r\n \r\nfrom sktime import show_versions; show_versions()\r\n-->\r\n\r\n</details>\r\n\r\n<!-- Thanks for contributing! -->\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nimport numpy as np\nimport pandas as pd\nfrom joblib import Parallel, delayed\nfrom scipy import sparse\nfrom sklearn.pipeline import FeatureUnion as _FeatureUnion\nfrom sklearn.pipeline import _fit_transform_one, _transform_one\n\nfrom sktime.transformations.base import _PanelToPanelTransformer\n\n__all__ = [\"FeatureUnion\"]\n__author__ = [\"Markus L\u00f6ning\"]\n\n\nclass FeatureUnion(_FeatureUnion, _PanelToPanelTransformer):\n    \"\"\"Concatenates results of multiple transformer objects.\n\n    This estimator applies a list of transformer objects in parallel to the\n    input data, then concatenates the results. This is useful to combine\n    several feature extraction mechanisms into a single transformer.\n    Parameters of the transformations may be set using its name and the\n    parameter name separated by a '__'. A transformer may be replaced entirely by\n    setting the parameter with its name to another transformer,\n    or removed by setting to 'drop' or ``None``.\n\n    Parameters\n    ----------\n    transformer_list : list of (string, transformer) tuples\n        List of transformer objects to be applied to the data. The first\n        half of each tuple is the name of the transformer.\n    n_jobs : int or None, optional (default=None)\n        Number of jobs to run in parallel.\n        ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n        context.\n        ``-1`` means using all processors.\n    transformer_weights : dict, optional\n        Multiplicative weights for features per transformer.\n        Keys are transformer names, values the weights.\n    preserve_dataframe : bool\n        Save constructed dataframe.\n    \"\"\"\n\n    _required_parameters = [\"transformer_list\"]\n\n    def __init__(\n        self,\n        transformer_list,\n        n_jobs=None,\n        transformer_weights=None,\n        preserve_dataframe=True,\n    ):\n        self.preserve_dataframe = preserve_dataframe\n        super(FeatureUnion, self).__init__(\n            transformer_list, n_jobs=n_jobs, transformer_weights=transformer_weights\n        )\n\n        # We need to add is-fitted state when inheriting from scikit-learn\n        self._is_fitted = False\n\n    def fit_transform(self, X, y=None, **fit_params):\n        \"\"\"Fit all transformations, transform the data and concatenate results.\n\n        Parameters\n        ----------\n        X : pandas DataFrame\n            Input data to be transformed.\n        y : pandas Series, shape (n_samples, ...), optional\n            Targets for supervised learning.\n\n        Returns\n        -------\n        Xt : pandas DataFrame\n            hstack of results of transformations. sum_n_components is the\n            sum of n_components (output dimension) over transformations.\n        \"\"\"\n        self._validate_transformers()\n        result = Parallel(n_jobs=self.n_jobs)(\n            delayed(_fit_transform_one)(trans, X, y, weight, **fit_params)\n            for name, trans, weight in self._iter()\n        )\n\n        if not result:\n            # All transformations are None\n            return np.zeros((X.shape[0], 0))\n\n        Xs, transformers = zip(*result)\n        self._update_transformer_list(transformers)\n\n        Xs = self._hstack(list(Xs))\n        self._is_fitted = True\n        return Xs\n\n    def fit(self, X, y=None, **fit_params):\n        \"\"\"Fit parameters.\"\"\"\n        super(FeatureUnion, self).fit(X, y, **fit_params)\n        self._is_fitted = True\n        return self\n\n    def transform(self, X):\n        \"\"\"Transform X separately by each transformer, concatenate results.\n\n        Parameters\n        ----------\n        X : pandas DataFrame\n            Input data to be transformed.\n\n        Returns\n        -------\n        Xt : pandas DataFrame\n            hstack of results of transformations. sum_n_components is the\n            sum of n_components (output dimension) over transformations.\n        \"\"\"\n        self.check_is_fitted()\n        Xs = Parallel(n_jobs=self.n_jobs)(\n            delayed(_transform_one)(trans, X, None, weight)\n            for name, trans, weight in self._iter()\n        )\n\n        if not Xs:\n            # All transformations are None\n            return np.zeros((X.shape[0], 0))\n\n        else:\n            return self._hstack(list(Xs))\n\n    def _hstack(self, Xs):\n        \"\"\"\n        Stacks X horizontally.\n\n        Supports input types (X): list of\n            numpy arrays, sparse arrays and DataFrames.\n        \"\"\"\n        if any(sparse.issparse(f) for f in Xs):\n            Xs = sparse.hstack(Xs).tocsr()\n\n        types = set(type(X) for X in Xs)\n        if self.preserve_dataframe and (pd.Series in types or pd.DataFrame in types):\n            return pd.concat(Xs, axis=1)\n\n        else:\n            return np.hstack(Xs)\n", "path": "sktime/series_as_features/compose/_pipeline.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport numpy as np\nimport pandas as pd\nfrom scipy import sparse\nfrom sklearn.pipeline import FeatureUnion as _FeatureUnion\n\nfrom sktime.transformations.base import _PanelToPanelTransformer\n\n__all__ = [\"FeatureUnion\"]\n__author__ = [\"Markus L\u00f6ning\"]\n\n\nclass FeatureUnion(_FeatureUnion, _PanelToPanelTransformer):\n    \"\"\"Concatenates results of multiple transformer objects.\n\n    This estimator applies a list of transformer objects in parallel to the\n    input data, then concatenates the results. This is useful to combine\n    several feature extraction mechanisms into a single transformer.\n    Parameters of the transformations may be set using its name and the\n    parameter name separated by a '__'. A transformer may be replaced entirely by\n    setting the parameter with its name to another transformer,\n    or removed by setting to 'drop' or ``None``.\n\n    Parameters\n    ----------\n    transformer_list : list of (string, transformer) tuples\n        List of transformer objects to be applied to the data. The first\n        half of each tuple is the name of the transformer.\n    n_jobs : int or None, optional (default=None)\n        Number of jobs to run in parallel.\n        ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n        context.\n        ``-1`` means using all processors.\n    transformer_weights : dict, optional\n        Multiplicative weights for features per transformer.\n        Keys are transformer names, values the weights.\n    preserve_dataframe : bool\n        Save constructed dataframe.\n    \"\"\"\n\n    _required_parameters = [\"transformer_list\"]\n\n    def __init__(\n        self,\n        transformer_list,\n        n_jobs=None,\n        transformer_weights=None,\n        preserve_dataframe=True,\n    ):\n        self.preserve_dataframe = preserve_dataframe\n        super(FeatureUnion, self).__init__(\n            transformer_list, n_jobs=n_jobs, transformer_weights=transformer_weights\n        )\n\n        # We need to add is-fitted state when inheriting from scikit-learn\n        self._is_fitted = False\n\n    def fit(self, X, y=None, **fit_params):\n        \"\"\"Fit parameters.\"\"\"\n        super().fit(X, y, **fit_params)\n        self._is_fitted = True\n        return self\n\n    def transform(self, X):\n        \"\"\"Transform X separately by each transformer, concatenate results.\"\"\"\n        self.check_is_fitted()\n        return super().transform(X)\n\n    def fit_transform(self, X, y, **fit_params):\n        \"\"\"Transform X separately by each transformer, concatenate results.\"\"\"\n        return self.fit(X, y, **fit_params).transform(X)\n\n    def _hstack(self, Xs):\n        \"\"\"\n        Stacks X horizontally.\n\n        Supports input types (X): list of\n            numpy arrays, sparse arrays and DataFrames.\n        \"\"\"\n        if any(sparse.issparse(f) for f in Xs):\n            Xs = sparse.hstack(Xs).tocsr()\n\n        types = {type(X) for X in Xs}\n        if self.preserve_dataframe and (pd.Series in types or pd.DataFrame in types):\n            return pd.concat(Xs, axis=1)\n\n        else:\n            return np.hstack(Xs)\n", "path": "sktime/series_as_features/compose/_pipeline.py"}]}