def test_find_with_dataframe(self, jhu_data, population_data): population = population_data.value("Italy") clean_df = jhu_data.cleaned() warnings.filterwarnings("ignore", category=DeprecationWarning) change_finder = ChangeFinder(clean_df, population, country="Italy") change_finder.run() phase_series = change_finder.show() assert isinstance(phase_series, PhaseSeries)
def test_find_with_small_min_size(self, jhu_data, population_data): population = population_data.value("Italy") clean_df = jhu_data.cleaned() warnings.filterwarnings("ignore", category=DeprecationWarning) with pytest.raises(ValueError): min_size = 2 change_finder = ChangeFinder(clean_df, population, country="Italy", min_size=min_size) change_finder.run()
def test_find_with_few_records(self, jhu_data, population_data): population = population_data.value("Italy") min_size = 7 df = jhu_data.subset(country="Italy") start_date = df.loc[df.index[0], Term.DATE].strftime(Term.DATE_FORMAT) end_date = Term.date_change(start_date, days=min_size - 2) sr_df = jhu_data.to_sr(country="Italy", population=population, end_date=end_date) with pytest.raises(ValueError): change_finder = ChangeFinder(sr_df, min_size=min_size) change_finder.run()
def test_find_with_few_records(self, jhu_data, population_data): min_size = 7 population = population_data.value("Italy") clean_df = jhu_data.subset("Italy") clean_df[Term.COUNTRY] = "Italy" clean_df[Term.PROVINCE] = Term.UNKNOWN clean_df = clean_df.iloc[:(min_size - 1), :] warnings.filterwarnings("ignore", category=DeprecationWarning) with pytest.raises(ValueError): change_finder = ChangeFinder(clean_df, population, country="Italy", min_size=min_size) change_finder.run()
def test_find(self, jhu_data, population_data, country, max_rmsle=20.0): # Setup population = population_data.value(country) sr_df = jhu_data.to_sr(country=country, population=population) # Find change points change_finder = ChangeFinder(sr_df, max_rmsle=max_rmsle) change_finder.run() # For all phases, check if RMSLE score is lower than max_rmsle=20.0 for (start_date, end_date) in zip(*change_finder.date_range()): phase_df = jhu_data.to_sr(country=country, population=population, start_date=start_date, end_date=end_date) rmsle = Trend(sr_df=phase_df).rmsle() assert rmsle < max_rmsle
def test_find(self, jhu_data, population_data, country): warnings.simplefilter("ignore", category=DeprecationWarning) warnings.simplefilter("ignore", category=UserWarning) population = population_data.value(country) sr_df = jhu_data.to_sr(country=country, population=population) change_finder = ChangeFinder(sr_df) change_finder.run() change_finder.show(area=jhu_data.area_name(country=country)) assert isinstance(change_finder.date_range(), tuple)
def test_min_size(self, jhu_data, population_data, country): # Dataset population = population_data.value(country) subset_df = jhu_data.subset(country=country, population=population) # Too small min_size with pytest.raises(ValueError): TrendDetector(data=subset_df, min_size=2) # Too large min_size with pytest.raises(ValueError): TrendDetector(data=subset_df, min_size=100000) # Reset detector = TrendDetector(data=subset_df) detector.reset() # Deprecated warnings.filterwarnings("ignore", category=DeprecationWarning) ChangeFinder(subset_df) Trend(subset_df)
def test_find(self, jhu_data, population_data, country): population = population_data.value(country) change_finder = ChangeFinder(jhu_data, population, country=country) change_finder.run() phase_series = change_finder.show() assert isinstance(phase_series, PhaseSeries)
def test_find_with_small_min_size(self, jhu_data, population_data): population = population_data.value("Italy") sr_df = jhu_data.to_sr(country="Italy", population=population) with pytest.raises(ValueError): change_finder = ChangeFinder(sr_df, min_size=2) change_finder.run()