From 0ec7cec78ee5c36b19a72238848b9f53f8486b4d Mon Sep 17 00:00:00 2001 From: zogkoa Date: Wed, 12 Jun 2024 15:36:32 +0100 Subject: [PATCH 1/7] Add kwargs to arguments --- src/apply_imputation_link.py | 1 + src/calculate_imputation_link.py | 1 + src/construction_matches.py | 2 +- src/cumulative_imputation_links.py | 1 + src/flag_and_count_matched_pairs.py | 4 ++-- src/imputation_flags.py | 1 + 6 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/apply_imputation_link.py b/src/apply_imputation_link.py index e04104fb..a0ffa3af 100755 --- a/src/apply_imputation_link.py +++ b/src/apply_imputation_link.py @@ -11,6 +11,7 @@ def create_and_merge_imputation_values( auxiliary, construction_link, imputation_types=("c", "fir", "bir", "fic"), + **kwargs ): """ Loop through different imputation types and merge the results according diff --git a/src/calculate_imputation_link.py b/src/calculate_imputation_link.py index ff2de06f..f8312296 100644 --- a/src/calculate_imputation_link.py +++ b/src/calculate_imputation_link.py @@ -10,6 +10,7 @@ def calculate_imputation_link( target_variable: str, predictive_variable: str, link_col: str, + **kwargs ) -> pd.DataFrame: """ Calculate link between target_variable and predictive_variable by strata, diff --git a/src/construction_matches.py b/src/construction_matches.py index 41ab2590..f816e0d1 100644 --- a/src/construction_matches.py +++ b/src/construction_matches.py @@ -1,7 +1,7 @@ import pandas as pd -def flag_construction_matches(dataframe, target, period, auxiliary): +def flag_construction_matches(dataframe, target, period, auxiliary, **kwargs): """ Add flag to indicate whether the record has non-null target, period and auxiliary variables, and is therefore valid to use when calculating diff --git a/src/cumulative_imputation_links.py b/src/cumulative_imputation_links.py index 91dfbed9..735c64fe 100755 --- a/src/cumulative_imputation_links.py +++ b/src/cumulative_imputation_links.py @@ -10,6 +10,7 @@ def get_cumulative_links( period, imputation_link, time_difference=1, + **kwargs ): """ Create cumulative imputation links for multiple consecutive periods diff --git a/src/flag_and_count_matched_pairs.py b/src/flag_and_count_matched_pairs.py index 7d286892..f0caf868 100644 --- a/src/flag_and_count_matched_pairs.py +++ b/src/flag_and_count_matched_pairs.py @@ -3,7 +3,7 @@ def flag_matched_pair_merge( - df, forward_or_backward, target, period, reference, strata, time_difference=1 + df, forward_or_backward, target, period, reference, strata, time_difference=1,**kwargs ): """ function to add flag to df if data forms a matched pair @@ -120,7 +120,7 @@ def flag_matched_pair_shift( return df -def count_matches(df, flag_column_name, period, strata, count_column_name=None): +def count_matches(df, flag_column_name, period, strata, count_column_name=None, **kwargs): """ Function to count the number of records with matches per period and stratum diff --git a/src/imputation_flags.py b/src/imputation_flags.py index 91bc04ad..b1d129d8 100644 --- a/src/imputation_flags.py +++ b/src/imputation_flags.py @@ -9,6 +9,7 @@ def create_impute_flags( strata: str, auxiliary: str, predictive_auxiliary: str, + **kwargs ): """ From ab710d0cb127a493b20012eed2ae46937cb6ff02 Mon Sep 17 00:00:00 2001 From: zogkoa Date: Wed, 12 Jun 2024 15:42:47 +0100 Subject: [PATCH 2/7] Run commit hooks --- src/apply_imputation_link.py | 2 +- src/calculate_imputation_link.py | 2 +- src/cumulative_imputation_links.py | 2 +- src/flag_and_count_matched_pairs.py | 13 +++++++++++-- src/imputation_flags.py | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/apply_imputation_link.py b/src/apply_imputation_link.py index a0ffa3af..7d31ed1a 100755 --- a/src/apply_imputation_link.py +++ b/src/apply_imputation_link.py @@ -11,7 +11,7 @@ def create_and_merge_imputation_values( auxiliary, construction_link, imputation_types=("c", "fir", "bir", "fic"), - **kwargs + **kwargs ): """ Loop through different imputation types and merge the results according diff --git a/src/calculate_imputation_link.py b/src/calculate_imputation_link.py index f8312296..d73ea53f 100644 --- a/src/calculate_imputation_link.py +++ b/src/calculate_imputation_link.py @@ -10,7 +10,7 @@ def calculate_imputation_link( target_variable: str, predictive_variable: str, link_col: str, - **kwargs + **kwargs ) -> pd.DataFrame: """ Calculate link between target_variable and predictive_variable by strata, diff --git a/src/cumulative_imputation_links.py b/src/cumulative_imputation_links.py index 735c64fe..2831d65a 100755 --- a/src/cumulative_imputation_links.py +++ b/src/cumulative_imputation_links.py @@ -10,7 +10,7 @@ def get_cumulative_links( period, imputation_link, time_difference=1, - **kwargs + **kwargs ): """ Create cumulative imputation links for multiple consecutive periods diff --git a/src/flag_and_count_matched_pairs.py b/src/flag_and_count_matched_pairs.py index f0caf868..9448b93a 100644 --- a/src/flag_and_count_matched_pairs.py +++ b/src/flag_and_count_matched_pairs.py @@ -3,7 +3,14 @@ def flag_matched_pair_merge( - df, forward_or_backward, target, period, reference, strata, time_difference=1,**kwargs + df, + forward_or_backward, + target, + period, + reference, + strata, + time_difference=1, + **kwargs ): """ function to add flag to df if data forms a matched pair @@ -120,7 +127,9 @@ def flag_matched_pair_shift( return df -def count_matches(df, flag_column_name, period, strata, count_column_name=None, **kwargs): +def count_matches( + df, flag_column_name, period, strata, count_column_name=None, **kwargs +): """ Function to count the number of records with matches per period and stratum diff --git a/src/imputation_flags.py b/src/imputation_flags.py index b1d129d8..6173f981 100644 --- a/src/imputation_flags.py +++ b/src/imputation_flags.py @@ -9,7 +9,7 @@ def create_impute_flags( strata: str, auxiliary: str, predictive_auxiliary: str, - **kwargs + **kwargs ): """ From 67d5cb5181ec9816e4b05fa0df87d83fffe9b548 Mon Sep 17 00:00:00 2001 From: zogkoa Date: Thu, 20 Jun 2024 11:22:10 +0100 Subject: [PATCH 3/7] Run pre commit hooks --- src/flag_and_count_matched_pairs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/flag_and_count_matched_pairs.py b/src/flag_and_count_matched_pairs.py index 556e96f9..223e245f 100644 --- a/src/flag_and_count_matched_pairs.py +++ b/src/flag_and_count_matched_pairs.py @@ -2,7 +2,6 @@ import pandas as pd # noqa F401 - def flag_matched_pair( df, forward_or_backward, target, period, reference, strata, time_difference=1 ): From e0f6245dd51e0aa4ff99de63cd7c230c0cbd72b8 Mon Sep 17 00:00:00 2001 From: zogkoa Date: Thu, 20 Jun 2024 11:24:13 +0100 Subject: [PATCH 4/7] Add kwargs for mapping --- src/flag_and_count_matched_pairs.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/flag_and_count_matched_pairs.py b/src/flag_and_count_matched_pairs.py index 223e245f..add1c0a5 100644 --- a/src/flag_and_count_matched_pairs.py +++ b/src/flag_and_count_matched_pairs.py @@ -3,7 +3,14 @@ def flag_matched_pair( - df, forward_or_backward, target, period, reference, strata, time_difference=1 + df, + forward_or_backward, + target, + period, + reference, + strata, + time_difference=1, + **kwargs ): """ function to flag matched pairs using the shift method @@ -24,6 +31,8 @@ def flag_matched_pair( column name containing strata information (sic) time_difference: int lookup distance for matched pairs + kwargs : mapping, optional + A dictionary of keyword arguments passed into func. Returns ------- @@ -54,7 +63,7 @@ def flag_matched_pair( return df -def count_matches(df, flag, period, strata): +def count_matches(df, flag, period, strata, **kwargs): """ function to flag matched pairs using the shift method @@ -70,6 +79,8 @@ def count_matches(df, flag, period, strata): column name containing time period strata : str column name containing strata information (sic) + kwargs : mapping, optional + A dictionary of keyword arguments passed into func. Returns ------- From 694ae64e9c797191518187c164c3a30f6f1d1c8c Mon Sep 17 00:00:00 2001 From: zogkoa Date: Fri, 21 Jun 2024 13:10:36 +0100 Subject: [PATCH 5/7] Add docstrings for kwargs --- src/apply_imputation_link.py | 2 ++ src/construction_matches.py | 3 ++- src/cumulative_imputation_links.py | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/apply_imputation_link.py b/src/apply_imputation_link.py index 7d31ed1a..a1c18f8b 100755 --- a/src/apply_imputation_link.py +++ b/src/apply_imputation_link.py @@ -45,6 +45,8 @@ def create_and_merge_imputation_values( tuple. If 'fic' is selected 'c' must also be selected and proceed 'fic'. For 'fic' to produce the correct result, the C marker must be in the first period for a given reference. + kwargs : mapping, optional + A dictionary of keyword arguments passed into func. Returns ------- diff --git a/src/construction_matches.py b/src/construction_matches.py index f816e0d1..84695ca2 100644 --- a/src/construction_matches.py +++ b/src/construction_matches.py @@ -16,7 +16,8 @@ def flag_construction_matches(dataframe, target, period, auxiliary, **kwargs): name of column containing time period auxiliary : string name of column containing auxiliary information - + kwargs : mapping, optional + A dictionary of keyword arguments passed into func. Returns ------- pandas.DataFrame diff --git a/src/cumulative_imputation_links.py b/src/cumulative_imputation_links.py index 2831d65a..1180e925 100755 --- a/src/cumulative_imputation_links.py +++ b/src/cumulative_imputation_links.py @@ -34,6 +34,8 @@ def get_cumulative_links( column name containing imputation links time_difference : int time difference between predictive and target period in months + kwargs : mapping, optional + A dictionary of keyword arguments passed into func Returns ------- From 8cd2535eb01ae137100e61c93cf56aaa67b2bd6e Mon Sep 17 00:00:00 2001 From: zogkoa Date: Fri, 21 Jun 2024 13:13:21 +0100 Subject: [PATCH 6/7] Add docstrings for kwargs --- src/calculate_imputation_link.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calculate_imputation_link.py b/src/calculate_imputation_link.py index d73ea53f..81709697 100644 --- a/src/calculate_imputation_link.py +++ b/src/calculate_imputation_link.py @@ -33,7 +33,8 @@ def calculate_imputation_link( Column name of the predicted target variable. link_col : str Name to use for the new column containing imputation link - + kwargs : mapping, optional + A dictionary of keyword arguments passed into func. Returns ------- df : pd.DataFrame From a0bcfb9c538fb7e9f55ebb951897300a79a4d08e Mon Sep 17 00:00:00 2001 From: zogkoa Date: Mon, 24 Jun 2024 12:04:47 +0100 Subject: [PATCH 7/7] Add docstrings for kwargs --- src/imputation_flags.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/imputation_flags.py b/src/imputation_flags.py index 6173f981..f4517c1d 100644 --- a/src/imputation_flags.py +++ b/src/imputation_flags.py @@ -37,6 +37,8 @@ def create_impute_flags( predictive_auxiliary: str Column name containing predictive auxiliary data, this is created, by flag_matched_pair_merge function. + kwargs : mapping, optional + A dictionary of keyword arguments passed into func. Returns -------