Exemplo n.º 1
0
    def test_invalid_window_size(self):
        window_size = -1
        df = pd.DataFrame.from_dict({"x0": [0, 1, 2, 3, 4, 5]})

        ma_feature = MovingAverage(window_size=window_size)

        with pytest.raises(ValueError):
            ma_feature.fit_transform(df)
Exemplo n.º 2
0
    def test_random_ts_and_window_size(self, df: pd.DataFrame,
                                       window_size: int):
        ma_feature = MovingAverage(window_size=window_size)
        df_ma = ma_feature.fit_transform(df)
        expected_df_ma = self._correct_ma(df, window_size)

        testing.assert_frame_equal(expected_df_ma, df_ma)
Exemplo n.º 3
0
    def test_positive_window_size(self):
        window_size = 2
        df = pd.DataFrame.from_dict({"x": [0, 1, 2, 3, 4, 5]})

        ma_feature = MovingAverage(window_size=window_size)
        df_ma = ma_feature.fit_transform(df)
        output_name = "x__" + ma_feature.__class__.__name__
        expected_df_ma = pd.DataFrame.from_dict(
            {output_name: [np.nan, 0.5, 1.5, 2.5, 3.5, 4.5]})

        testing.assert_frame_equal(expected_df_ma, df_ma, check_names=False)
Exemplo n.º 4
0
    def test_multi_columns_window_size(self):
        window_size = 2
        df = pd.DataFrame.from_dict({
            "x0": [0, 1, 2, 3, 4, 5],
            "x1": [7, 8, 9, 10, 11, 12]
        })

        ma_feature = MovingAverage(window_size=window_size)
        feature_name = ma_feature.__class__.__name__

        df_ma = ma_feature.fit_transform(df)
        expected_df_ma = pd.DataFrame({
            f"x0__{feature_name}": [np.nan, 0.5, 1.5, 2.5, 3.5, 4.5],
            f"x1__{feature_name}": [np.nan, 7.5, 8.5, 9.5, 10.5, 11.5],
        })

        testing.assert_frame_equal(expected_df_ma, df_ma, check_names=False)