Use np.isin for country check in winter_fuel_allowance (#257)#1650
Merged
Use np.isin for country check in winter_fuel_allowance (#257)#1650
Conversation
One of the last OR-chained equality checks in the codebase. All 6 baseline winter-fuel YAML tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
MaxGhenis
approved these changes
May 1, 2026
Collaborator
MaxGhenis
left a comment
There was a problem hiding this comment.
Reviewed: the country predicate is equivalent to the prior England/Wales OR check and follows existing np usage. CI is green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace
(country == "ENGLAND") | (country == "WALES")inpolicyengine_uk/variables/gov/dwp/winter_fuel_allowance.pywithnp.isin(country, ["ENGLAND", "WALES"]), per the cleanup asked for in #257.This is one of only two OR-chained equality patterns still in the repo — the other is
(band == bands.HIGHER) | (band == bands.ADDITIONAL)inreforms/cps/marriage_tax_reforms.py, which I left alone:np.isindoes not work on rawEnumArray(verified empirically — it returns all-False). Making that one work withnp.isinwould require first calling.decode_to_str()and comparing against string names, which is less idiomatic than the current enum comparison, so that cleanup is arguably not an improvement.Closes #257 — leaves the codebase free of genuine OR-chained equality cases where
np.isinis a clearer alternative.Test plan
policyengine_uk/tests/policy/baseline/gov/dwp/winter_fuel_allowance.yamlpass.🤖 Generated with Claude Code