Skip to content

Commit

Permalink
Corrected error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjeevLakhwani committed Nov 1, 2024
1 parent ebcb8de commit 5793eec
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions transcriptomics_data_service/routers/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,10 @@ def _load_csv(file_bytes: bytes) -> pd.DataFrame:
if df.columns.duplicated().any():
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Duplicate Sample IDs detected.")

# Ensuring raw count values are integers, otherwise flagging an error
try:
df = df.applymap(lambda x: int(x) if pd.notna(x) else None)
except ValueError as e:
# HTTPException is terminal, it cannot get caught by any other try/catch block
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=f"Invalid non-integer value found: {e}")

# Ensuring raw count values are integers
df = df.applymap(lambda x: int(x) if pd.notna(x) else None)
return df

except pd.errors.ParserError as e:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=f"Error parsing CSV: {e}")
except ValueError as e:
Expand Down

0 comments on commit 5793eec

Please sign in to comment.