From 8957201382550b3c7960b295d421b9f62a31c9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Caron?= Date: Mon, 9 Dec 2024 08:49:18 +0100 Subject: [PATCH] Update usage from os.path to pathlib.Path (cont'd) --- qpbenchmark/benchmark.py | 12 ++++++------ qpbenchmark/parquet_test_set.py | 2 +- qpbenchmark/results.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/qpbenchmark/benchmark.py b/qpbenchmark/benchmark.py index f163f3c..5fc9cc7 100644 --- a/qpbenchmark/benchmark.py +++ b/qpbenchmark/benchmark.py @@ -26,7 +26,7 @@ def parse_command_line_arguments( - test_set_path: Optional[Union[str, Path]] = None, + test_set_path: Optional[Union[Path, str]] = None, ) -> argparse.Namespace: """Extracts and interprets command line arguments passed to the script. @@ -196,7 +196,7 @@ def load_test_set(path: str) -> TestSet: return TestClass() -def report(args, results: Results, test_set_path: str): +def report(args, results: Results, test_set_path: Union[Path, str]): """Write report to file. Args: @@ -213,15 +213,15 @@ def report(args, results: Results, test_set_path: str): report = Report(author, results) if results.csv_path is None: raise BenchmarkError("not sure where to save report: no results file") - results_dir = os.path.dirname(results.csv_path) - test_set_name = os.path.basename(test_set_path).replace(".py", "") + results_dir = results.csv_path.parent + test_set_name = Path(test_set_path).name.replace(".py", "") md_path = f"{results_dir}/{test_set_name}.md" report.write(md_path) def main( - test_set_path: Optional[Union[str, Path]] = None, - results_path: Optional[Union[str, Path]] = None, + test_set_path: Optional[Union[Path, str]] = None, + results_path: Optional[Union[Path, str]] = None, ): """Main function of the script. diff --git a/qpbenchmark/parquet_test_set.py b/qpbenchmark/parquet_test_set.py index 3ee3bfa..99f7fcd 100644 --- a/qpbenchmark/parquet_test_set.py +++ b/qpbenchmark/parquet_test_set.py @@ -20,7 +20,7 @@ class ParquetTestSet(TestSet): """Test set read from a Parquet file.""" - def __init__(self, path: Union[str, Path]): + def __init__(self, path: Union[Path, str]): """Initialize test set. Args: diff --git a/qpbenchmark/results.py b/qpbenchmark/results.py index a9190d3..bc0c066 100644 --- a/qpbenchmark/results.py +++ b/qpbenchmark/results.py @@ -44,7 +44,7 @@ def check_df(df) -> None: raise ResultsError('"found" column has some non-boolean values') def __init__( - self, csv_path: Optional[Union[str, Path]], test_set: TestSet + self, csv_path: Optional[Union[Path, str]], test_set: TestSet ): """Initialize results. @@ -96,7 +96,7 @@ def nb_rows(self) -> int: """Number of rows in the dataframe.""" return self.df.shape[0] - def write(self, path: Optional[Union[str, Path]] = None) -> None: + def write(self, path: Optional[Union[Path, str]] = None) -> None: """Write results to their CSV file for persistence. Args: