From 0ec573ceda0cb944053134f92c86f275d0b13a39 Mon Sep 17 00:00:00 2001 From: Al Johri Date: Wed, 25 Mar 2026 09:16:32 -0400 Subject: [PATCH 1/2] Fix Python 3.12+ SyntaxWarning and pandas 3.0 compatibility - Fix invalid escape sequences in LaTeX strings in report.py - Use pd.api.types.is_string_dtype() instead of dtype == "O" checks in qrels.py and run.py for pandas 3.0 StringDtype compatibility --- ranx/data_structures/qrels.py | 12 ++++++------ ranx/data_structures/report.py | 10 +++++----- ranx/data_structures/run.py | 12 ++++++------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ranx/data_structures/qrels.py b/ranx/data_structures/qrels.py index f0d24bf..4996283 100644 --- a/ranx/data_structures/qrels.py +++ b/ranx/data_structures/qrels.py @@ -291,12 +291,12 @@ def from_df( Returns: Qrels: ranx.Qrels """ - assert ( - df[q_id_col].dtype == "O" - ), "DataFrame Query IDs column dtype must be `object` (string)" - assert ( - df[doc_id_col].dtype == "O" - ), "DataFrame Document IDs column dtype must be `object` (string)" + assert pd.api.types.is_string_dtype( + df[q_id_col] + ), "DataFrame Query IDs column dtype must be string" + assert pd.api.types.is_string_dtype( + df[doc_id_col] + ), "DataFrame Document IDs column dtype must be string" assert ( df[score_col].dtype == np.int64 ), "DataFrame scores column dtype must be `int`" diff --git a/ranx/data_structures/report.py b/ranx/data_structures/report.py index bfb2a92..cd02aee 100644 --- a/ranx/data_structures/report.py +++ b/ranx/data_structures/report.py @@ -199,21 +199,21 @@ def to_latex(self) -> str: table_prefix = ( "% To change the table size, act on the resizebox argument `0.8`.\n" - + """\\begin{table*}[ht]\n\centering\n\caption{\nOverall effectiveness of the models.\nThe best results are highlighted in boldface.\nSuperscripts denote significant differences in """ + + "\\begin{table*}[ht]\n\\centering\n\\caption{\nOverall effectiveness of the models.\nThe best results are highlighted in boldface.\nSuperscripts denote significant differences in " + self.get_stat_test_label(self.stat_test) - + """ with $p \le """ + + " with $p \\le " + str(self.max_p) + "$.\n}\n\\resizebox{0.8\\textwidth}{!}{" + "\n\\begin{tabular}{c|l" + "|c" * len(self.metrics) + "}" + "\n\\toprule" - + "\n\\textbf{\#}" + + "\n\\textbf{\\#}" + "\n& \\textbf{Model}" + "".join( [f"\n& \\textbf{{{self.get_metric_label(m)}}}" for m in self.metrics] ) - + " \\\\ \n\midrule" + + " \\\\ \n\\midrule" ) table_content = [] @@ -243,7 +243,7 @@ def to_latex(self) -> str: ) table_suffix = ( - "\\bottomrule\n\end{tabular}\n}\n\label{tab:results}\n\end{table*}" + "\\bottomrule\n\\end{tabular}\n}\n\\label{tab:results}\n\\end{table*}" ) return ( diff --git a/ranx/data_structures/run.py b/ranx/data_structures/run.py index 6df514d..92047de 100644 --- a/ranx/data_structures/run.py +++ b/ranx/data_structures/run.py @@ -310,12 +310,12 @@ def from_df( Returns: Run: ranx.Run """ - assert ( - df[q_id_col].dtype == "O" - ), "DataFrame Query IDs column dtype must be `object` (string)" - assert ( - df[doc_id_col].dtype == "O" - ), "DataFrame Document IDs column dtype must be `object` (string)" + assert pd.api.types.is_string_dtype( + df[q_id_col] + ), "DataFrame Query IDs column dtype must be string" + assert pd.api.types.is_string_dtype( + df[doc_id_col] + ), "DataFrame Document IDs column dtype must be string" assert ( df[score_col].dtype == np.float64 ), "DataFrame scores column dtype must be `float`" From f83fe20b3cc405ab033c90e0850fb322f260f4f6 Mon Sep 17 00:00:00 2001 From: Al Johri Date: Fri, 27 Mar 2026 11:40:58 -0400 Subject: [PATCH 2/2] Add ttest to typos ignore list The typos spell checker flags scipy's ttest_rel as a misspelling. --- _typos.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/_typos.toml b/_typos.toml index 62e669f..98f6b37 100644 --- a/_typos.toml +++ b/_typos.toml @@ -3,4 +3,5 @@ extend-ignore-identifiers-re = [ ".*Hsi", "relevants", "Comput", + "ttest.*", ]