WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit c9820e2

Browse files
authored
Warn and skip instead of failing when group represents the intersection of multiple demographic groups (#1696)
* warn and skip instead of failing when group uses multiple demos * switch test to warn * trailing spaces in warning
1 parent 65f890b commit c9820e2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/acquisition/flusurv/api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,16 @@ def _group_by_epiweek(self, data):
323323

324324
def _groupid_to_name(self, ageid, sexid, raceid, fluid):
325325
if ((ageid, sexid, raceid, fluid).count(0) < 3):
326-
raise ValueError("Expect at least three of four group ids to be 0")
326+
warn(
327+
"We expect an obs to represent only a single demographic group at " +
328+
"a time. This obs represents multiple, with demographic IDs " +
329+
f"ageid {ageid}, sexid {sexid}, raceid {raceid}, fluid {fluid}. " +
330+
"Skip it."
331+
)
332+
# This obs will be added to the processed data, but won't be
333+
# inserted into the DB, since the column name is not in
334+
# constants.EXPECTED_GROUPS.
335+
group = "_".join((str(ageid), str(sexid), str(raceid), str(fluid)))
327336
if (ageid, sexid, raceid, fluid).count(0) == 4:
328337
group = "overall"
329338
# In all cases, if id is not available as a key in the dict, use the

tests/acquisition/flusurv/test_flusurv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def test_groupids_to_name(self):
379379

380380
with self.assertRaisesRegex(ValueError, "Ageid cannot be 6"):
381381
api_fetcher._groupid_to_name(6, 0, 0, 0)
382-
with self.assertRaisesRegex(ValueError, "Expect at least three of four group ids to be 0"):
382+
with self.assertWarnsRegex(Warning, "We expect an obs to represent only a single demographic group at a time"):
383383
api_fetcher._groupid_to_name(1, 1, 0, 0)
384384
api_fetcher._groupid_to_name(0, 1, 1, 0)
385385
api_fetcher._groupid_to_name(1, 1, 1, 1)

0 commit comments

Comments
 (0)