Skip to content

Commit

Permalink
Merge pull request #236 from CDCgov/patch-ick4
Browse files Browse the repository at this point in the history
Patch to correct populate_fields() because that code got lost during …
  • Loading branch information
RamiyapriyaS authored Dec 18, 2024
2 parents c604963 + c4e5a5c commit 7c7357a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bin/validate_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,19 @@ def populate_fields(self):
replaced_df = self.df.replace(to_replace={term: ["", None] for term in existing_terms}, value=field_value_mapping)
final_df = replaced_df.fillna("")
# Remove any N/A or na or N/a or n/A
unwanted_vals = ['N/A', 'N/a', 'na', 'n/A', 'NA']
unwanted_vals = ['N/A', 'NA']
for col in existing_terms:
final_df[col] = final_df[col].apply(
lambda x: "Not Provided" if str(x) in unwanted_vals else x
lambda x: "Not Provided" if str(x).strip().upper() in map(str.upper, unwanted_vals) else x
)
# Validate populated fields
try:
# Ensure no null values in specified columns
assert not any(final_df[field].isnull().any() for field in existing_terms)
# Ensure all values are either empty or "Not Provided"
for field in existing_terms:
final_df[field] = final_df[field].apply(
lambda x: "Not Provided" if str(x).strip().lower() == "not provided" else x)
assert all(value == "" or value == "Not Provided" for value in final_df[field].values)
except AssertionError:
raise AssertionError(
Expand Down

0 comments on commit 7c7357a

Please sign in to comment.