Exemplo n.º 1
0
def test_raises_error_when_transform_df_with_different_n_variables(
        df_datetime):
    transformer = DatetimeFeatures()
    transformer.fit(df_datetime)
    # different number of columns than the df used to fit
    with pytest.raises(ValueError):
        transformer.transform(df_datetime[vars_dt])
Exemplo n.º 2
0
def test_raises_error_when_nan_in_transform_df(df_datetime):
    transformer = DatetimeFeatures()
    transformer.fit(df_datetime)
    # dataset containing nans
    with pytest.raises(ValueError):
        transformer.transform(dates_nan)
    transformer = DatetimeFeatures(variables="index")
    transformer.fit(dates_idx_dt)
    with pytest.raises(ValueError):
        transformer.transform(dates_idx_nan)
Exemplo n.º 3
0
def test_attributes_upon_fitting(df_datetime):
    transformer = DatetimeFeatures()
    transformer.fit(df_datetime)

    assert transformer.variables_ == vars_dt
    assert transformer.features_to_extract_ == FEATURES_DEFAULT
    assert transformer.n_features_in_ == df_datetime.shape[1]

    transformer = DatetimeFeatures(variables="date_obj1",
                                   features_to_extract="all")
    transformer.fit(df_datetime)

    assert transformer.variables_ == ["date_obj1"]
    assert transformer.features_to_extract_ == FEATURES_SUPPORTED

    transformer = DatetimeFeatures(
        variables=["date_obj1", "time_obj"],
        features_to_extract=["year", "quarter_end", "second"],
    )
    transformer.fit(df_datetime)

    assert transformer.variables_ == ["date_obj1", "time_obj"]
    assert transformer.features_to_extract_ == [
        "year", "quarter_end", "second"
    ]
Exemplo n.º 4
0
def test_raises_error_when_fitting_not_a_df(_not_a_df):
    transformer = DatetimeFeatures()
    # trying to fit not a df
    with pytest.raises(TypeError):
        transformer.fit(_not_a_df)
Exemplo n.º 5
0
def test_raises_error_when_transforming_not_a_df(_not_a_df, df_datetime):
    transformer = DatetimeFeatures()
    transformer.fit(df_datetime)
    # trying to transform not a df
    with pytest.raises(TypeError):
        transformer.transform(_not_a_df)