From 800a5aca49c2e96b477c1873ad93e4ef3fd6913d Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Thu, 10 Oct 2024 10:47:44 +0200 Subject: [PATCH] Renamed open_file() --> load_file_obj() and close_file() --> unload_file_obj() to focus more on the management operations on the files that actual file handling operations. --- src/hdf5_ops.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hdf5_ops.py b/src/hdf5_ops.py index 7172fd4..50c0fb3 100644 --- a/src/hdf5_ops.py +++ b/src/hdf5_ops.py @@ -44,11 +44,11 @@ class HDF5DataOpsManager(): # Define public methods - def open_file(self): + def load_file_obj(self): if self.file_obj is None: self.file_obj = h5py.File(self.file_path, self.mode) - def close_file(self): + def unload_file_obj(self): if self.file_obj: self.file_obj.flush() # Ensure all data is written to disk self.file_obj.close() @@ -76,7 +76,7 @@ class HDF5DataOpsManager(): returns a copy of the dataset content in the form of dataframe when possible or numpy array """ if self.file_obj is None: - self.open_file() + self.load_file_obj() dataset_obj = self.file_obj[dataset_name] # Read dataset content from dataset obj @@ -148,7 +148,7 @@ class HDF5DataOpsManager(): obj.attrs.update(annotation_dict_copy) except Exception as e: - self.close_file() + self.unload_file_obj() print(f"An unexpected error occurred: {e}. The file object has been properly closed.") @@ -204,7 +204,7 @@ class HDF5DataOpsManager(): obj.attrs.update(update_dict) except Exception as e: - self.close_file() + self.unload_file_obj() print(f"An unexpected error occurred: {e}. The file object has been properly closed.") def delete_metadata(self, obj_name, annotation_dict): @@ -247,7 +247,7 @@ class HDF5DataOpsManager(): print(msg) except Exception as e: - self.close_file() + self.unload_file_obj() print(f"An unexpected error occurred: {e}. The file object has been properly closed.") @@ -293,13 +293,13 @@ class HDF5DataOpsManager(): msg = f"Skipping: Attribute '{old_attr}' does not exist." print(msg) # Optionally, replace with warnings.warn(msg) except Exception as e: - self.close_file() + self.unload_file_obj() print( f"An unexpected error occurred: {e}. The file object has been properly closed. " "Please ensure that 'obj_name' exists in the file, and that the keys in 'renaming_map' are valid attributes of the object." ) - self.close_file() + self.unload_file_obj() def get_metadata(self, obj_path): """ Get file attributes from object at path = obj_path. For example, @@ -392,7 +392,7 @@ class HDF5DataOpsManager(): # Close the file if it's already open if self.file_obj is not None: - self.close_file() + self.unload_file_obj() # Attempt to open the file in 'r+' mode for appending try: