From 076f20bc209aa3c4c9bc0549f0be972a797a5cb2 Mon Sep 17 00:00:00 2001 From: giaccg Date: Fri, 2 Aug 2024 12:43:09 +0100 Subject: [PATCH 1/2] fixed type in winsorisation flag --- mbs_results/flag_for_winsorisation.py | 2 +- tests/test_flag_for_winsorisation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mbs_results/flag_for_winsorisation.py b/mbs_results/flag_for_winsorisation.py index dc88634a..dc470e6c 100644 --- a/mbs_results/flag_for_winsorisation.py +++ b/mbs_results/flag_for_winsorisation.py @@ -26,7 +26,7 @@ def winsorisation_flag(df, a_weight, g_weight): df["flag_calculation"] = df[a_weight] * df[g_weight] - df["nw_ag_flag"] = df["flag_calculation"].apply(lambda x: True if x <= 1 else 0) + df["nw_ag_flag"] = df["flag_calculation"].apply(lambda x: True if x <= 1 else False) df = df.drop("flag_calculation", axis=1) diff --git a/tests/test_flag_for_winsorisation.py b/tests/test_flag_for_winsorisation.py index 849567b5..9dff320b 100755 --- a/tests/test_flag_for_winsorisation.py +++ b/tests/test_flag_for_winsorisation.py @@ -28,4 +28,4 @@ def test_winsorisation_flag(self, winsorisation_flag_test_data): df=df_input, a_weight="a_weight", g_weight="g_weight" ) - assert_frame_equal(df_output, df_expected_output, check_dtype=False) + assert_frame_equal(df_output, df_expected_output) From 00ebc3685d90228e8649eb338410ae3e0a33cca6 Mon Sep 17 00:00:00 2001 From: giaccg Date: Fri, 2 Aug 2024 15:16:56 +0100 Subject: [PATCH 2/2] fixed pre commit hook --- mbs_results/calculate_predicted_unit_value.py | 4 ++-- mbs_results/calculate_ratio_estimation.py | 2 +- mbs_results/calculate_winsorised_weight.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mbs_results/calculate_predicted_unit_value.py b/mbs_results/calculate_predicted_unit_value.py index 6b927241..3631bd4b 100644 --- a/mbs_results/calculate_predicted_unit_value.py +++ b/mbs_results/calculate_predicted_unit_value.py @@ -28,7 +28,7 @@ def calculate_predicted_unit_value( A pandas DataFrame with a new column containing the predicted unit value. """ - winsorised = (df[sampled] == 1) & (not df[nw_ag_flag] is True) + winsorised = (df[sampled] == 1) & (df[nw_ag_flag] == False) # noqa: E712 filtered_df = df.loc[winsorised] sum_weighted_target_values = ( @@ -40,7 +40,7 @@ def calculate_predicted_unit_value( lambda x: x * (sum_weighted_target_values / sum_weighted_auxiliary_values) ) - non_winsorised = (df[sampled] == 0) | (df[nw_ag_flag] is True) + non_winsorised = (df[sampled] == 0) | (df[nw_ag_flag] == True) # noqa: E712 df["predicted_unit_value"] = df["predicted_unit_value"].mask(non_winsorised, np.nan) return df diff --git a/mbs_results/calculate_ratio_estimation.py b/mbs_results/calculate_ratio_estimation.py index d0d6426e..4e564712 100755 --- a/mbs_results/calculate_ratio_estimation.py +++ b/mbs_results/calculate_ratio_estimation.py @@ -49,7 +49,7 @@ def calculate_ratio_estimation( ) df = df.drop("flag_calculation", axis=1) - non_winsorised = (df[sampled] == 0) | (df[nw_ag_flag] is True) + non_winsorised = (df[sampled] == 0) | (df[nw_ag_flag] == True) # noqa: E712 df["ratio_estimation_treshold"] = df["ratio_estimation_treshold"].mask( non_winsorised, np.nan ) diff --git a/mbs_results/calculate_winsorised_weight.py b/mbs_results/calculate_winsorised_weight.py index f3bebbec..34b96b35 100755 --- a/mbs_results/calculate_winsorised_weight.py +++ b/mbs_results/calculate_winsorised_weight.py @@ -67,7 +67,7 @@ def calculate_winsorised_weight( df = df.drop(["w", "new_target"], axis=1) - non_winsorised = (df[sampled] == 0) | (df[nw_ag_flag] is True) + non_winsorised = (df[sampled] == 0) | (df[nw_ag_flag] == True) # noqa: E712 df["outlier_weight"] = df["outlier_weight"].mask(non_winsorised, np.nan) df["new_target_variable"] = df["new_target_variable"].mask(non_winsorised, np.nan)