Skip to content

Commit

Permalink
add check to basics
Browse files Browse the repository at this point in the history
  • Loading branch information
slopp committed Sep 14, 2023
1 parent 92e1ade commit 04cacb3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion hooli_basics/definitions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dagster import asset
from dagster import asset, asset_check, AssetCheckResult, Definitions
from pandas import DataFrame, read_html, get_dummies, to_numeric
from sklearn.linear_model import LinearRegression as Regression

Expand All @@ -9,15 +9,28 @@ def country_stats() -> DataFrame:
df["pop_change"] = ((to_numeric(df["pop_2023"]) / to_numeric(df["pop_2022"])) - 1)*100
return df

@asset_check(
)
def check_country_stats(country_stats):
return AssetCheckResult(success=True)

@asset
def change_model(country_stats: DataFrame) -> Regression:
data = country_stats.dropna(subset=["pop_change"])
dummies = get_dummies(data[["continent"]])
return Regression().fit(dummies, data["pop_change"])



@asset
def continent_stats(country_stats: DataFrame, change_model: Regression) -> DataFrame:
result = country_stats.groupby("continent").sum()
result["pop_change_factor"] = change_model.coef_
return result


defs = Definitions(
assets=[country_stats, continent_stats, change_model],
asset_checks=[check_country_stats]
)

0 comments on commit 04cacb3

Please sign in to comment.