Repository: KIT-IAI/pyWATTS

Issue:
Ensure backward compatibility after summary feature
**What is your feature request related to?**
* Problem related

**Please describe the module/problem**
Due to the new summary feature pyWATTS is not backward compatible because `pipeline.train(..)` and `pipeline.test(..)` now return a tuple of `(data, summary)`.

**Describe the solution you'd like**
Enable the user to switch between returning and not returning a tuple of `(data, summary)`. E.g. by a parameter in the train and test method.

**Describe alternatives you've considered**
For example offer a pipeline.get_summary() would also be an option.

**Additional context**
None

**What type of Feature Request**
* Core enhancement


Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 22454a5..e68c5eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@
   * Time needed by the fit method is recorded by the summary. (Part of the summary.md)
   * Section about how to get results of a pyWATTS pipeline.
 * Add MAECalculator as another error measure. ([#99](https://github.com/KIT-IAI/pyWATTS/issues/99))
+* Add summary parameter to train and test to ensure backward compatibility. ([#127](https://github.com/KIT-IAI/pyWATTS/issues/127))
 
 ### Changed
 * Remove parameter step.stop. Instead we call the method _should_stop on the previous steps. ([#25](https://github.com/KIT-IAI/pyWATTS/issues/25))
diff --git a/pywatts/core/pipeline.py b/pywatts/core/pipeline.py
index d39a876..72b77ac 100644
--- a/pywatts/core/pipeline.py
+++ b/pywatts/core/pipeline.py
@@ -148,7 +148,7 @@ class Pipeline(BaseTransformer):
 
         # TODO built the graph which should be drawn by starting with the last steps...
 
-    def test(self, data: Union[pd.DataFrame, xr.Dataset]):
+    def test(self, data: Union[pd.DataFrame, xr.Dataset], summary: bool = False):
         """
         Executes all modules in the pipeline in the correct order. This method call only transform on every module
         if the ComputationMode is Default. I.e. if no computationMode is specified during the addition of the module to
@@ -159,9 +159,9 @@ class Pipeline(BaseTransformer):
         :return: The result of all end points of the pipeline
         :rtype: Dict[xr.DataArray]
         """
-        return self._run(data, ComputationMode.Transform)
+        return self._run(data, ComputationMode.Transform, summary)
 
-    def train(self, data: Union[pd.DataFrame, xr.Dataset]):
+    def train(self, data: Union[pd.DataFrame, xr.Dataset], summary: bool = False):
         """
         Executes all modules in the pipeline in the correct order. This method calls fit and transform on each module
         if the ComputationMode is Default. I.e. if no computationMode is specified during the addition of the module to
@@ -173,9 +173,9 @@ class Pipeline(BaseTransformer):
         :rtype: Dict[xr.DataArray]
         """
 
-        return self._run(data, ComputationMode.FitTransform)
+        return self._run(data, ComputationMode.FitTransform, summary)
 
-    def _run(self, data: Union[pd.DataFrame, xr.Dataset], mode: ComputationMode):
+    def _run(self, data: Union[pd.DataFrame, xr.Dataset], mode: ComputationMode, summary: bool):
 
         for step in self.id_to_step.values():
             step.reset()
@@ -185,7 +185,10 @@ class Pipeline(BaseTransformer):
             data = data.to_xarray()
 
         if isinstance(data, xr.Dataset):
-            return self.transform(**{key: data[key] for key in data.data_vars}), self.create_summary()
+            if summary:
+                return self.transform(**{key: data[key] for key in data.data_vars}), self.create_summary()
+            else:
+                return self.transform(**{key: data[key] for key in data.data_vars})
 
         elif isinstance(data, dict):
             for key in data:
@@ -195,7 +198,10 @@ class Pipeline(BaseTransformer):
                         "Make sure to pass Dict[str, xr.DataArray].",
                         self.name
                     )
-            return self.transform(**data), self.create_summary()
+            if summary:
+                return self.transform(**data), self.create_summary()
+            else:
+                return self.transform(**data)
 
 
         raise WrongParameterException(


Test patch:
diff --git a/tests/unit/core/test_pipeline.py b/tests/unit/core/test_pipeline.py
index 07842c7..5f9fbf4 100644
--- a/tests/unit/core/test_pipeline.py
+++ b/tests/unit/core/test_pipeline.py
@@ -346,8 +346,9 @@ class TestPipeline(unittest.TestCase):
         self.pipeline.set_params(pd.Timedelta("24h"))
         self.pipeline.add(module=first_step)
 
-        self.pipeline.test(pd.DataFrame({"test": [1, 2, 2, 3], "test2": [2, 2, 2, 2]},
-                                        index=pd.DatetimeIndex(pd.date_range('2000-01-01', freq='24H', periods=4))))
+        data = pd.DataFrame({"test": [1, 2, 2, 3], "test2": [2, 2, 2, 2]},
+                            index=pd.DatetimeIndex(pd.date_range('2000-01-01', freq='24H', periods=4)))
+        self.pipeline.test(data)
 
         first_step.set_computation_mode.assert_called_once_with(ComputationMode.Transform)
         calls = [
@@ -516,8 +517,9 @@ class TestPipeline(unittest.TestCase):
         self.pipeline.add(module=first_step)
         self.pipeline.add(module=second_step)
 
-        result, summary = self.pipeline.train(pd.DataFrame({"test": [1, 2, 2, 3, 4], "test2": [2, 2, 2, 2, 2]},
-                                         index=pd.DatetimeIndex(pd.date_range('2000-01-01', freq='24H', periods=5))))
+        data = pd.DataFrame({"test": [1, 2, 2, 3, 4], "test2": [2, 2, 2, 2, 2]},
+                            index=pd.DatetimeIndex(pd.date_range('2000-01-01', freq='24H', periods=5)))
+        result, summary = self.pipeline.train(data, summary=True)
 
         first_step.set_computation_mode.assert_called_once_with(ComputationMode.FitTransform)
         second_step.set_computation_mode.assert_called_once_with(ComputationMode.FitTransform)
@@ -549,7 +551,7 @@ class TestPipeline(unittest.TestCase):
 
         ds = xr.Dataset({'foo': foo, "target": target, "target2": target2})
 
-        result, summary = self.pipeline.train(ds)
+        result, summary = self.pipeline.train(ds, summary=True)
 
         self.assertTrue("Training Time" in summary)
         self.assertTrue("RMSE" in summary)