Skip to content

Commit

Permalink
Generalize tmd_constructor for Records and Policy
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Dec 9, 2024
1 parent c620c34 commit 2e912ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 8 additions & 7 deletions taxcalc/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class instance: Policy
'DependentCredit_before_CTC': 'is a removed parameter name',
'FilerCredit_c': 'is a removed parameter name',
'ALD_InvInc_ec_base_RyanBrady': 'is a removed parameter name',
# TODO: following parameter renamed in PR 2292 merged on 2019-04-15
# following parameter renamed in PR 2292 merged on 2019-04-15
"cpi_offset": (
"was renamed parameter_indexing_CPI_offset. "
"See documentation for change in usage."
Expand All @@ -62,7 +62,7 @@ class instance: Policy
"was renamed parameter_indexing_CPI_offset. "
"See documentation for change in usage."
),
# TODO: following parameters renamed in PR 2345 merged on 2019-06-24
# following parameters renamed in PR 2345 merged on 2019-06-24
'PT_excl_rt':
'was renamed PT_qbid_rt in release 2.4.0',
'PT_excl_wagelim_thd':
Expand Down Expand Up @@ -102,17 +102,18 @@ def __init__(self, gfactors=None, **kwargs):
Policy.WAGE_INDEXED_PARAMS, **kwargs)

@staticmethod
def tmd_constructor(growfactors_path): # pragma: no cover
def tmd_constructor(growfactors: Path | GrowFactors): # pragma: no cover
"""
Static method returns a Policy object instantiated with TMD
input data. This convenience method works in a analogous way
to Policy(), which returns a Policy object instantiated with
non-TMD input data.
"""
assert isinstance(growfactors_path, Path)
gf_filename = str(growfactors_path)
tmd_growfactors = GrowFactors(growfactors_filename=gf_filename)
return Policy(gfactors=tmd_growfactors)
if isinstance(growfactors, Path):
growfactors = GrowFactors(growfactors_filename=str(growfactors))
else:
assert isinstance(growfactors, GrowFactors)
return Policy(gfactors=growfactors)

@staticmethod
def read_json_reform(obj):
Expand Down
9 changes: 6 additions & 3 deletions taxcalc/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def cps_constructor(data=None,
def tmd_constructor(
data_path: Path,
weights_path: Path,
growfactors_path: Path,
growfactors: Path | GrowFactors,
exact_calculations=False,
): # pragma: no cover
"""
Expand All @@ -250,12 +250,15 @@ def tmd_constructor(
"""
assert isinstance(data_path, Path)
assert isinstance(weights_path, Path)
assert isinstance(growfactors_path, Path)
if isinstance(growfactors, Path):
growfactors = GrowFactors(growfactors_filename=str(growfactors))
else:
assert isinstance(growfactors, GrowFactors)
return Records(
data=pd.read_csv(data_path),
start_year=Records.TMDCSV_YEAR,
weights=pd.read_csv(weights_path),
gfactors=GrowFactors(growfactors_filename=str(growfactors_path)),
gfactors=growfactors,
adjust_ratios=None,
exact_calculations=exact_calculations,
weights_scale=1.0,
Expand Down

0 comments on commit 2e912ac

Please sign in to comment.