Skip to content

Commit a98fa33

Browse files
committed
Add guardrails to prevent type TypeError: can't multiply sequence by non-int of type 'float' see HEA-811
1 parent d006329 commit a98fa33

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

pipelines/assets/livelihood_activity.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,15 @@ def get_instances_from_dataframe(
846846
# worksheets
847847
column = df.columns[i + 1]
848848
household_size = df.iloc[3, i + 1]
849+
# Convert household_size to int
850+
try:
851+
if pd.notna(household_size) and household_size != "":
852+
# Convert to float first to handle "5.0" or "5.7", then to int
853+
household_size = int(float(household_size))
854+
else:
855+
household_size = None
856+
except (ValueError, TypeError):
857+
household_size = None
849858
livelihood_activity["kcals_consumed"] = (
850859
livelihood_activity["percentage_kcals"] * 2100 * 365 * household_size
851860
if livelihood_activity["percentage_kcals"] and household_size

0 commit comments

Comments
 (0)