Skip to content

Commit

Permalink
🐛 convert percentages to numbers in fast-track
Browse files Browse the repository at this point in the history
  • Loading branch information
Marigold committed Oct 7, 2024
1 parent 2db77c8 commit fed8712
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion apps/wizard/app_pages/fasttrack/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ def processing_part_1(import_method, dataset_uris, infer_metadata, is_private, _
else:
raise ValueError(f"Unknown import method: {import_method}")

# PROCES
# PROCESS
if infer_metadata:
st.write("Inferring metadata...")
data, variables_meta_dict = _infer_metadata(data, variables_meta_dict)

data = _convert_percentages(data, variables_meta_dict)

# VALIDATION
st.write("Validating data and metadata...")
success = _validate_data(data, variables_meta_dict)
Expand Down Expand Up @@ -145,6 +147,14 @@ def processing_part_2(data, dataset_meta, variables_meta_dict, origin, dataset_u
return fast_import


def _convert_percentages(data: pd.DataFrame, variables_meta_dict: Dict[str, VariableMeta]) -> pd.DataFrame:
"""Convert percentages to numbers."""
for col in data.columns:
if getattr(variables_meta_dict.get(col, {}), "unit", "") == "%":
data[col] = data[col].str.replace("%", "").astype(float)
return data


def _validate_data(df: pd.DataFrame, variables_meta_dict: Dict[str, VariableMeta]) -> bool:
errors = []

Expand Down

0 comments on commit fed8712

Please sign in to comment.