From 4f91fb91a638f9c431bb4808cece1792c7d869e7 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Thu, 12 Dec 2024 18:17:17 -0500 Subject: [PATCH] Check if downloaded file is empty (#385) * Check if downloaded file is empty * pathlib --- pycytominer/cyto_utils/cell_locations.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pycytominer/cyto_utils/cell_locations.py b/pycytominer/cyto_utils/cell_locations.py index 5c4edeb7..9906317c 100644 --- a/pycytominer/cyto_utils/cell_locations.py +++ b/pycytominer/cyto_utils/cell_locations.py @@ -177,7 +177,14 @@ def _download_s3(self, uri: str): self.s3.download_file(bucket, key, tmp_file.name) - return tmp_file.name + # Check if the downloaded file exists and has a size greater than 0 + tmp_file_path = pathlib.Path(tmp_file.name) + if tmp_file_path.exists() and tmp_file_path.stat().st_size > 0: + return tmp_file.name + else: + raise ValueError( + f"Downloaded file '{tmp_file.name}' is empty or does not exist." + ) def _load_metadata(self): """Load the metadata into a Pandas DataFrame