Skip to content

Suggested fix for ImpfSetTropCyclone.get_countries_per_region() #1105#1106

Merged
spjuhel merged 7 commits into
developfrom
feature/fix-1105-get_countries_per_region
Apr 10, 2026
Merged

Suggested fix for ImpfSetTropCyclone.get_countries_per_region() #1105#1106
spjuhel merged 7 commits into
developfrom
feature/fix-1105-get_countries_per_region

Conversation

@spjuhel

@spjuhel spjuhel commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator

Changes proposed in this PR:

  • Updates the method to correctly return expected values when providing no argument for region, or None or "all".
  • Updates the code for Kosovo in the CountryCode enum to XKO to avoid LookupError.

This PR fixes #1105

PR Author Checklist

PR Reviewer Checklist

@peanutfun peanutfun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix! Please add a test for region="all".

Comment thread climada/entity/impact_funcs/trop_cyclone.py Outdated
spjuhel and others added 2 commits December 19, 2025 09:46
Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>

@peanutfun peanutfun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding the test, but it basically doubles the contents of the CountryCode enum, which I think is error-prone. I like the idea of comparing two results of the get_countries_per_region(), though. How about you compare the partial contents of out to get_countries_per_region(reg) for each reg?

out_all = get_countries_per_region("all")
for reg in (...):
    out_reg = get_countries_per_region(reg)
    self.assertDictEqual(out[0][reg], out_all[0])
    # ...and so on

@spjuhel

spjuhel commented Feb 19, 2026

Copy link
Copy Markdown
Collaborator Author

@peanutfun Does this corresponds to what you had in mind?

    def test_get_countries_per_region_all_or_none(self):
        ifs = ImpfSetTropCyclone()
        out = ifs.get_countries_per_region()
        out2 = ifs.get_countries_per_region("all")
        self.assertEqual(out, out2)
        for reg in CountryCode.REGION_NAME.value:
            out_reg = ifs.get_countries_per_region(reg)
            for i in range(4):
                self.assertEqual(out[i][reg], out_reg[i])

I've also added overloads.

@spjuhel

spjuhel commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator Author

Ready to merge?

@spjuhel spjuhel merged commit a3d0c12 into develop Apr 10, 2026
8 of 9 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.

ImpfSetTropCyclone.get_countries_per_region() doesn't work for region=None

2 participants