From 02896c465ffe53decfb38a141ae881118b4a3ade Mon Sep 17 00:00:00 2001 From: "tiffany.cheng" Date: Thu, 18 Jun 2026 13:45:18 +0100 Subject: [PATCH 1/2] Add: decompress csv function in utils.py --- mario/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mario/utils.py b/mario/utils.py index 6d43f6f..d5ab141 100644 --- a/mario/utils.py +++ b/mario/utils.py @@ -29,3 +29,13 @@ def gzip_file(input_path, output_path=None): with open(input_path, "rb") as f_in, gzip.open(output_path, "wb") as f_out: shutil.copyfileobj(f_in, f_out) return output_path + + +def decompress_gzip_file(input_path, output_path=None): + import gzip + import shutil + if output_path is None: + output_path = input_path.removesuffix(".gz") + with gzip.open(input_path, "rb") as f_in, open(output_path, "wb") as f_out: + shutil.copyfileobj(f_in, f_out) + return output_path \ No newline at end of file From e2f138494b37f7c76f310bf018835aae466bffe9 Mon Sep 17 00:00:00 2001 From: "tiffany.cheng" Date: Fri, 19 Jun 2026 15:05:13 +0100 Subject: [PATCH 2/2] Add: some checking code according to code review --- mario/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mario/utils.py b/mario/utils.py index d5ab141..4dc529c 100644 --- a/mario/utils.py +++ b/mario/utils.py @@ -1,5 +1,7 @@ import os from datetime import datetime +import logging +logger = logging.getLogger(__name__) def append_current_date_to_file_name(file_name: str) -> str: @@ -33,9 +35,23 @@ def gzip_file(input_path, output_path=None): def decompress_gzip_file(input_path, output_path=None): import gzip + import os import shutil + if not input_path.endswith(".gz"): + raise ValueError(f"Input path must end with '.gz': {input_path}") + if output_path is None: output_path = input_path.removesuffix(".gz") + + # Create output directory if not exists + output_dir = os.path.dirname(output_path) + if output_dir: + os.makedirs(output_dir, exist_ok=True) + + if os.path.exists(output_path): + logger.warning(f"Output file already exists and will be overwritten: {output_path}") + with gzip.open(input_path, "rb") as f_in, open(output_path, "wb") as f_out: shutil.copyfileobj(f_in, f_out) + return output_path \ No newline at end of file