Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid value error in weekly_hours_worked file by using np.divide #5505

Merged
merged 10 commits into from
Jan 27, 2025
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: patch
changes:
fixed:
- Invalid value encountered when dividing income_effect by original_earnings in weekly hours worked calculation
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,21 @@ def formula(person, period, parameters):
original_emp = person("employment_income_before_lsr", period)
original_self_emp = person("self_employment_income_before_lsr", period)
original_earnings = original_emp + original_self_emp
lsr_relative_change = np.where(
original_earnings == 0, 0, income_effect / original_earnings

lsr_relative_change = np.divide(
income_effect,
original_earnings,
out=np.zeros_like(
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid awkward line breaks.

Suggested change
out=np.zeros_like(
# Assign no LSR change to people with no original earnings to avoid dividing by zero.
out=np.zeros_like(income_effect, dtype=np.float32),
where=original_earnings != 0,

Copy link
Contributor

Choose a reason for hiding this comment

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

Try make format and please add the comment I suggested

income_effect, dtype=np.float32
), # Default to 0 where division isn't valid
where=original_earnings
!= 0, # Perform division only where original_earnings != 0
)

return original * lsr_relative_change


class weekly_hours_worked_behavioural_response_substitution_elasticity(
Variable
):
class weekly_hours_worked_behavioural_response_substitution_elasticity(Variable):
value_type = float
entity = Person
label = "behavioural response in weekly hours worked (substitution effect)"
Expand Down
Loading