Repository: KIT-IAI/pyWATTS

Issue:
Mask in rolling_base does not work for weekends and or public holidays
**Describe the bug**
The mask in rolling_base does not works for weekends and public holidays. All values of weekends and public holidays are in the same group and not also grouped by the minute and the hour.

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ed8fab..5316d4c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,8 @@
 * Missing call of _get_rolling in Rolling Base  ([#76](https://github.com/KIT-IAI/pyWATTS/issues/76))
 * Fix save and load of keras Wrapper  ([#91](https://github.com/KIT-IAI/pyWATTS/issues/91))
 * Import of pytorchWrapper via wrapper.__init__
+* Fix the mask for weekends and public holidays in rolling_base  ([#107](https://github.com/KIT-IAI/pyWATTS/issues/107))
+
 
 
 ## 0.1.0 - 2021-25-03
diff --git a/pywatts/modules/rolling_base.py b/pywatts/modules/rolling_base.py
index ef383a3..1b10ac9 100644
--- a/pywatts/modules/rolling_base.py
+++ b/pywatts/modules/rolling_base.py
@@ -38,13 +38,12 @@ class RollingBase(BaseTransformer, ABC):
      :type closed: str
     """
 
-    def __init__(self, name: str = "RollingMean", window_size=24 * 7, window_size_unit="d",
+    def __init__(self, name: str = None, window_size=24 * 7, window_size_unit="d",
                  group_by: RollingGroupBy = RollingGroupBy.No, continent: str = "Europe",
                  country: str = "Germany", closed="left"):
 
-        super().__init__(name)
+        super().__init__(name if name is not None else self.__class__.__name__)
         self.window_size = window_size
-        self.window_size_unit = "d"
         self.group_by = group_by
         self.window_size_unit = window_size_unit
         self.country = country
@@ -109,13 +108,12 @@ class RollingBase(BaseTransformer, ABC):
         if self.group_by == RollingGroupBy.No:
             rolling = self._get_rolling(df)
         elif self.group_by == RollingGroupBy.WorkdayWeekend:
-            mask = df.index.map(
-                lambda element: element.minute + 1440 if element.weekday() >= 5 else element.hour).values
+            mask = df.index.map(lambda
+                                    element: element.minute + element.hour * 60 + 1440 if element.weekday() >= 5 else element.minute + element.hour * 60).values
             rolling = self._get_rolling(df.groupby(mask)).reset_index(0).drop("level_0", axis=1).sort_index()
         elif self.group_by == RollingGroupBy.WorkdayWeekendAndHoliday:
-            mask = df.index.map(lambda element:
-                                element.minute + 1440 if self.cal.is_holiday(element) or element.weekday() >= 5
-                                else element.hour).values
+            mask = df.index.map(lambda element: element.minute + element.hour * 60 + 1440 if self.cal.is_holiday(
+                element) or element.weekday() >= 5 else element.minute + element.hour * 60).values
             rolling = self._get_rolling(df.groupby(mask)).reset_index(0).drop("level_0", axis=1).sort_index()
         else:
             raise WrongParameterException(
diff --git a/pywatts/modules/rolling_mean.py b/pywatts/modules/rolling_mean.py
index d5c8d65..22f5d01 100644
--- a/pywatts/modules/rolling_mean.py
+++ b/pywatts/modules/rolling_mean.py
@@ -1,13 +1,4 @@
-from enum import IntEnum
-from typing import Dict, Optional
-
-import xarray as xr
-
-from pywatts.core.base import BaseTransformer
-from pywatts.core.exceptions.wrong_parameter_exception import WrongParameterException
 from pywatts.modules.rolling_base import RollingBase
-from pywatts.utils._workalendar_utils import _init_calendar
-from pywatts.utils._xarray_time_series_utils import numpy_to_xarray
 
 
 class RollingMean(RollingBase):


Test patch:
diff --git a/tests/unit/modules/test_rolling_mean.py b/tests/unit/modules/test_rolling_mean.py
index b1b7521..a777205 100644
--- a/tests/unit/modules/test_rolling_mean.py
+++ b/tests/unit/modules/test_rolling_mean.py
@@ -52,34 +52,35 @@ class TestRollingMean(unittest.TestCase):
     def test_transform_groupbyNo(self):
         time = pd.date_range('2002-01-01', freq='24H', periods=7)
 
-        ds = xr.DataArray([2, 3, 4, 5, 6, 7, 8], dims=["time"] , coords={'time': time})
+        ds = xr.DataArray([2, 3, 4, 5, 6, 7, 8], dims=["time"], coords={'time': time})
 
         result = self.rolling_mean.transform(ds)
 
-        expected_result = xr.DataArray([0. , 2. , 2.5, 3. , 4. , 5. , 6. ], dims=["time"] , coords={'time': time})
+        expected_result = xr.DataArray([0., 2., 2.5, 3., 4., 5., 6.], dims=["time"], coords={'time': time})
 
         xr.testing.assert_equal(result, expected_result)
 
     def test_transform_groupbyWeekendWeekday(self):
         self.rolling_mean.set_params(group_by=RollingGroupBy.WorkdayWeekend)
-        time = pd.date_range('2002-01-01', freq='24H', periods=7)
+        time = pd.date_range('2002-01-01', freq='12H', periods=14)
 
-        ds = xr.DataArray([2, 3, 4, 5, 6, 7, 42], dims=["time"], coords={'time': time})
+        ds = xr.DataArray([2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 42, 42], dims=["time"], coords={'time': time})
 
         result = self.rolling_mean.transform(ds)
 
-        expected_result = xr.DataArray([0., 2., 2.5, 3., 0., 6., 5.], dims=["time"], coords={'time': time})
+        expected_result = xr.DataArray([0., 0., 2., 2., 2.5, 2.5, 3., 3., 0., 0., 6., 6., 5., 5.], dims=["time"],
+                                       coords={'time': time})
 
         xr.testing.assert_equal(result, expected_result)
 
     def test_transform_groupbyWeekendWeekdayAndHoliday(self):
-        time = pd.date_range('2002-01-01', freq='24H', periods=7)
+        time = pd.date_range('2002-01-01', freq='12H', periods=14)
         self.rolling_mean.set_params(window_size=4, group_by=RollingGroupBy.WorkdayWeekendAndHoliday)
 
-        ds = xr.DataArray([2, 3, 4, 5, 6, 7, 42], dims=["time"], coords={'time': time})
+        ds = xr.DataArray([2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 42, 42], dims=["time"], coords={'time': time})
 
         result = self.rolling_mean.transform(ds)
 
-        expected_result = xr.DataArray([0., 0., 3, 3.5, 2., 6., 4.5], dims=["time"], coords={'time': time})
+        expected_result = xr.DataArray([0., 0., 0., 0., 3, 3, 3.5, 3.5, 2, 2., 6.,6,4.5, 4.5], dims=["time"], coords={'time': time})
 
         xr.testing.assert_equal(result, expected_result)