Skip to content

Hea 688/ignore activities without wealth category#152

Merged
rhunwicks merged 3 commits into
mainfrom
HEA-688/ignore_activities_without_wealth_category
Sep 5, 2025
Merged

Hea 688/ignore activities without wealth category#152
rhunwicks merged 3 commits into
mainfrom
HEA-688/ignore_activities_without_wealth_category

Conversation

@rhunwicks

Copy link
Copy Markdown
Contributor

No description provided.

The Data, Data2 and Data3 worksheets that contain the Livelihood Actitivies
contain blank columns separating the Wealth Categories (VP, P, etc.).
Sometimes these blank columns contain data where a 0 value or a
formula has been copied across the row.

We can detect the separator column because it won't have a Wealth Category,
and then ignore any Livelihood Activities we find in it.
@rhunwicks rhunwicks self-assigned this Sep 4, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR filters out livelihood activities without a wealth category to prevent processing invalid data from blank columns in BSS (Baseline Survey Sheet). The changes ensure that only valid livelihood activities with proper wealth group categorization are processed.

  • Filter livelihood activities to require a wealth category component
  • Add assertion to prevent linting warnings about potential None values
  • Fix type annotations in lookup module for better type safety

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pipelines/assets/livelihood_activity.py Adds filtering logic to exclude activities without wealth category and includes assertion for linting
apps/common/lookups.py Updates type annotations and default values for better type safety

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

livelihood_activity
for livelihood_activity in livelihood_activities_for_strategy
if any(
if livelihood_activity["wealth_group"][2] # Make sure there is a Wealth Category

Copilot AI Sep 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a magic number (index 2) to access the wealth category makes the code unclear. Consider adding a named constant or accessing by key name to make the intention explicit.

Copilot uses AI. Check for mistakes.
Comment thread pipelines/assets/livelihood_activity.py Outdated
Comment on lines +439 to +442
# Assertion to prevent linting from complaining about possible None values
assert livelihood_strategy is not None, (
"Found Livelihood Activities from row %s, but there is no Livelihood Strategy defined." % row
)

Copilot AI Sep 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using assertions for runtime validation in production code is not recommended. Consider using a proper exception like ValueError or RuntimeError instead, as assertions can be disabled with -O flag.

Suggested change
# Assertion to prevent linting from complaining about possible None values
assert livelihood_strategy is not None, (
"Found Livelihood Activities from row %s, but there is no Livelihood Strategy defined." % row
)
# Raise an exception to prevent possible None values for livelihood_strategy
if livelihood_strategy is None:
raise ValueError(
"Found Livelihood Activities from row %s, but there is no Livelihood Strategy defined." % row
)

Copilot uses AI. Check for mistakes.
Comment thread pipelines/assets/livelihood_activity.py Outdated
]

# Assertion to prevent linting from complaining about possible None values
assert livelihood_strategy is not None, (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhunwicks, this line appears to block some previously processed rows. For example, I checked cell Data!A59, which has empty values across the entire row for the camel milk label. I reviewed the runs for livelihood_activity_instances asset locally for the BSSes: ML01/02 and NG05, where the labels are recorded as "Camels' milk" or "Lait de chamelle".

@rhunwicks rhunwicks merged commit 9838c45 into main Sep 5, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants