from dask.distributed import Client, progress
def get_forecast_for_ts(city, ts):
print(f'Computing forecast for {city}')
m.add_seasonality(name='yearly', period=365, fourier_order=10)
future = m.make_future_dataframe(periods=7, freq='D')
#This function creates an input dataframe for Prophet, keyed by city
#and executes the prophet forecast in parallel over a specified number of workers
def get_forecasts_dask(city:str = None):
input_df = get_delay_ts(city=city).execute()
#Change n_workers as needed for the machine you're running on (number of cores)
client = Client(threads_per_worker=1, n_workers=16)
#Use dask delayed, to create an array of deferred calls to the forecast method, splitting the above result dataframe by city
fcsts = [delayed(get_forecast_for_ts)(city=k, ts=v[['ds','y']]) for k, v in input_df.groupby('dest_city')]
#Run the forecasts in parallel
forecasts = delayed(fcsts).compute()
print(f"Unexpected error {e}")