diff --git a/src/pheval/post_processing/post_processing.py b/src/pheval/post_processing/post_processing.py index 4c10ddf3..609c9823 100644 --- a/src/pheval/post_processing/post_processing.py +++ b/src/pheval/post_processing/post_processing.py @@ -269,15 +269,15 @@ def _rank_with_grouping_id(self, pheval_result_df: pd.DataFrame) -> pd.DataFrame pheval_result_df["min_rank"] = ( pheval_result_df.groupby(["score", "grouping_id"]) .ngroup() - .rank(method="min", ascending=self.ascending) - ) + .rank(method="dense", ascending=self.ascending) + ).astype(int) pheval_result_df["rank"] = pheval_result_df.groupby("score")["min_rank"].transform("max") return pheval_result_df def _rank_without_grouping_id(self, pheval_result_df: pd.DataFrame) -> pd.DataFrame: """Apply ranking without using grouping_id.""" - pheval_result_df["rank"] = pheval_result_df["score"].rank( - method="max", ascending=self.ascending + pheval_result_df["rank"] = ( + pheval_result_df["score"].rank(method="max", ascending=self.ascending).astype(int) ) return pheval_result_df diff --git a/tests/test_post_processing.py b/tests/test_post_processing.py index 074f3104..f6cfbb74 100644 --- a/tests/test_post_processing.py +++ b/tests/test_post_processing.py @@ -329,8 +329,8 @@ def test__rank_with_grouping_id(self): { "score": [0.9, 0.9, 0.8, 0.7, 0.7, 0.6, 0.5, 0.5, 0.4], "grouping_id": ["A", "A", "B", "C", "D", "E", "F", "F", "G"], - "min_rank": [1.0, 1.0, 3.0, 5.0, 4.0, 6.0, 7.0, 7.0, 9.0], - "rank": [1.0, 1.0, 3.0, 5.0, 5.0, 6.0, 7.0, 7.0, 9.0], + "min_rank": [1, 1, 2, 4, 3, 5, 6, 6, 7], + "rank": [1, 1, 2, 4, 4, 5, 6, 6, 7], } ) ) @@ -347,7 +347,7 @@ def test__rank_without_grouping_id(self): pd.DataFrame( { "score": [0.9, 0.9, 0.8, 0.7, 0.7, 0.6, 0.5, 0.5, 0.4], - "rank": [2.0, 2.0, 3.0, 5.0, 5.0, 6.0, 8.0, 8.0, 9.0], + "rank": [2, 2, 3, 5, 5, 6, 8, 8, 9], } ) ) @@ -366,7 +366,7 @@ def test_rank_pheval_results_gene(self): "ENSG00000068985", ], "score": [0.9234, 0.6529, 0.6529, 0.5235], - "rank": [1.0, 3.0, 3.0, 4.0], + "rank": [1, 3, 3, 4], } ) ) @@ -383,7 +383,7 @@ def test_rank_pheval_results_variant(self): "ref": ["A", "A", "A", "T"], "alt": ["G", "C", "C", "G"], "score": [0.1245, 0.4578, 0.9999, 0.9999], - "rank": [1.0, 2.0, 4.0, 4.0], + "rank": [1, 2, 4, 4], } ) ) @@ -400,7 +400,7 @@ def test_rank_pheval_results_variant_grouping_id(self): "ref": ["A", "A", "A", "T"], "alt": ["G", "C", "C", "G"], "score": [0.1245, 0.4578, 0.9999, 0.9999], - "rank": [4.0, 3.0, 1.0, 1.0], + "rank": [3, 2, 1, 1], } ) ) @@ -422,7 +422,7 @@ def test_rank_pheval_results_disease(self): 2: "OMIM:614483", }, "score": {0: 4.284, 1: 4.284, 2: -1.871}, - "rank": {0: 2.0, 1: 2.0, 2: 3.0}, + "rank": {0: 2, 1: 2, 2: 3}, } ) ) @@ -443,7 +443,7 @@ def test_create_pheval_result_gene(self): "ENSG00000068985", ], "score": [0.9234, 0.6529, 0.6529, 0.5235], - "rank": [1.0, 3.0, 3.0, 4.0], + "rank": [1, 3, 3, 4], } ) ) @@ -460,7 +460,7 @@ def test_create_pheval_result_variant(self): "ref": ["A", "A", "A", "T"], "alt": ["G", "C", "C", "G"], "score": [0.1245, 0.4578, 0.9348, 0.9999], - "rank": [1.0, 2.0, 3.0, 4.0], + "rank": [1, 2, 3, 4], } ) ) @@ -482,7 +482,7 @@ def test_create_pheval_result_disease(self): 2: "OMIM:614483", }, "score": {0: 4.284, 1: 4.284, 2: -1.871}, - "rank": {0: 2.0, 1: 2.0, 2: 3.0}, + "rank": {0: 2, 1: 2, 2: 3}, } ) )