Skip to content

Commit

Permalink
test decoder/ encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
camillebrianceau committed Mar 19, 2024
1 parent 3a86778 commit d9bb413
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion clinicadl/utils/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,36 @@
def path_encoder(obj):
if isinstance(obj, Path):
return str(obj)
raise TypeError(f"Object of type {type(obj)} is not JSON serializable")
elif isinstance(obj, dict):
for key, value in obj.items():
if isinstance(value, dict):
for key2, value2 in value.items():
if (
key2.endswith("tsv")
or key2.endswith("dir")
or key2.endswith("directory")
or key2.endswith("path")
or key2.endswith("json")
or key2.endswith("location")
):
if value2 == False:
obj[value][key2] = ""
elif isinstance(value2, Path):
obj[value][key2] = value2.as_posix()
else:
if (
key.endswith("tsv")
or key.endswith("dir")
or key.endswith("directory")
or key.endswith("path")
or key.endswith("json")
or key.endswith("location")
):
if value == False:
obj[key] = ""
elif isinstance(value, Path):
obj[key] = value.as_posix()
return obj


def path_decoder(obj):
Expand Down

0 comments on commit d9bb413

Please sign in to comment.