Repository navigation
Monthly Conversion: Antiobiotic Data #2 - #94
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the antibiotic exposure model to use the newer antibiotic predictions dataset (grouped by timepoint + sex) and aligns the public API/tests with the renamed data accessor.
Changes:
- Renames the internal exposure dataset handle from
mid_trendstodataand updates copying logic accordingly. - Switches the data loader from
processed_data/.../midtrends.csvtoprocessed_data/.../antibiotic_predictions.csv(with the newn_abx_μcolumn). - Removes the old
midtrends.csvfiles and updates the constructor test to reference.data.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_antibiotic_exposure.py | Updates constructor test to use the renamed .data grouping accessor. |
| leap/processed_data/time_delta_365/midtrends.csv | Deletes the legacy midtrends dataset. |
| leap/processed_data/time_delta_30/midtrends.csv | Deletes the legacy midtrends dataset. |
| leap/antibiotic_exposure.py | Renames API surface from mid_trends to data and changes loader to antibiotic_predictions.csv / n_abx_μ. |
Suppressed comments (2)
leap/antibiotic_exposure.py:121
antibiotic_predictions.csvhassexvalues likeF/M(seeprocessed_data/time_delta_*/antibiotic_predictions.csv), but the API and tests treat sex as0/1. As loaded,df.groupby(["timepoint", "sex"])will be keyed by strings, soget_group((..., 0))and downstream code usingint(sex)won't match. Map the CSV sex values to0/1(and validate unexpected values) before grouping.
df = pd.read_csv(
get_data_path(f"processed_data/{time_delta_tag}/antibiotic_predictions.csv"),
parse_dates=["timepoint"]
)
grouped_df = df.groupby(["timepoint", "sex"])
leap/antibiotic_exposure.py:160
- In the
fixyearnon-numeric branch,self.datais grouped bytimepoint(a parsed datetime), but this usesbirth_year(an int) as the group key. This will raise aKeyErrorat runtime whenfixyearis set and not numeric. Convertbirth_yearto the samedt.datetime(birth_year, 1, 1)key used elsewhere.
μ = max(
self.data.get_group((birth_year, int(sex)))["n_abx_μ"].iloc[0],
self.parameters["βfloor"]
)
p = self.parameters["θ"] / (self.parameters["θ"] + μ)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| Each entry is a dataframe with a single row with the following columns: | ||
|
|
||
| * ``year (int)``: The calendar year, e.g. ``2024``. | ||
| * ``timepoint (dt.datetime)``: The date and time, e.g. ``2024``. |
KateJohnson
self-requested a review
September 1, 2026 20:10
KateJohnson
approved these changes
Sep 1, 2026
antibiotic_predictions.csv encodes sex as F/M strings, but code expected 0/1 ints from the old midtrends.csv, causing get_group() KeyErrors. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Description
This is a continuation of #82: Monthly Conversion: Antibiotic Exposure. PR #82 was closed by mistake, without update the
*.csvfiles. I reverted that PR in PR #93.This PR is thus everything from PR #82 , plus
midtrends.csvhas been renamed toantibiotic_predictions.csvand the the extra files deleted.Type of Change
Tests
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
Linked PRs / Issues
Original PR: #82
Revert: #93
Checklist: