def test_toDatetimeComponents_passed_Year_Component_drop_Date_True_Default( df_small, df_small_NFeatures): dt = df_small.copy() for feature in dt.columns[0:6]: dt[feature] = pd.to_datetime(dt[feature], exact=True, errors="ignore", infer_datetime_format=True) with pytest.raises(PasoError): toDatetimeComponents(dt, components=["Year"])
def test_toDatetimeComponents_internet_traffic_datetime_no_drop( df_internet_traffic): dt = df_internet_traffic.copy() dt["date"] = pd.to_datetime( df_internet_traffic["date"], exact=True, errors="ignore", infer_datetime_format=True, ) assert (toDatetimeComponents(dt, drop=False).columns == [ "date", "bit", "byte", "Year", "Month", "Week", "Day", "Dayofweek", "Dayofyear", "Elapsed", "Is_month_end", "Is_month_start", "Is_quarter_end", "Is_quarter_start", "Is_year_end", "Is_year_start", ], )
def test_toDatetimeComponents_passed_Year_Component_drop_Date_False( df_small_no_NA, df_small_NFeatures): dt = df_small_no_NA.copy() for feature in dt.columns[0:6]: dt[feature] = pd.to_datetime(dt[feature], exact=True, errors="ignore", infer_datetime_format=True) assert (toDatetimeComponents(dt, drop=False, components=[ "Year" ]).shape[1] == (df_small_NFeatures - 4) * 1 + df_small_NFeatures)
def test_toDatetimeComponents_passed_DoY_Elapsed_IME_Components_drop_Date_True_method( df_small_no_NA, df_small_NFeatures): dt = df_small_no_NA.copy() for feature in dt.columns[0:6]: dt[feature] = pd.to_datetime(dt[feature], exact=True, errors="ignore", infer_datetime_format=True) assert (toDatetimeComponents(dt, components=[ "Dayofyear", "Elapsed", "Is_month_end" ]).shape[1] == (df_small_NFeatures - 4) * 3 + df_small_NFeatures - 5)
def test_toDatetimeComponents_with_NA_ValueError(df_small_NA): with pytest.raises(PasoError): toDatetimeComponents(df_small_NA)
def test_toDatetimeComponents_passed_All_Componentss_drop_Date_True_Default( df_small_no_NA, df_small_NFeatures, NComponentFeatures): dt = df_small_no_NA.copy() assert (toDatetimeComponents(dt).shape[1] == (df_small_NFeatures - 4) * NComponentFeatures + df_small_NFeatures - 5)
def test_df_toDatetimeComponents_WrongArgType(): with pytest.raises(PasoError): toDatetimeComponents([1, 2, 3])