-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ParamTools #2401
Use ParamTools #2401
Conversation
…'s a Policy parameter - Updates test_decorators.py for change in Policy parameter value dimensionality
…oved/renamed parameters
The test errors look like pycodestyle errors. I'll push some fixes soon. |
I just pushed a whole bunch of codestyle fixes. I've been spoiled by my use of tools that format code for me. One thing that might be helpful for TC is to add a pre-commit hook that runs the pycodestyle command when you create a git commit (for example). If the code style test fails, then it won't let you make the commit. |
@MattHJensen asked yesterday on the TC community call for a TODO list for reviewers:
My TODO list is:
@MattHJensen @Peter-Metz Let me know if I'm missing anything here. |
Codecov Report
@@ Coverage Diff @@
## master #2401 +/- ##
=======================================
Coverage 99.92% 99.92%
=======================================
Files 13 13
Lines 2530 2530
=======================================
Hits 2528 2528
Misses 2 2 Continue to review full report at Codecov.
|
@hdoupe the only other thing i can think of is fixing the user guide. Let me know if I can help with any of these tasks. |
Do you have time to look at the user guide? I modified the |
@hdoupe Yep, I'll take a look tomorrow. |
I installed TC from this branch and successfully ran all tests of the latest version of Cost of Capital Calculator with it. @rickecon or I will try with OG-USA soon. |
Thanks @jdebacker! This is much appreciated! |
- Adds back expand_array tests - Use to_array labels argument in '_{attr}' logic - Move initialize logic to __init__ method but keep initialize for legacy purposes
These tasks are complete. @MattHJensen @Peter-Metz let me know how things look. Here's the script I used to fix the key order: import json
if __name__ == "__main__":
to_convert = [
"taxcalc/policy_current_law.json",
"taxcalc/growdiff.json",
"taxcalc/consumption.json",
]
keys = [
"title",
"description",
"notes",
"section_1",
"section_2",
"section_3",
"start_year",
"indexable",
"indexed",
"type",
"value",
"validators",
"compatible_data",
]
for path in to_convert:
print('converting', path)
with open(path, "r") as f:
defaults = json.loads(f.read())
sorted_defaults = {}
if "schema" in defaults:
sorted_defaults["schema"] = defaults["schema"]
for param, data in defaults.items():
if param == "schema":
continue
assert not (data.keys() - set(keys)), f"{param} has extra keys: {data.keys()}"
sorted_defaults[param] = {}
for key in keys:
if key in data:
sorted_defaults[param][key] = data[key]
with open(path, "w") as f:
f.write(json.dumps(sorted_defaults, indent=4)) |
Reformat user guide
@hdoupe I ran through OG-USA with TC built from this branch after commit |
Glad to hear it @jdebacker. Thanks again for testing out these changes. |
@Peter-Metz @MattHJensen #2401 is ready for another round of review. I think we should be pretty close to getting this merged. @Peter-Metz are you still good with re-working the handling of the |
@hdoupe @MattHJensen changes look good to me and Hank - yeah, I have the |
@Peter-Metz sounds great. I'm excited to see your |
@hdoupe, thanks very much for this PR and for so generously accommodating Peter and my requests through the review process. I am merging this PR now and expect it to appear in a new release within the month. |
@Peter-Metz, thanks for all of your help with the review! |
It was my pleasure. @MattHJensen and @Peter-Metz thanks for the thorough review! |
This PR shows how ParamTools could be used to handle Tax-Calculator's parameters. I used a script to convert the configuration files from the Tax-Calculator format to the ParamTools format, but besides this difference, there are only a couple public-facing API changes:
Theinflation_rates()
andgrowth_rates()
methods now return dictionaries where the keys are years and the values are the rates. It was easier for me to work with this format since most operations require you to get a value for a certain year at a time. This can easily be reverted.The parameter values that are accessible as instance attributes (e.g.
pol.II_em
) are not casted down into a lower dimension. So, if the year is 2017, thenpol.II_em
returns[4050.0]
instead of4050.0
. ParamTools does this to keep the results consistent for when you havepol.set_year(2017)
orpol.set_year([2017, 2018])
. TheCalculator.policy_param
method automatically casts the value into a lower dimension to preserve compatibility:There may be some other API changes that I have missed. I'll be going over the code to make sure that I have not missed anything else. If anyone is interested, I'd really appreciate them running their downstream projects or notebooks with the changes in this branch to make sure I haven't broken anything.
There are few notable places where I maintained consistency:
The
_update
method still takes reforms that are in the Tax-Calculator format. The reforms are reformatted and passed to the ParamToolsadjust
method. All classes that inherit fromtaxcalc.Parameters
will have this behavior. That's why none of the reforms in this repo needed to be reformatted in this PR.Getting the parameter value using a leading underscore still returns its values for all years:
This is done with a custom attribute getter which checks if the attribute meets this pattern and then does the necessary operations to get the values for all years.
Other attributes and methods like
start_year
,current_year
, andset_year
were either copied over to the newParameters
class or re-written to wrap the ParamTools API to maintain consistency.I opened this PR as a draft because I'm not sure if the Tax-Calculator project is interested in adopting ParamTools. After all, Tax-Calculator has a perfectly good parameters processing backend that is fast, reliable, and well-tested. This exercise was very helpful for ParamTools. It prompted me to improve ParamTools's performance, make it more extendable, add better error messages, add warnings, and the list goes on. I even spotted a small bug in Tax-Calculator (#2381) while I was re-implementing the inflation indexing algorithm with ParamTools. I also included detailed documentation on the indexing algorithm in the new
adjust
method, which could be helpful to have in the Tax-Calculator docs. So, I think this exercise was helpful for Tax-Calculator, too. I'm excited to hear people's feedback on this PR.