From cbbbc706c532c3eeff4e29fcc9ce55bac825828b Mon Sep 17 00:00:00 2001 From: Taylor Dunlap Date: Wed, 17 Jan 2024 00:12:44 +0000 Subject: [PATCH] fixing python model --- .../python/forecast_daily_returns.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/models/demo_examples/python/forecast_daily_returns.py b/models/demo_examples/python/forecast_daily_returns.py index d09524f..ad9df82 100644 --- a/models/demo_examples/python/forecast_daily_returns.py +++ b/models/demo_examples/python/forecast_daily_returns.py @@ -1,15 +1,18 @@ import pandas as pd from prophet import Prophet +import pandas as pd # import packages +from prophet import Prophet + def model( dbt, session ): dbt.config( - materialized="table", - packages=['pandas','Prophet','holidays==0.18'] # how to import python libraries in dbt's context + materialized="table", # the incremental materialization is also supported + packages=['pandas==1.5.3','Prophet','holidays==0.18'] # how to import python libraries in dbt's context ) # use historical data to fit model - df = dbt.ref("agg_daily_returned_orders").to_pandas() + df = dbt.ref("agg_daily_returned_orders").to_pandas() # use dbt.ref to reference other models in your dbt project df.columns = df.columns.str.lower() m = Prophet() m.fit(df) @@ -18,4 +21,8 @@ def model( dbt, session ): future = m.make_future_dataframe(periods=365) df = m.predict(future) - return df + return df # return final dataset via data frame. This is required. + +# The Preview button in the IDE is disabled, but you can iterate by building the object and then opening a new tab and running... select * from ref('forecast_daily_returns') +# Tests and Documentation can also be applied to python models, in the same manner as sql models (.yml file or custom tests). +