From c65d3418b866c1b73bdc8f73e6b363e042f9391e Mon Sep 17 00:00:00 2001 From: JGarciaCondado Date: Tue, 28 Nov 2023 11:18:56 +0100 Subject: [PATCH] [STYLE] Lint formatting of lifestyle factors --- src/ageml/ui.py | 7 +++---- src/ageml/utils.py | 2 ++ src/ageml/visualizer.py | 2 +- tests/test_ageml/test_processing.py | 1 + tests/test_ageml/test_ui.py | 2 ++ tests/test_ageml/test_visualizer.py | 2 ++ 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/ageml/ui.py b/src/ageml/ui.py index 45351ea..80ac344 100644 --- a/src/ageml/ui.py +++ b/src/ageml/ui.py @@ -21,7 +21,7 @@ import ageml.messages as messages from ageml.visualizer import Visualizer -from ageml.utils import * +from ageml.utils import create_directory, feature_extractor, significant_markers, convert, log from ageml.modelling import AgeML from ageml.processing import find_correlations @@ -259,9 +259,8 @@ def load_data(self, required=None): non_shared_subjects = [s for s in dfs[i].index.to_list() if s not in dfs[j].index.to_list()] if non_shared_subjects.__len__() != 0: - warn_message = ( - "Subjects in dataframe %s not in dataframe %s: %s" % (labels[i], labels[j], non_shared_subjects) - ) + warn_message = ("Subjects in dataframe %s not in dataframe %s: %s" + % (labels[i], labels[j], non_shared_subjects)) print(warn_message) warnings.warn(warn_message, category=UserWarning) self.subjects_missing_data = ( diff --git a/src/ageml/utils.py b/src/ageml/utils.py index 98b5422..907fc8b 100644 --- a/src/ageml/utils.py +++ b/src/ageml/utils.py @@ -49,6 +49,7 @@ def feature_extractor(df): return X, y, feature_names + def significant_markers(bon, fdr): """Returns markers for significant features. @@ -67,6 +68,7 @@ def significant_markers(bon, fdr): markers.append("") return markers + def log(func): """Decorator function to log stdout to log.txt.""" diff --git a/src/ageml/visualizer.py b/src/ageml/visualizer.py index e096b18..924ca76 100644 --- a/src/ageml/visualizer.py +++ b/src/ageml/visualizer.py @@ -221,4 +221,4 @@ def deltas_by_groups(self, deltas, labels): plt.xlabel("Gruop") plt.ylabel("Delta") plt.savefig(os.path.join(self.path_for_fig, "clinical_groups_box_plot.svg")) - plt.close() \ No newline at end of file + plt.close() diff --git a/tests/test_ageml/test_processing.py b/tests/test_ageml/test_processing.py index a439aa9..f691fe8 100644 --- a/tests/test_ageml/test_processing.py +++ b/tests/test_ageml/test_processing.py @@ -16,6 +16,7 @@ def test_find_correlations(): assert np.array_equal(order, order_expected) is True assert np.allclose(p_values, p_values_expected, atol=1e-7) is True + @pytest.mark.parametrize('X, Y, exception_msg', [ (np.array([[2, 4, np.nan], [4, 8, -12], [6, 12, -18], [8, 16, -24]]), np.array([1, 2, 3, 4]), "NaN entrie(s) found in X."), (np.array([[2, 4, -6], [4, 8, -12], [6, 12, -18], [8, 16, -24]]), np.array([1, 2, 3, np.nan]), "NaN entrie(s) found in Y.") diff --git a/tests/test_ageml/test_ui.py b/tests/test_ageml/test_ui.py index 0a8d5c3..ad7127e 100644 --- a/tests/test_ageml/test_ui.py +++ b/tests/test_ageml/test_ui.py @@ -349,6 +349,7 @@ def test_run_age(dummy_interface, features): ] ) + def test_run_lifestyle(dummy_interface, ages, factors): # Run the lifestyle pipeline ages_path = create_csv(ages, dummy_interface.dir_path) @@ -371,6 +372,7 @@ def test_run_lifestyle(dummy_interface, ages, factors): log_path = os.path.join(dummy_interface.dir_path, "log.txt") assert os.path.exists(log_path) + def test_run_clinical(dummy_interface, ages, clinical): # Run the clinical pipeline ages_path = create_csv(ages, dummy_interface.dir_path) diff --git a/tests/test_ageml/test_visualizer.py b/tests/test_ageml/test_visualizer.py index 967a9e3..2e296d6 100644 --- a/tests/test_ageml/test_visualizer.py +++ b/tests/test_ageml/test_visualizer.py @@ -90,6 +90,7 @@ def test_age_bias_correction(dummy_viz, np_test_data, dummy_ml): # Cleanup shutil.rmtree(os.path.dirname(svg_path)) + def test_factors_vs_deltas(dummy_viz): # Create dummy data corrs = [[0.5, 0.6, 0.7, 0.8, 0.9]] @@ -104,6 +105,7 @@ def test_factors_vs_deltas(dummy_viz): # Cleanup shutil.rmtree(os.path.dirname(svg_path)) + def test_deltas_by_groups(dummy_viz, np_test_data, dummy_ml): # Separate data in X and Y X = np_test_data[:, :3]