Skip to content

Commit be8857c

Browse files
authored
Merge pull request #220 from American-Institutes-for-Research/HEA-873/inherit_product_in_wealth_characteristics
Inherit product_id in wealth_characteristic_instances - see HEA-873
2 parents 082ede5 + 492e0a0 commit be8857c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

pipelines/assets/wealth_characteristic.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def wealth_characteristic_instances(
195195
"wealth_characteristic_id",
196196
"product_id",
197197
"unit_of_measure_id",
198+
"wealth_characteristic__has_product",
198199
)
199200
}
200201
context.log.info("Loaded %d Wealth Characteristic Labels", len(label_map))
@@ -239,6 +240,7 @@ def wealth_characteristic_instances(
239240

240241
# Iterate over the rows
241242
wealth_group_characteristic_values = []
243+
last_product_id = None
242244
for row in df.iloc[num_header_rows:].index: # Ignore the Wealth Group header rows
243245
label = prepared_labels[row]
244246
if not label:
@@ -249,6 +251,21 @@ def wealth_characteristic_instances(
249251
if not any(attributes.values()):
250252
# Ignore rows that don't contain any relevant data (or which aren't in the label_map)
251253
continue
254+
# Apply product inheritance
255+
if attributes.get("product_id"):
256+
last_product_id = attributes.get("product_id")
257+
elif attributes.get("wealth_characteristic__has_product"):
258+
if not last_product_id:
259+
raise ValueError(
260+
"Wealth Characteristic Label '%s' in row %s requires a product, but there is no previous product to inherit"
261+
% (label, row)
262+
)
263+
attributes["product_id"] = last_product_id
264+
else:
265+
# The current label doesn't need a product (and doesn't have one), so clear the last_product_id
266+
# so that it isn't inherited by subsequent labels.
267+
last_product_id = None
268+
252269
# Lookup the Wealth Group Category from Column B
253270
wealth_group_category = wealthgroupcategorylookup.get(df.loc[row, "B"])
254271
if not wealth_group_category:

0 commit comments

Comments
 (0)