Repository: KIT-IAI/pyWATTS

Issue:
data_var_name parameter of sample module is not needed any more
**Describe the bug**
The data_var_name parameter of the sample module was needed for the old API. The new api do not need it any more. 

**Expected behavior**
Remove the paramter data_var_names


Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 149d4bd..3df65fe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,7 +19,7 @@
   * Fixed pipeline crashing in RMSE module because of wrong time index ([#39](https://github.com/KIT-IAI/pyWATTS/issues/39))
   * Fixed bracket operator not working for steps within the pipeline ([#42](https://github.com/KIT-IAI/pyWATTS/issues/42))
   * Fixed dict objects could not be passed to pipeline ([#43](https://github.com/KIT-IAI/pyWATTS/issues/43))
-
+  * Fixed old parameter in sample_module  ([#67](https://github.com/KIT-IAI/pyWATTS/issues/67))
 
 ## [0.0.1] - 2021-MM-DD
 
diff --git a/pywatts/modules/sample_module.py b/pywatts/modules/sample_module.py
index 81f91c6..36bb0d2 100644
--- a/pywatts/modules/sample_module.py
+++ b/pywatts/modules/sample_module.py
@@ -17,20 +17,15 @@ class Sampler(BaseTransformer):
     :type sample_size: int
     :param indices: The indices which should be shifted through time
     :type indices: List[str]
-    :param data_var_names: Name for the shifted time series
-    :type data_var_names: List[str]
 
      """
 
-    def __init__(self, sample_size: int, name: str = "SampleModule", indeces: List[str] = None, data_var_names=None):
+    def __init__(self, sample_size: int, name: str = "SampleModule", indeces: List[str] = None):
         super().__init__(name)
         if indeces is None:
             indeces = []
-        if data_var_names is None:
-            data_var_names = []
         self.sample_size = sample_size
         self.indexes = indeces
-        self.data_var_names = data_var_names
 
     def get_params(self) -> Dict[str, object]:
         """
@@ -42,10 +37,9 @@ class Sampler(BaseTransformer):
         return {
             "lag": self.sample_size,
             "indeces": self.indexes,
-            "data_var_names": self.data_var_names
         }
 
-    def set_params(self, sample_size: int = None, indexes: List[str] = None, data_var_names=[]):
+    def set_params(self, sample_size: int = None, indexes: List[str] = None):
         """
         Set params.
 
@@ -53,8 +47,6 @@ class Sampler(BaseTransformer):
         :type sample_size: int
         :param indices: The indices which should be shifted through time
         :type indices: List[str]
-        :param data_var_names: Name for the shifted time series
-        :type data_var_names: List[str]
 
         """
         if sample_size:
@@ -62,8 +54,7 @@ class Sampler(BaseTransformer):
         if indexes is not None:
             # Do not use if indexes here, since this would be false if indexes is empty.
             self.indexes = indexes
-        if data_var_names:
-            self.data_var_names = data_var_names
+
 
     def transform(self, x: xr.DataArray) -> xr.DataArray:
         """
@@ -87,6 +78,5 @@ class Sampler(BaseTransformer):
                 "Perhaps you set the wrong indexes with set_params or during the initialization of the Sampler.",
                 module=self.name)
         result = result.transpose(_get_time_indeces(x)[0], "horizon", ...)
-        if self.data_var_names:
-            return result.rename(dict(zip(x.data_vars.keys(), self.data_var_names)))
+
         return result


Test patch:
diff --git a/tests/unit/modules/test_sample_module.py b/tests/unit/modules/test_sample_module.py
index 8f2b541..69b978d 100644
--- a/tests/unit/modules/test_sample_module.py
+++ b/tests/unit/modules/test_sample_module.py
@@ -20,7 +20,6 @@ class TestSampler(unittest.TestCase):
                          {
                              "lag": 2,
                              "indeces": [],
-                             "data_var_names": []
                          })
 
     def test_set_params(self):
@@ -28,44 +27,25 @@ class TestSampler(unittest.TestCase):
                          {
                              "lag": 2,
                              "indeces": [],
-                             "data_var_names" : []
                          })
-        self.sampler.set_params(indexes=["Foo"], sample_size=12, data_var_names=["BAR"])
+        self.sampler.set_params(indexes=["Foo"], sample_size=12)
         self.assertEqual(self.sampler.get_params(),
                          {
                              "lag": 12,
                              "indeces": ["Foo"],
-                             "data_var_names": ["BAR"]
                          })
 
     def test_transform(self):
         time = pd.date_range('2000-01-01', freq='24H', periods=7)
 
-        ds = xr.Dataset({'foo': ('time', [2, 3, 4, 5, 6, 7, 8]), 'time': time})
+        da = xr.DataArray([2, 3, 4, 5, 6, 7, 8], dims=['time'], coords={"time": time})
 
-        result = self.sampler.transform(ds)
+        result = self.sampler.transform(da)
 
         time = pd.date_range('2000-01-01', freq='24H', periods=7)
 
-        expected_result = xr.Dataset(
-            {'foo': (['time', 'horizon'], [[2, 0], [3, 2], [4,3], [5,4], [6,5], [7,6], [8,7]]),
-             'time': time})
-
-        xr.testing.assert_equal(result, expected_result)
-
-    def test_transform_bar(self):
-        self.sampler.set_params(data_var_names=["BAR"])
-        time = pd.date_range('2000-01-01', freq='24H', periods=7)
-
-        ds = xr.Dataset({'foo': ('time', [2, 3, 4, 5, 6, 7, 8]), 'time': time})
-
-        result = self.sampler.transform(ds)
-
-        time = pd.date_range('2000-01-01', freq='24H', periods=7)
-
-        expected_result = xr.Dataset(
-            {'BAR': (['time', 'horizon'], [[2, 0], [3, 2], [4,3], [5,4], [6,5], [7,6], [8,7]]),
-             'time': time})
+        expected_result = xr.DataArray([[2, 0], [3, 2], [4,3], [5,4], [6,5], [7,6], [8,7]], dims=["time", "horizon"],
+                                       coords={"time":time})
 
         xr.testing.assert_equal(result, expected_result)
 
@@ -73,9 +53,9 @@ class TestSampler(unittest.TestCase):
         time = pd.date_range('2000-01-01', freq='24H', periods=7)
         self.sampler.set_params(indexes=["FOO"])
 
-        ds = xr.Dataset({'foo': ('time', [2, 3, 4, 5, 6, 7, 8]), 'time': time})
+        da = xr.DataArray([2, 3, 4, 5, 6, 7, 8], dims=['time'], coords={"time": time})
         with self.assertRaises(WrongParameterException) as context:
-            self.sampler.transform(ds)
+            self.sampler.transform(da)
         self.assertEqual(context.exception.message,
                          "Not all indexes (['FOO']) are in the indexes of x (['time']). "
                          "Perhaps you set the wrong indexes with set_params or during the initialization of the Sampler.")