Skip to content

Commit

Permalink
Remove mask_values from calculate_links function
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonZogk committed May 17, 2024
1 parent a3067c1 commit 4ddd931
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/forward_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ def calculate_imputation_link(
match_col: str,
target_variable: str,
predictive_variable: str,
filter_cond: str = None,
) -> pd.DataFrame:
) -> pd.Series:
"""
Calculate link between target_variable and predictive_variable by given groups,
a match_col must be supplied which indicates if target_variable and
predictive_variable can be linked. If an optional filter_cond is given
it excludes them when calculating the links.
predictive_variable can be linked.
Parameters
----------
Expand All @@ -66,9 +64,6 @@ def calculate_imputation_link(
Column name of the targeted variable.
predictive_variable : str
Column name of the predicted target variable.
filter_cond : str, optional
Expression to exclude specific values from the links.
The default is None.
Returns
-------
Expand All @@ -78,11 +73,6 @@ def calculate_imputation_link(

df_intermediate = df.copy()

# If condition supplied exclude filtered values from links
if filter_cond is not None:

df_intermediate.mask_values([target_variable, predictive_variable], filter_cond)

df_intermediate[target_variable] = (
df_intermediate[target_variable] * df_intermediate[match_col]
)
Expand All @@ -99,6 +89,4 @@ def calculate_imputation_link(

link = numerator / denominator

link.replace(np.nan, 1, inplace=True) # set defaults

return link

0 comments on commit 4ddd931

Please sign in to comment.