Skip to content

Commit

Permalink
Add capability to handle tmd.csv input file
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Apr 18, 2024
1 parent 19ef5c9 commit 6dc7b7a
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ endef
.PHONY=pytest-cps
pytest-cps:
@$(pytest-setup)
@cd taxcalc ; pytest -n4 --disable-warnings -m "not requires_pufcsv and not pre_release"
@cd taxcalc ; pytest -n4 --disable-warnings -m "not requires_pufcsv and not requires_tmdcsv and not pre_release"
@$(pytest-cleanup)

.PHONY=pytest
pytest:
@$(pytest-setup)
@cd taxcalc ; pytest -n4 -m "not pre_release"
@cd taxcalc ; pytest -n4 --disable-warnings -m "not pre_release"
@$(pytest-cleanup)

.PHONY=pytest-all
pytest-all:
@$(pytest-setup)
@cd taxcalc ; pytest -n4 -m ""
@cd taxcalc ; pytest -n4 --disable-warnings -m ""
@$(pytest-cleanup)

define tctest-cleanup
Expand Down Expand Up @@ -103,7 +103,7 @@ define coverage-cleanup
rm -f .coverage htmlcov/*
endef

COVMARK = "not requires_pufcsv and not pre_release"
COVMARK = "not requires_pufcsv and not requires_tmdcsv and not pre_release"

OS := $(shell uname -s)

Expand Down
6 changes: 5 additions & 1 deletion taxcalc/cli/tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ def cli_tc_main():
sys.stderr.write(tcio.errmsg)
sys.stderr.write('USAGE: tc --help\n')
return 1
aging = inputfn.endswith('puf.csv') or inputfn.endswith('cps.csv')
aging = (
inputfn.endswith('puf.csv') or
inputfn.endswith('cps.csv') or
inputfn.endswith('tmd.csv')
)
tcio.init(input_data=inputfn, tax_year=taxyear,
baseline=args.baseline,
reform=args.reform, assump=args.assump,
Expand Down
36 changes: 35 additions & 1 deletion taxcalc/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ class instance: Records
doing when attempting this.
Use Records.cps_constructor() to get a Records object instantiated
with CPS input data.
with CPS input data developed in the taxdata repository.
Use Records.tmd_constructor() to get a Records object instantiated
with TMD input data developed in the tax-microdata repository.
"""
# suppress pylint warning about constructor having too many arguments:
# pylint: disable=too-many-arguments
Expand All @@ -107,11 +110,14 @@ class instance: Records

PUFCSV_YEAR = 2011
CPSCSV_YEAR = 2014
TMDCSV_YEAR = 2021

PUF_WEIGHTS_FILENAME = 'puf_weights.csv.gz'
PUF_RATIOS_FILENAME = 'puf_ratios.csv'
CPS_WEIGHTS_FILENAME = 'cps_weights.csv.gz'
CPS_RATIOS_FILENAME = None
TMD_WEIGHTS_FILENAME = 'tmd_weights.csv.gz'
TMD_RATIOS_FILENAME = None
CODE_PATH = os.path.abspath(os.path.dirname(__file__))
VARINFO_FILE_NAME = 'records_variables.json'
VARINFO_FILE_PATH = CODE_PATH
Expand Down Expand Up @@ -218,6 +224,34 @@ def cps_constructor(data=None,
adjust_ratios=Records.CPS_RATIOS_FILENAME,
exact_calculations=exact_calculations)

@staticmethod
def tmd_constructor(data=None,
gfactors=GrowFactors(),
exact_calculations=False):
"""
Static method returns a Records object instantiated with TMD
input data. This works in a analogous way to Records(), which
returns a Records object instantiated with PUF input data.
This is a convenience method that eliminates the need to
specify all the details of the TMD input data just as the
default values of the arguments of the Records class constructor
eliminate the need to specify all the details of the PUF input
data.
"""
if data is None:
data = os.path.join(Records.CODE_PATH, 'tmd.csv.gz')
if gfactors is None:
weights = None

Check warning on line 244 in taxcalc/records.py

View check run for this annotation

Codecov / codecov/patch

taxcalc/records.py#L241-L244

Added lines #L241 - L244 were not covered by tests
else:
weights = os.path.join(Records.CODE_PATH,

Check warning on line 246 in taxcalc/records.py

View check run for this annotation

Codecov / codecov/patch

taxcalc/records.py#L246

Added line #L246 was not covered by tests
Records.TMD_WEIGHTS_FILENAME)
return Records(data=data,

Check warning on line 248 in taxcalc/records.py

View check run for this annotation

Codecov / codecov/patch

taxcalc/records.py#L248

Added line #L248 was not covered by tests
start_year=Records.TMDCSV_YEAR,
gfactors=gfactors,
weights=weights,
adjust_ratios=Records.TMD_RATIOS_FILENAME,
exact_calculations=exact_calculations)

def increment_year(self):
"""
Add one to current year, and also does
Expand Down
13 changes: 12 additions & 1 deletion taxcalc/taxcalcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, input_data, tax_year, baseline, reform, assump,
inp = 'x'
self.puf_input_data = False
self.cps_input_data = False
self.tmd_input_data = False
if isinstance(input_data, str):
# remove any leading directory path from INPUT filename
fname = os.path.basename(input_data)
Expand All @@ -85,6 +86,7 @@ def __init__(self, input_data, tax_year, baseline, reform, assump,
# check existence of INPUT file
self.puf_input_data = input_data.endswith('puf.csv')
self.cps_input_data = input_data.endswith('cps.csv')
self.tmd_input_data = input_data.endswith('tmd.csv')
if not self.cps_input_data and not os.path.isfile(input_data):
msg = 'INPUT file could not be found'
self.errmsg += 'ERROR: {}\n'.format(msg)
Expand Down Expand Up @@ -320,7 +322,16 @@ def init(self, input_data, tax_year, baseline, reform, assump,
gfactors=gfactors_base,
exact_calculations=exact_calculations
)
else: # if not cps_input_data but aging_input_data
elif self.tmd_input_data:
recs = Records.tmd_constructor(

Check warning on line 326 in taxcalc/taxcalcio.py

View check run for this annotation

Codecov / codecov/patch

taxcalc/taxcalcio.py#L326

Added line #L326 was not covered by tests
gfactors=gfactors_ref,
exact_calculations=exact_calculations
)
recs_base = Records.tmd_constructor(

Check warning on line 330 in taxcalc/taxcalcio.py

View check run for this annotation

Codecov / codecov/patch

taxcalc/taxcalcio.py#L330

Added line #L330 was not covered by tests
gfactors=gfactors_base,
exact_calculations=exact_calculations
)
else: # if not {cps|tmd}_input_data but aging_input_data
recs = Records(
data=input_data,
gfactors=gfactors_ref,
Expand Down

0 comments on commit 6dc7b7a

Please sign in to comment.