Exemplo n.º 1
0
 def test_naming(self, time_series: pd.DataFrame):
     exogenous = Exogenous()
     transformed_time_series = exogenous.fit_transform(time_series)
     expected_columns = [
         f"{column_name}__Exogenous" for column_name in time_series.columns
     ]
     assert expected_columns == list(transformed_time_series.columns)
Exemplo n.º 2
0
    def test_correct_nearest_pad_method(self):
        method = "nearest"
        exog = pd.DataFrame.from_dict({"x_1": [0, 1, 2, 3]})
        exog.index = [
            pd.Timestamp(2000, 1, 1),
            pd.Timestamp(2000, 2, 1),
            pd.Timestamp(2000, 3, 1),
            pd.Timestamp(2000, 4, 1),
        ]

        df = pd.DataFrame.from_dict({"x_2": [10, 11, 12, 13]})
        df.index = [
            pd.Timestamp(2000, 1, 1),
            pd.Timestamp(2000, 1, 2),
            pd.Timestamp(2000, 1, 3),
            pd.Timestamp(2000, 1, 29),
        ]

        exog_feature = Exogenous(exogenous_time_series=exog, method=method)

        new_exog_feature = exog_feature.fit_transform(df)
        expected_exog = pd.DataFrame.from_dict({"output_name": [0, 0, 0, 1]})
        expected_exog.index = [
            pd.Timestamp(2000, 1, 1),
            pd.Timestamp(2000, 1, 2),
            pd.Timestamp(2000, 1, 3),
            pd.Timestamp(2000, 1, 29),
        ]

        testing.assert_frame_equal(expected_exog, new_exog_feature)
Exemplo n.º 3
0
    def test_correct_exog_none_method(self):
        method = None
        exog = pd.DataFrame.from_dict({"x0": [0, 1, 2, 3]})
        exog.index = [
            pd.Timestamp(2000, 1, 1),
            pd.Timestamp(2000, 2, 1),
            pd.Timestamp(2000, 3, 1),
            pd.Timestamp(2000, 4, 1),
        ]

        df = pd.DataFrame.from_dict({"x1": [10, 11, 12, 13]})
        df.index = [
            pd.Timestamp(2000, 1, 1),
            pd.Timestamp(2000, 1, 2),
            pd.Timestamp(2000, 1, 3),
            pd.Timestamp(2000, 1, 4),
        ]

        exog_feature = Exogenous(exogenous_time_series=exog, method=method)
        feature_name = exog_feature.__class__.__name__

        new_exog_feature = exog_feature.fit_transform(df)
        expected_exog = pd.DataFrame.from_dict(
            {f"x0__{feature_name}": [0, np.nan, np.nan, np.nan]})
        expected_exog.index = [
            pd.Timestamp(2000, 1, 1),
            pd.Timestamp(2000, 1, 2),
            pd.Timestamp(2000, 1, 3),
            pd.Timestamp(2000, 1, 4),
        ]

        testing.assert_frame_equal(expected_exog, new_exog_feature)
Exemplo n.º 4
0
    def test_correct_multi_columns_exog(self):
        output_name = "exog"
        exog = pd.DataFrame.from_dict({
            "x_0": [0, 1, 2, 3],
            "x_1": [5, 6, 7, 8]
        })
        exog.index = [
            pd.Timestamp(2000, 1, 1),
            pd.Timestamp(2000, 2, 1),
            pd.Timestamp(2000, 3, 1),
            pd.Timestamp(2000, 4, 1),
        ]

        df = pd.DataFrame.from_dict({"x_2": [10, 11, 12, 13]})
        df.index = [
            pd.Timestamp(2000, 1, 1),
            pd.Timestamp(2000, 1, 2),
            pd.Timestamp(2000, 1, 3),
            pd.Timestamp(2000, 1, 29),
        ]

        exog_feature = Exogenous(exogenous_time_series=exog)

        new_exog_feature = exog_feature.fit_transform(df)
        expected_exog = pd.DataFrame.from_dict({
            f"{output_name}_0": [0, np.nan, np.nan, np.nan],
            f"{output_name}_1": [5, np.nan, np.nan, np.nan],
        })
        expected_exog.index = [
            pd.Timestamp(2000, 1, 1),
            pd.Timestamp(2000, 1, 2),
            pd.Timestamp(2000, 1, 3),
            pd.Timestamp(2000, 1, 29),
        ]

        testing.assert_frame_equal(expected_exog, new_exog_feature)
Exemplo n.º 5
0
 def test_multiple_columns(self, time_series: pd.DataFrame):
     exogenous = Exogenous()
     transformed_time_series = exogenous.fit_transform(time_series)
     transformed_time_series.columns = ["A", "B"]
     assert_frame_equal(transformed_time_series, time_series, check_names=False)