-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
Revise Parameters class code, documentation, and tests #321
Conversation
and to eliminate many (but not all) pylint warnings. All items in py.test continue to pass after these revisions.
eliminated. Also, add default_inflation_rate classmethod to provide access to the __rates dictionary.
pylint warnings in taxcalc/tests/test_parameters.py.
reflect experience implementing multiple-year reforms as described in GitHib OSPC/Tax-Calculator issue #324.
implementation of multiple-year reforms.
the year_mods dictionary must equal Parameters.current_year.
the year_mods dictionary must no less that Parameters.start_year and no greater than Parameters.start_year+Parameters.budget_years.
method that passed year is in [start_year,end_year] range.
two-dimensional parameters in reform and to check two-dimensional parameter reform results.
Parameters.start_year.
corrects inflation indexing error detected in reform_test.py. However, this expand_2D fix causes three taxcalc/tests/test_utils.py errors that need to be explored.
The prior check-in changed the inflation rate indexing scheme in the expand_2D() function to be the same as the inflation rate indexing scheme in the expand_1D() function, which allowed the reform_test.py script to execute without any assert errors. However, this change caused three test_utils.py tests and three test_calculate.py tests to fail. The current check-in fixes all three failing test_utils.py tests by correcting the computation of expected results (which had been computed using the wrong inflation rate indexing scheme).
by changing name of reformed parameter from '_rt7' (which does not exist in the params.json file) to '_II_rt7' (which does exist in the params.json file).
by calling calc.params.update(user_mods) on the calc.params object that contains the fake dictionary of policy parameters read from the paramsfile.
by changing the second dimension of the '_STD_Aged' parameter in the user_mods dictionary from two to six (so that it agrees with the specification of that parameter in the params.json file and thus avoids a broadcast error in the Parameters class update method).
describes correctly how to specify changes in a two-dimensional policy parameter in the passed user_mods dictionary.
@@ -0,0 +1,241 @@ | |||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like some reasonable tests here, although it seems to me that this is testing the same functionality for various parameters. The maintenance burden goes up for each hard coded value that is tested (since it could change in the future), but if you think there is benefit in keeping all of the functions here, no problem. The right place for this file is taxcalc/tests/test_reform.py (or really anything starting with test_
, with each of the functions prefaced with test_
so that py.test will run them each time.
A major component of the changes here is a modification of To start, here is an example of what happens with Parameters objects in the A few features to note:
says that
is important, because we will have a start_year of 2013, then some later year, like 2016, will be the current year. If the
is equal to 1 (i.e. 2016 - 2015). So, we skip the first value in the provided sequence, (e.g. for I'm not sure all of that makes sense, but at the very least, you can download that gist to a file at the top of your repo and you will have a valid test that you can test against to continue with this PR. This test should go into master immediately, since dependent packages won't work unless the functionality described in those tests works. There are at least two good catches here in |
T.J. (@talumbau) said:
I think the complexity of the test is worth it because it revealed a bug in the Parameters update I will move this test to the taxcalc/tests/test_parameters.py file because it is testing the ability Does that approach make sense? |
Apart from the inflation-indexing test results being inconsistent with those that will be I suggest that if everybody is OK with pull request #326, then we should proceed Does this seem like a reasonable approach? If not, what would be a better approach? |
@MattHJensen and TJ @talumbau, |
@MattHJensen said:
TJ @talumbau, when do you expect to post this new pull request? It would |
probably by 8pm central time today |
@martinholmer, were you interested in being able to specify a multi year reform like in this snippet?
Perhaps you were waiting to discuss this as a separate issue later. |
OK, I've put up PR #330 that has a test in it that this PR will fail. The reason it fails is because this branch has a test that makes sure that there is only one year given in user_mods. That's probably reasonable for now. At least, our tests only use user_mods that way, so we should probably enforce that for now. However,
Put that in around line 35 or so in calculate.py and you will then pass the new test. |
TJ @talumbau said:
This is a perfect example of the problems created by a lack of object-oriented desgin |
@MattHJensen said:
Actually, the basic design of the Parameters class already allows the above, as |
num_years_to_expand = (self.start_year + self.budget_years) - year | ||
inf_rates = [self._inflation_rates[(year - self.start_year) + i] | ||
for i in range(0, num_years_to_expand)] | ||
paramvals = self._vals #TODO: requires __init__(...,data=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this before. What is the meaning of the comment here?
That sounds like a perfectly reasonable position, but I don't see how it applies to this situation. As I mentioned before, there is nothing here regarding a breaking of encapsulation, or really any OO concepts at all. There exists a free standing function called |
num_years=num_years_to_expand) | ||
cval = getattr(self, name) | ||
cval[(self.current_year - self.start_year):] = nval | ||
setattr(self, name, cval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setattr
is not needed here. If you remove this line of code from the parameters-edit2
branch, all of the tests still pass. cval
is just a name associated with whatever attribute we are modifying. Line 238 does the mutation of that value. After that, there is no more work to do.
The last issue that should be discussed with this PR is that is puts a particular restriction on the user reform year to be the same exact year as the current year for the This is just a trade-off. The implementation of |
Yes, @martinholmer, I definitely agree that we should be continually thinking about how we can make improvements to the code base, and your suggestions on that front would be much appreciated. The way I'd suggest going about this would be to set up a video conference/screenshare to make sure we're all an the same page about the existing taxcalc code base as well as the codebase in dropq and webapp. Then you can make your suggestions via an issue + gist or via a PR (the choice of these two paths would depend on how likely you think everyone else is to agree with your suggestions, how much work it is to implement, and whether it is easy to communicate your intent via a pared down example) |
num_years=nyrs)) | ||
|
||
# specify multi-year reform using a dictionary of year_provisions dicts | ||
reform = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinholmer, were you interested in organizing these dictionaries by parameter rather than by year. I.e, like the snippet below rather than what is shown in the test?
reform = {
'_AMT_thd_MarriedS': {
_c_cpi': False
2015: [60000],
2016: [65000]
},
'_EITC_c': {
2016: [[900, 5000, 8000, 9000]],
2017: [[950, 6000, 8000, 9000]],
2018: [[950, 6000, 8000, 1000]]
}
}
This would parallel more closely, (and potentially be a better supplement, even alternative to) our current method of specifying multi-year reforms {name: [1st_yr_val, 2nd_yr_val, 3rd_yr_val, ...]}
Let me dig into this later today after I get the pep8 PR tied up. |
This pull request #321 is now not able to be merged into the master branch because |
I'm still hoping the vast majority of this content gets merged. Doesn't hurt to wait until after our code design discussion to move forward, though. |
The revisions add Sphinx-aware docstrings (with lengthy docstrings for the class constructor and
for the update method) and a new classmethod called default_inflation_rate. The revisions also
eliminate all but a few pylint warnings in parameters.py file.. Also, test_parameters.py has been
revised to use the new default_inflation_rate classmethod and to eliminate some (but nowhere
close to all) pylint warnings. These revisions leave the 75 items in py.test passing and also
produce exactly the same results_puf.csv file (which is the output written by the test.py script)
as before the changes in this pull request.