From a27b5c3f41dad6efc5991ababc6af33959334f22 Mon Sep 17 00:00:00 2001 From: Andrea Baraldi Date: Mon, 9 Oct 2023 22:45:19 +0200 Subject: [PATCH 1/2] Update data_preproc_functions.py to solve conversion to float issue Solving issue 497 when converting values to float due to deprecation of float function in numpy. https://github.com/Trusted-AI/AIF360/issues/497#issue-1923826267 Using pandas built in functions to optimize time. Proof: timeit.timeit("df['age'].apply(lambda x: float(x >= 26))", number=10, setup="import pandas as pd;df = pd.DataFrame({'age':range(1000000)})") >>> 2.8678155599627644 timeit.timeit("(df['age'] >= 26).astype(float)", number=10, setup="import pandas as pd;df = pd.DataFrame({'age':range(1000000)})") >>> 0.01317960600135848 ((df['age'] >= 26).astype(float) == df['age'].apply(lambda x: float(x >= 26))).all() >>> True Signed-off-by: Andrea Baraldi --- .../optim_preproc_helpers/data_preproc_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aif360/algorithms/preprocessing/optim_preproc_helpers/data_preproc_functions.py b/aif360/algorithms/preprocessing/optim_preproc_helpers/data_preproc_functions.py index 11e0b296..5b646fc8 100644 --- a/aif360/algorithms/preprocessing/optim_preproc_helpers/data_preproc_functions.py +++ b/aif360/algorithms/preprocessing/optim_preproc_helpers/data_preproc_functions.py @@ -265,7 +265,7 @@ def group_status(x): df['credit_history'] = df['credit_history'].apply(lambda x: group_credit_hist(x)) df['savings'] = df['savings'].apply(lambda x: group_savings(x)) df['employment'] = df['employment'].apply(lambda x: group_employ(x)) - df['age'] = df['age'].apply(lambda x: np.float(x >= 26)) + df['age'] = ((df['age'] >= 26).astype(float) df['status'] = df['status'].apply(lambda x: group_status(x)) return df From e3a90b8fa7c47c3c987f262b35ab063edd78e812 Mon Sep 17 00:00:00 2001 From: Samuel Hoffman Date: Wed, 11 Oct 2023 11:36:48 -0400 Subject: [PATCH 2/2] Remove extra parenthesis Signed-off-by: Samuel Hoffman --- .../optim_preproc_helpers/data_preproc_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aif360/algorithms/preprocessing/optim_preproc_helpers/data_preproc_functions.py b/aif360/algorithms/preprocessing/optim_preproc_helpers/data_preproc_functions.py index 5b646fc8..708ca135 100644 --- a/aif360/algorithms/preprocessing/optim_preproc_helpers/data_preproc_functions.py +++ b/aif360/algorithms/preprocessing/optim_preproc_helpers/data_preproc_functions.py @@ -265,7 +265,7 @@ def group_status(x): df['credit_history'] = df['credit_history'].apply(lambda x: group_credit_hist(x)) df['savings'] = df['savings'].apply(lambda x: group_savings(x)) df['employment'] = df['employment'].apply(lambda x: group_employ(x)) - df['age'] = ((df['age'] >= 26).astype(float) + df['age'] = (df['age'] >= 26).astype(float) df['status'] = df['status'].apply(lambda x: group_status(x)) return df