Skip to content

Commit

Permalink
Merge pull request #2834 from martinholmer/policy-tmd-ctor
Browse files Browse the repository at this point in the history
Add Policy.tmd_constructor static method
  • Loading branch information
martinholmer authored Nov 8, 2024
2 parents 22b99e4 + ed04183 commit cc43319
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion taxcalc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
from taxcalc.utils import *
from taxcalc.cli import *

__version__ = '4.3.1a'
__version__ = '4.3.1b'
__min_python3_version__ = 10
__max_python3_version__ = 12
19 changes: 16 additions & 3 deletions taxcalc/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os
import json
from pathlib import Path
import numpy as np
from taxcalc.parameters import Parameters
from taxcalc.growfactors import GrowFactors
Expand Down Expand Up @@ -80,7 +81,7 @@ class instance: Policy
# (3) specify which Policy parameters are wage (rather than price) indexed
WAGE_INDEXED_PARAMS = ['SS_Earnings_c', 'SS_Earnings_thd']

def __init__(self, gfactors=None, only_reading_defaults=False, **kwargs):
def __init__(self, gfactors=None, **kwargs):
# put JSON contents of DEFAULTS_FILE_NAME into self._vals dictionary
super().__init__()
# handle gfactors argument
Expand All @@ -92,7 +93,6 @@ def __init__(self, gfactors=None, only_reading_defaults=False, **kwargs):
raise ValueError('gfactors is not None or a GrowFactors instance')
# read default parameters and initialize
syr = Policy.JSON_START_YEAR
lyr = Policy.LAST_BUDGET_YEAR
nyrs = Policy.DEFAULT_NUM_YEARS
self._inflation_rates = None
self._wage_growth_rates = None
Expand All @@ -101,6 +101,19 @@ def __init__(self, gfactors=None, only_reading_defaults=False, **kwargs):
Policy.REDEFINED_PARAMS,
Policy.WAGE_INDEXED_PARAMS, **kwargs)

@staticmethod
def tmd_constructor(growfactors_path): # 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)

@staticmethod
def read_json_reform(obj):
"""
Expand Down Expand Up @@ -129,7 +142,7 @@ def parameter_list():
Policy.DEFAULTS_FILE_PATH,
Policy.DEFAULTS_FILE_NAME
)
with open(path) as f:
with open(path, 'r', encoding='utf-8') as f:
defaults = json.loads(f.read()) # pylint: disable=protected-access
return [k for k in defaults if k != "schema"]

Expand Down

0 comments on commit cc43319

Please sign in to comment.