From 7c963fd6b0d826c79c24ab531e785673bbeb881e Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 15 Aug 2024 11:00:14 +0100 Subject: [PATCH 1/8] Lower employment income by 10% --- policyengine_us_data/datasets/cps/policyengine_cps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/policyengine_us_data/datasets/cps/policyengine_cps.py b/policyengine_us_data/datasets/cps/policyengine_cps.py index 7c76973..2dee521 100644 --- a/policyengine_us_data/datasets/cps/policyengine_cps.py +++ b/policyengine_us_data/datasets/cps/policyengine_cps.py @@ -204,7 +204,7 @@ def add_personal_income_variables( assert isinstance(p, dict) # Assign CPS variables. - cps["employment_income"] = person.WSAL_VAL + cps["employment_income"] = person.WSAL_VAL * 0.9 cps["weekly_hours_worked"] = person.HRSWK * person.WKSWORK / 52 From 15c82ab9106c13f14aabe52aa6705369c9bc4985 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 15 Aug 2024 11:05:56 +0100 Subject: [PATCH 2/8] Try adding PR comment --- .github/review_pull_request.py | 5 ++++- .github/upload_evaluation.py | 1 - policyengine_us_data/utils/github.py | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/review_pull_request.py b/.github/review_pull_request.py index a646b40..c460716 100644 --- a/.github/review_pull_request.py +++ b/.github/review_pull_request.py @@ -1,6 +1,6 @@ import pandas as pd from policyengine_us_data.data_storage import STORAGE_FOLDER -from IPython.display import Markdown +from policyengine_us_data.utils.github import set_pr_auto_review_comment def main(): df = pd.read_csv(STORAGE_FOLDER / "evaluation.csv") @@ -11,11 +11,14 @@ def main(): diff = (most_recent_rows - second_most_recent_rows) # Convert to df diff = diff.reset_index() + diff = diff[diff.Variable == "household_net_income"] table = diff.to_markdown(index=False) review_text = f"""## National projection changes\n\n{table}""" print(review_text) + set_pr_auto_review_comment(review_text) + if __name__ == "__main__": main() \ No newline at end of file diff --git a/.github/upload_evaluation.py b/.github/upload_evaluation.py index 851ff65..bac7ca9 100644 --- a/.github/upload_evaluation.py +++ b/.github/upload_evaluation.py @@ -3,7 +3,6 @@ from policyengine_us_data.data_storage import STORAGE_FOLDER if __name__ == "__main__": - main() upload( "policyengine", "policyengine-us-data", diff --git a/policyengine_us_data/utils/github.py b/policyengine_us_data/utils/github.py index 380b4ef..487f4a5 100644 --- a/policyengine_us_data/utils/github.py +++ b/policyengine_us_data/utils/github.py @@ -79,3 +79,24 @@ def upload( ) return response.json() + +def set_pr_auto_review_comment(text: str): + # On a pull request, set a review comment with the given text. + + pr_number = os.environ["GITHUB_PR_NUMBER"] + + url = f"https://api.github.com/repos/{os.environ['GITHUB_REPOSITORY']}/pulls/{pr_number}/reviews" + + response = requests.post( + url, + headers=auth_headers, + json={ + "body": text, + "event": "COMMENT", + }, + ) + + if response.status_code != 200: + raise ValueError( + f"Invalid response code {response.status_code} for url {url}. Received: {response.text}" + ) \ No newline at end of file From 34915e998f3446071e2259d38c1a6e3e09387dc0 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 15 Aug 2024 11:13:25 +0100 Subject: [PATCH 3/8] Add missing dep --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index ce419ad..7213c7f 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ "tqdm", "requests", "policyengine_us", + "tabulate", ], }, ) From 342071cc73ef452d544753353e26743cb6042bd5 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 15 Aug 2024 11:20:30 +0100 Subject: [PATCH 4/8] Try gh actions fix --- .github/review_pull_request.py | 4 ++-- .github/workflows/pull_request.yaml | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/review_pull_request.py b/.github/review_pull_request.py index c460716..c7f21cc 100644 --- a/.github/review_pull_request.py +++ b/.github/review_pull_request.py @@ -3,6 +3,8 @@ from policyengine_us_data.utils.github import set_pr_auto_review_comment def main(): + + set_pr_auto_review_comment("Testing!") df = pd.read_csv(STORAGE_FOLDER / "evaluation.csv") most_recent_rows = df[df.Date == df.Date.max()].sort_values(["Variable", "Time period"]).set_index(["Variable", "Time period"]).Total @@ -18,7 +20,5 @@ def main(): print(review_text) - set_pr_auto_review_comment(review_text) - if __name__ == "__main__": main() \ No newline at end of file diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index b6b910f..e64b08d 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -11,6 +11,7 @@ jobs: runs-on: ubuntu-latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_PR_NUMBER: ${{ github.event.number }} steps: - name: Checkout code @@ -22,11 +23,5 @@ jobs: - name: Install dependencies run: make install - - name: Run tests - run: make test - - - name: Run evaluation - run: make evaluate - - name: Add review comment run: python .github/review_pull_request.py \ No newline at end of file From e40ecc9bd8c12a4f5d606a45a5ef3a13e9ab942b Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 15 Aug 2024 11:22:25 +0100 Subject: [PATCH 5/8] Test that subsequent commits don't create a new comment --- .github/workflows/pull_request.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index e64b08d..35dfb52 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -12,7 +12,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_PR_NUMBER: ${{ github.event.number }} - steps: - name: Checkout code uses: actions/checkout@v2 From e728f5b1e78f6ceb5bd68fd55419670d4dea3128 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 15 Aug 2024 11:25:18 +0100 Subject: [PATCH 6/8] Re-add evaluation --- .github/review_pull_request.py | 8 ++++---- .github/workflows/pull_request.yaml | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/review_pull_request.py b/.github/review_pull_request.py index c7f21cc..448f13a 100644 --- a/.github/review_pull_request.py +++ b/.github/review_pull_request.py @@ -3,8 +3,6 @@ from policyengine_us_data.utils.github import set_pr_auto_review_comment def main(): - - set_pr_auto_review_comment("Testing!") df = pd.read_csv(STORAGE_FOLDER / "evaluation.csv") most_recent_rows = df[df.Date == df.Date.max()].sort_values(["Variable", "Time period"]).set_index(["Variable", "Time period"]).Total @@ -13,12 +11,14 @@ def main(): diff = (most_recent_rows - second_most_recent_rows) # Convert to df diff = diff.reset_index() - diff = diff[diff.Variable == "household_net_income"] + diff = diff[diff.Variable == "household_net_income"].T table = diff.to_markdown(index=False) - review_text = f"""## National projection changes\n\n{table}""" + review_text = f"""## National projection changes\n\nThis pull request makes the following changes to economic estimates.\n\n{table}""" print(review_text) + set_pr_auto_review_comment(review_text) + if __name__ == "__main__": main() \ No newline at end of file diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 35dfb52..1a822e5 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -12,6 +12,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_PR_NUMBER: ${{ github.event.number }} + steps: - name: Checkout code uses: actions/checkout@v2 @@ -22,5 +23,11 @@ jobs: - name: Install dependencies run: make install + - name: Run tests + run: make test + + - name: Run evaluation + run: make evaluate + - name: Add review comment run: python .github/review_pull_request.py \ No newline at end of file From 54b5518e4c1cf451811aa2699dc17ffbd2451f17 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 15 Aug 2024 11:35:32 +0100 Subject: [PATCH 7/8] Change review format --- .github/review_pull_request.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/review_pull_request.py b/.github/review_pull_request.py index 448f13a..7c2c176 100644 --- a/.github/review_pull_request.py +++ b/.github/review_pull_request.py @@ -11,14 +11,15 @@ def main(): diff = (most_recent_rows - second_most_recent_rows) # Convert to df diff = diff.reset_index() - diff = diff[diff.Variable == "household_net_income"].T + diff.Total = diff.Total.apply(lambda x: f"{x:+.1f}") + diff = diff[diff.Variable == "household_net_income"].set_index("Time period")[["Total"]].T table = diff.to_markdown(index=False) - review_text = f"""## National projection changes\n\nThis pull request makes the following changes to economic estimates.\n\n{table}""" + review_text = f"""## National projection changes\n\nThis pull request makes the following changes to economic estimates.\n\n### Household net income\n\n{table}""" print(review_text) - set_pr_auto_review_comment(review_text) + #set_pr_auto_review_comment(review_text) if __name__ == "__main__": main() \ No newline at end of file From 9cb547a21262e2bf37e30b0699acf4490daabe0c Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 15 Aug 2024 11:43:48 +0100 Subject: [PATCH 8/8] Re-add comment action --- .github/review_pull_request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/review_pull_request.py b/.github/review_pull_request.py index 7c2c176..1d85e78 100644 --- a/.github/review_pull_request.py +++ b/.github/review_pull_request.py @@ -19,7 +19,7 @@ def main(): print(review_text) - #set_pr_auto_review_comment(review_text) + set_pr_auto_review_comment(review_text) if __name__ == "__main__": main() \ No newline at end of file