Skip to content

Commit 89829a2

Browse files
authored
Merge pull request #67 from ImageMarkup/isic-167-strip-metadata-strings
Strip metadata strings before processing
2 parents fafd54b + 53652fc commit 89829a2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

isic_cli/cli/metadata.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def validate(csv_file: io.BufferedReader):
4242
df = pd.read_csv(csv_file, header=0)
4343

4444
# pydantic expects None for the absence of a value, not NaN
45-
df = df.replace({np.nan: None})
45+
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)
46+
df = df.replace({np.nan: None, "": None})
4647

4748
# batch problems apply to the overall csv and can't be computed without looking at the
4849
# entire csv.
@@ -53,7 +54,8 @@ def validate(csv_file: io.BufferedReader):
5354

5455
for i, (_, row) in track(enumerate(df.iterrows(), start=2), total=len(df)):
5556
try:
56-
MetadataRow.model_validate(row.to_dict())
57+
row = row.to_dict()
58+
MetadataRow.model_validate({k: v for k, v in row.items() if v is not None})
5759
except ValidationError as e:
5860
for error in e.errors():
5961
column = error["loc"][0]

0 commit comments

Comments
 (0)