From 643caf2205a90a1cb9d7d5b49158835b6d963801 Mon Sep 17 00:00:00 2001 From: nmdefries <42820733+nmdefries@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:08:53 -0500 Subject: [PATCH 1/3] warn and skip instead of failing when group uses multiple demos --- src/acquisition/flusurv/api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/acquisition/flusurv/api.py b/src/acquisition/flusurv/api.py index dd602766a..f358a63b1 100644 --- a/src/acquisition/flusurv/api.py +++ b/src/acquisition/flusurv/api.py @@ -323,7 +323,16 @@ def _group_by_epiweek(self, data): def _groupid_to_name(self, ageid, sexid, raceid, fluid): if ((ageid, sexid, raceid, fluid).count(0) < 3): - raise ValueError("Expect at least three of four group ids to be 0") + warn( + "We expect an obs to represent only a single demographic group at" + + "a time. This obs represents multiple, with demographic IDs " + + f"ageid {ageid}, sexid {sexid}, raceid {raceid}, fluid {fluid}." + + "Skip it." + ) + # This obs will be added to the processed data, but won't be + # inserted into the DB, since the column name is not in + # constants.EXPECTED_GROUPS. + group = "_".join((str(ageid), str(sexid), str(raceid), str(fluid))) if (ageid, sexid, raceid, fluid).count(0) == 4: group = "overall" # In all cases, if id is not available as a key in the dict, use the From 9b4562547679487c77c8883e7e6dd4dc09814521 Mon Sep 17 00:00:00 2001 From: nmdefries <42820733+nmdefries@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:50:23 -0500 Subject: [PATCH 2/3] switch test to warn --- tests/acquisition/flusurv/test_flusurv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acquisition/flusurv/test_flusurv.py b/tests/acquisition/flusurv/test_flusurv.py index 18eb1aa33..c9c4a75fd 100644 --- a/tests/acquisition/flusurv/test_flusurv.py +++ b/tests/acquisition/flusurv/test_flusurv.py @@ -379,7 +379,7 @@ def test_groupids_to_name(self): with self.assertRaisesRegex(ValueError, "Ageid cannot be 6"): api_fetcher._groupid_to_name(6, 0, 0, 0) - with self.assertRaisesRegex(ValueError, "Expect at least three of four group ids to be 0"): + with self.assertWarnsRegex(Warning, "We expect an obs to represent only a single demographic group at a time"): api_fetcher._groupid_to_name(1, 1, 0, 0) api_fetcher._groupid_to_name(0, 1, 1, 0) api_fetcher._groupid_to_name(1, 1, 1, 1) From 57140bbe5b172ff145a960cab3aacc86d2135365 Mon Sep 17 00:00:00 2001 From: nmdefries <42820733+nmdefries@users.noreply.github.com> Date: Mon, 8 Dec 2025 20:10:28 -0500 Subject: [PATCH 3/3] trailing spaces in warning --- src/acquisition/flusurv/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/acquisition/flusurv/api.py b/src/acquisition/flusurv/api.py index f358a63b1..735800eb6 100644 --- a/src/acquisition/flusurv/api.py +++ b/src/acquisition/flusurv/api.py @@ -324,9 +324,9 @@ def _group_by_epiweek(self, data): def _groupid_to_name(self, ageid, sexid, raceid, fluid): if ((ageid, sexid, raceid, fluid).count(0) < 3): warn( - "We expect an obs to represent only a single demographic group at" + + "We expect an obs to represent only a single demographic group at " + "a time. This obs represents multiple, with demographic IDs " + - f"ageid {ageid}, sexid {sexid}, raceid {raceid}, fluid {fluid}." + + f"ageid {ageid}, sexid {sexid}, raceid {raceid}, fluid {fluid}. " + "Skip it." ) # This obs will be added to the processed data, but won't be