test_diagnostics.py (prophet-1.1) | : | test_diagnostics.py (prophet-1.1.1) | ||
---|---|---|---|---|
skipping to change at line 57 | skipping to change at line 57 | |||
methods = [None, 'processes', 'threads', CustomParallelBackend()] | methods = [None, 'processes', 'threads', CustomParallelBackend()] | |||
try: | try: | |||
from dask.distributed import Client | from dask.distributed import Client | |||
client = Client(processes=False) # noqa | client = Client(processes=False) # noqa | |||
methods.append("dask") | methods.append("dask") | |||
except ImportError: | except ImportError: | |||
pass | pass | |||
for parallel in methods: | for parallel in methods: | |||
df_cv = diagnostics.cross_validation( | with self.subTest(i=parallel): | |||
m, horizon='4 days', period='10 days', initial='115 days', | df_cv = diagnostics.cross_validation( | |||
parallel=parallel) | m, horizon='4 days', period='10 days', initial='115 days', | |||
self.assertEqual(len(np.unique(df_cv['cutoff'])), 3) | parallel=parallel) | |||
self.assertEqual(max(df_cv['ds'] - df_cv['cutoff']), horizon) | self.assertEqual(len(np.unique(df_cv['cutoff'])), 3) | |||
self.assertTrue(min(df_cv['cutoff']) >= min(self.__df['ds']) + initi | self.assertEqual(max(df_cv['ds'] - df_cv['cutoff']), horizon) | |||
al) | self.assertTrue(min(df_cv['cutoff']) >= min(self.__df['ds']) + i | |||
dc = df_cv['cutoff'].diff() | nitial) | |||
dc = dc[dc > pd.Timedelta(0)].min() | dc = df_cv['cutoff'].diff() | |||
self.assertTrue(dc >= period) | dc = dc[dc > pd.Timedelta(0)].min() | |||
self.assertTrue((df_cv['cutoff'] < df_cv['ds']).all()) | self.assertTrue(dc >= period) | |||
# Each y in df_cv and self.__df with same ds should be equal | self.assertTrue((df_cv['cutoff'] < df_cv['ds']).all()) | |||
df_merged = pd.merge(df_cv, self.__df, 'left', on='ds') | # Each y in df_cv and self.__df with same ds should be equal | |||
self.assertAlmostEqual( | df_merged = pd.merge(df_cv, self.__df, 'left', on='ds') | |||
np.sum((df_merged['y_x'] - df_merged['y_y']) ** 2), 0.0) | self.assertAlmostEqual( | |||
df_cv = diagnostics.cross_validation( | np.sum((df_merged['y_x'] - df_merged['y_y']) ** 2), 0.0) | |||
m, horizon='4 days', period='10 days', initial='135 days') | df_cv = diagnostics.cross_validation( | |||
self.assertEqual(len(np.unique(df_cv['cutoff'])), 1) | m, horizon='4 days', period='10 days', initial='135 days') | |||
with self.assertRaises(ValueError): | self.assertEqual(len(np.unique(df_cv['cutoff'])), 1) | |||
diagnostics.cross_validation( | with self.assertRaises(ValueError): | |||
m, horizon='10 days', period='10 days', initial='140 days') | diagnostics.cross_validation( | |||
m, horizon='10 days', period='10 days', initial='140 day | ||||
s') | ||||
# invalid alias | # invalid alias | |||
with self.assertRaisesRegex(ValueError, "'parallel' should be one"): | with self.assertRaisesRegex(ValueError, "'parallel' should be one"): | |||
diagnostics.cross_validation(m, horizon="4 days", parallel="bad") | diagnostics.cross_validation(m, horizon="4 days", parallel="bad") | |||
# no map method | # no map method | |||
with self.assertRaisesRegex(ValueError, "'parallel' should be one"): | with self.assertRaisesRegex(ValueError, "'parallel' should be one"): | |||
diagnostics.cross_validation(m, horizon="4 days", parallel=object()) | diagnostics.cross_validation(m, horizon="4 days", parallel=object()) | |||
def test_check_single_cutoff_forecast_func_calls(self): | def test_check_single_cutoff_forecast_func_calls(self): | |||
End of changes. 1 change blocks. | ||||
21 lines changed or deleted | 23 lines changed or added |