Skip to content

Commit

Permalink
add errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisTrakos committed Apr 16, 2024
1 parent f1e0ec9 commit 8e20b25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,27 @@ def ids_mapping_patient_number(
data_name: str,
folder_path: str,
) -> str:
pattern = re.compile(r"^\d+$")
ids_mapping = {"123": "456"}
json_file = Path(folder_path) / ("id_mapping_" + data_name + ".json")
json_name = "id_mapping_" + data_name + ".json"
json_file = Path(folder_path) / (json_name)
if not Path(json_file).exists():
msg = f"In {folder_path} file {json_name} does not exists."
raise FileNotFoundError(msg)
with Path.open(json_file) as f:
json_data = json.load(f)
for key, value in json_data.items():
if not (isinstance(key, str) and pattern.match(key)):
msg = f"Key '{key}' is not a string containing only numbers."
raise ValueError(
msg,
)
if not (isinstance(value, str) and pattern.match(value)):
msg = f"Value '{value}' for key '{key}' is not a string containing only numbers." # noqa: E501
raise ValueError(
msg,
)

if (
patient_number == "nan"
or patient_number == ""
Expand Down Expand Up @@ -683,7 +700,9 @@ def xlsx_to_excel(self: Anonymizer, excel_sheets: dict[str, str]) -> None:
if xlsx_file.endswith(".xlsx"):
dataframe = pd.read_excel(Path(self.anon_folder) / xlsx_file)
dataframe.to_excel(
excel_writer, sheet_name=file_name, index=False,
excel_writer,
sheet_name=file_name,
index=False,
)
excel_writer._save() # noqa: SLF001

Expand Down
Binary file modified python/prm/samples/valab/data/Breast_Cancer_anonymized.xls
Binary file not shown.

0 comments on commit 8e20b25

Please sign in to comment.