From 1e8776a8b2dbcd74b5f43ceeffe91a44d2d0e399 Mon Sep 17 00:00:00 2001
From: Michael Boniface <m.j.boniface@soton.ac.uk>
Date: Thu, 20 Feb 2025 10:37:49 +0000
Subject: [PATCH] added exceptions in phen

---
 acmc/phen.py | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/acmc/phen.py b/acmc/phen.py
index 25ab3d4..c232421 100644
--- a/acmc/phen.py
+++ b/acmc/phen.py
@@ -404,10 +404,6 @@ def translate_codes(df, target_code_type):
 				# merge on corresponding codes and take target column
 				translated = pd.merge(col, df_map, how="left")[target_code_type]  
 				# TODO: BUG mask does not match column
-				# log_invalid_code(col,
-				# 				 ~translated.isna(),
-				# 				 code_type=col_name,
-				# 				 cause=f"Translation to {target}") #log codes with no translation
 				codes = pd.concat([codes, translated])  # merge to output
 			else:
 				logger.warning(f"No mapping from {col_name} to {target_code_type}, file {str(map_path.resolve())} does not exist")
@@ -419,10 +415,12 @@ def map_file(df, target_code_type, out, concepts, meta_columns=[]):
 	# seperate out meta_columns
 	metadata_df = df[meta_columns]
 	df = df.drop(columns=meta_columns)
+
+	# translate codes
 	codes = translate_codes(df, target_code_type)
 	codes = codes.dropna()  # delete NaNs
 	
-	# Append to out df
+	# Append to output if translated 
 	if len(codes) > 0:
 		codes = pd.DataFrame({"CONCEPT": codes})
 		codes = codes.join(metadata_df)
@@ -509,10 +507,14 @@ def map(phen_dir, target_code_type):
 										   out,
 										   concepts=file["concept_set_categories"][cat],
 										   meta_columns=meta_columns,)
+				else:
+					raise AttributeError(f"File {file} has either no concept_set or conceot_set_categories or the instance of dataframe objectives associated is incorrect, concept_set must be a DataFrame, conceot_set_categories must be pd.core.groupby.generic.DataFrameGroupBy")
+			else:
+				logger.warning(f"File {file} has no output after preprocessing in config {str(config_path.resolve())}")
 
 	# Check there is output from processing
 	if len(out.index) == 0:
-		raise Exception(f"No output after map processing, check configuration {str(config_path.resolve())}")
+		raise Exception(f"No output after map processing, check config {str(config_path.resolve())}")
 
 	# Final processing
 	out = out.reset_index(drop=True)
-- 
GitLab