Skip to content

Commit

Permalink
Merge pull request #162 from PSLmodels/fix-warnings
Browse files Browse the repository at this point in the history
Avoid deprecation warnings in uprate_puf.py code
  • Loading branch information
martinholmer authored Aug 21, 2024
2 parents 54f825d + 2b01850 commit bcc6dea
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
env:
POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN: ${{ secrets.POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN}}
PSL_TAX_MICRODATA_RELEASE_AUTH_TOKEN: ${{ secrets.PSL_TAX_MICRODATA_RELEASE_AUTH_TOKEN}}
- name: Generate datasets
run: make flat-file
- name: Generate tmd files
run: make tmd_files
- name: Run tests
run: make test
- name: Test documentation builds
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
env:
POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN: ${{ secrets.POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN}}
PSL_TAX_MICRODATA_RELEASE_AUTH_TOKEN: ${{ secrets.PSL_TAX_MICRODATA_RELEASE_AUTH_TOKEN}}
- name: Generate datasets
run: make flat-file
- name: Generate tmd files
run: make tmd_files
- name: Run tests
run: make test
- name: Build documentation
Expand All @@ -44,4 +44,3 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
folder: docs/book/_build/html

57 changes: 48 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,66 @@
.PHONY=clean
clean:
rm -f tax_microdata_benchmarking/storage/output/*

.PHONY=install
install:
pip install -e .
python tax_microdata_benchmarking/download_prerequisites.py

test:
pytest . -v

format:
black . -l 79

flat-file:
tax_microdata_benchmarking/storage/output/tmd.csv.gz: \
tax_microdata_benchmarking/imputation_assumptions.py \
tax_microdata_benchmarking/datasets/tmd.py \
tax_microdata_benchmarking/datasets/puf.py \
tax_microdata_benchmarking/datasets/cps.py \
tax_microdata_benchmarking/datasets/taxcalc_dataset.py \
tax_microdata_benchmarking/utils/taxcalc_utils.py \
tax_microdata_benchmarking/utils/imputation.py \
tax_microdata_benchmarking/utils/is_tax_filer.py \
tax_microdata_benchmarking/utils/pension_contributions.py \
tax_microdata_benchmarking/utils/soi_replication.py \
tax_microdata_benchmarking/utils/soi_targets.py \
tax_microdata_benchmarking/utils/reweight.py \
tax_microdata_benchmarking/utils/trace.py \
tax_microdata_benchmarking/create_taxcalc_input_variables.py
python tax_microdata_benchmarking/create_taxcalc_input_variables.py

tax_microdata_benchmarking/storage/output/tmd_growfactors.csv: \
tax_microdata_benchmarking/storage/input/puf_growfactors.csv \
tax_microdata_benchmarking/create_taxcalc_growth_factors.py
python tax_microdata_benchmarking/create_taxcalc_growth_factors.py

tax_microdata_benchmarking/storage/output/tmd_weights.csv.gz: \
tax_microdata_benchmarking/storage/input/cbo_population_forecast.yaml \
tax_microdata_benchmarking/storage/output/tmd.csv.gz \
tax_microdata_benchmarking/create_taxcalc_sampling_weights.py
python tax_microdata_benchmarking/create_taxcalc_sampling_weights.py

data: install flat-file test
.PHONY=tmd_files
tmd_files: tax_microdata_benchmarking/storage/output/tmd.csv.gz \
tax_microdata_benchmarking/storage/output/tmd_growfactors.csv \
tax_microdata_benchmarking/storage/output/tmd_weights.csv.gz

.PHONY=test
test: tmd_files
pytest . -v

.PHONY=data
data: install tmd_files test

.PHONY=format
format:
black . -l 79

.PHONY=documentation
documentation:
jb build docs/book

.PHONY=reweighting-visualisation
reweighting-visualisation:
tensorboard --logdir=tax_microdata_benchmarking/storage/output/reweighting

tax-expenditures-report: flat-file
.PHONY=tax-expenditures-report
tax-expenditures-report: tmd_files
-pytest . --disable-warnings -m taxexp
diff tax_microdata_benchmarking/storage/output/tax_expenditures \
tax_microdata_benchmarking/examination/tax_expenditures
4 changes: 2 additions & 2 deletions tax_microdata_benchmarking/datasets/uprate_puf.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ def uprate_puf(puf, from_year, to_year):
for variable in SOI_TO_PUF_POS_ONLY_RENAMES:
growth = get_growth(variable, from_year, to_year)
puf_variable = SOI_TO_PUF_POS_ONLY_RENAMES[variable]
puf[puf_variable][puf[puf_variable] > 0] *= growth
puf.loc[puf[puf_variable] > 0, puf_variable] *= growth

for variable in SOI_TO_PUF_NEG_ONLY_RENAMES:
growth = get_growth(variable, from_year, to_year)
puf_variable = SOI_TO_PUF_NEG_ONLY_RENAMES[variable]
puf[puf_variable][puf[puf_variable] < 0] *= growth
puf.loc[puf[puf_variable] < 0, puf_variable] *= growth

# Remaining variables, uprate purely by AGI growth
# (for now, because I'm not sure how to handle the deductions,
Expand Down
16 changes: 7 additions & 9 deletions tests/test_flat_file.py → tests/test_tmd_files.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
This module adds basic sanity tests for each TC-input flat file,
checking that the totals of each variable are within the ballpark
of the Tax-Data 2023 PUF's totals.
This module adds basic tests for several tmd file variables,
checking that the variable total is within the ballpark of
the Tax-Data 2023 PUF's totals.
"""

import os
Expand All @@ -21,9 +21,11 @@
get_tax_expenditure_results,
)

warnings.filterwarnings("ignore")

test_mode = os.environ.get("TEST_MODE", "lite")
# include this test only to gather warnings information
def test_create_taxcalc_tmd_file():
create_variable_file(write_file=False)


FOLDER = Path(__file__).parent

Expand Down Expand Up @@ -159,10 +161,6 @@ def test_tax_expenditure_estimates(
)


def test_create_taxcalc_tmd_file():
create_variable_file(write_file=False)


@pytest.mark.parametrize(
"flat_file", datasets_to_test, ids=dataset_names_to_test
)
Expand Down

0 comments on commit bcc6dea

Please sign in to comment.