Commit 2e8773e2 authored by Nic's avatar Nic
Browse files

[units][validation] make code more robust

parent 1ff3dbfd
......@@ -424,27 +424,12 @@ class DataFrameSchematizer:
if self._is_units:
# at this point, we still have df_num and df_nonnum
for col, units in self._target_units.copy().items():
df_num[col] = df_num[col]
except KeyError:
# no units specified in source file"
# maybe a string where a number is expected...
# let's investigate it for a better user feedback
df[col] = pd.Series(
dtype="pint[ ]",
self._target_units[col] = "" # .pop(col)
self._source_units[col] = "" # .pop(col)
early_report[(col, None)].append("unable to convert this column")
df_num = df_num.pint.dequantify()
df = pd.concat((df_num, df_nonnum), axis=1)
# reorder columns as initially
df.columns = [t[0] for t in df.columns.tolist()] # restrict to level 0
if col not in df_num.columns:
df_num[col] = df_num[col]
df = pd.concat((df_num.pint.dequantify(), df_nonnum), axis=1)
# re-arrange columns: restrict to level 0 and reorder as initially
df.columns = [t[0] for t in df.columns.tolist()]
df = df[[c for c in initial_without_urow.columns]]
# =====================================================================
# fill empty values as requested by schema
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment