Skip to content
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

Parameters class API redesign #343

Merged
merged 51 commits into from
Sep 8, 2015
Merged

Parameters class API redesign #343

merged 51 commits into from
Sep 8, 2015

Conversation

martinholmer
Copy link
Collaborator

This pull request includes a redesign of the Parameters class API plus Sphinx-aware documentation. The new API is as described in issue #336. The old Parameters class had no documentation, but a combination of the source code, the tests in test_parameters.py and test_calculate.py, and the helpful discussion in issue #342, provided a basis for the redesign. The redesign includes a replacement for the old global default_data function, which passes all the tests and works as described in the issue #342 discussion. Several changes have been made on Sep 1 (see details below in commit history) in response to helpful suggestions made by T.J. Alumbaugh (@talumbau) and @MattHJensen.

These changes were required by the new signature of the Parameters
class __init__ function.
Not sure why this error was not found before; perhaps something to do
with the calculator factory function.
Not sure why this error was not found before; perhaps something to do
with two Calculator objects in test with only one being used in test.
…s_dict.

Not sure why this error was not found before; perhaps something to do
with the calculator factory function.
Not sure why this test was using the calculator factory function when
its former name makes clear that is testing the Calculator
constructor.  And again, not sure why this error was not found before;
perhaps something to do with a flaw in the logic of the calculator
factory function.
This classmethod appears to not be used in the webapp repo;
dropping it causes six (out of 78) taxcalc tests to fail.
This classmethod appears to not be used in the webapp repo; dropping
it does not change the four (out of 78) taxcalc test failures.
Dropping Calculator.from_file requires minor changes to the
Calculator.__init__ method, which now treats the params argument in
the same way as the records argument is treated.
The first change is the elimination of the Calculator.from_files
method; the second change is the new Calculator.__init__ method
that requires a Parameters object be passed via the params argument.
After the changes in the logic of four tests, there are no test
failures among the 78 taxcalc tests.
There appear to be no uses of the old public Parameters.update method
in the webapp repo.
There appear to be no uses of the Parameters.increment_year method in
the webapp repo.
Add Parameters classmethod _params_dict_from_json_file() that
incorporates params.json file read logic from global default_data()
function.  Then use this new classmethod in Parameters.__init__
instead of calling default_data(metadata=True)
Add Parameters classmethod default_data(cls, metadata=False,
first_value_year=None) that is intended to replace the legacy
global default_data function in the parameters.py file.
Add logic to tests that call the global default_data function so that
they can continue to do that or they can call the new Parameters
default_data classmethod.  Both tests pass regardless of which
default_data they call.
The new test confirms that every parameter in the params.json
file has an attribute named "start_year" whose value is equal
to Parameters.JSON_START_YEAR.
The "original" code means as of 11-Aug-2015 check-in e5cbc0e, except
for the change from Parameters.PARAM_FILENAME to
Parameters.PARAMS_FILENAME and the change from DEFAULT_START_YEAR to
Parameters.JSON_START_YEAR.
np.array([1400, 1100, 1100, 1400, 1400, 1199]))


def test_update_Parameters_raises_on_future_year():
p = Parameters(start_year=2013)
def test_Parameters_reform_before_start_year():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above here, regarding 'raises' in the test name.

@martinholmer
Copy link
Collaborator Author

@MattHJensen I tried to test this in dropq and the web application. Here is what I found:

the tests in webapp-public pass in the one case where we call default_data using the new default_data

I was unable to test this branch in dropq because of a behavior change between the existing update method and the new implement_reform method. I don't know if this is an intentional change or not. If it is intentional, @martinholmer and I will need to walk through how one should create a Calculator instance and add reforms. Here is the new behavior vs. the old:

from taxcalc import Calculator, Records, Parameters

# User specified plan, start at 2013
params = Parameters(start_year=2013)
# setting up for reform for 2015
params.set_year(2014)
params.set_year(2015)
assert params.current_year == 2015
mods = {2015: {'_II_rt3': [0.31], '_II_rt4': [0.39]}}
params.implement_reform(mods)
# I would assume params.current_year is still 2015
#this fails because params.current_year goes back to 2013
assert params.current_year == 2015

dropq builds Parameter instances assuming that after implementing a reform (or "updating" in the old way) the current_year remains the same. So, I could impose a solution in my branch and try to get dropq to run. Should I do that?

T.J. @talumbau (and @MattHJensen) would something like the following work?

params = Parameters()
mods = {2015: {'_II_rt3': [0.31], '_II_rt4': [0.39]}}
params.implement_reform(mods)
params.set_year(2015)

@talumbau
Copy link
Member

@martinholmer for inline conversations, would you mind keeping the conversation inline using the Add a Line Note button?

screen shot 2015-08-31 at 12 53 29 pm

We have many inline conversations on this PR and if we use the main Conversation thread I think it will get too complicated.

@MattHJensen
Copy link
Contributor

I believe this PR is ready to be merged based on the following analysis:

There are two outstanding lines of discussion that have not yet been fully addressed, but after conversing with @martinholmer on the phone this morning, I believe both of them ought to be dealt with in follow-on work. These two areas, and the reason for separating them from this PR, are as follows:

  1. @talumbau raised several points about test names and test coverage (or overcoverage) which have not yet been addressed. The first and foremost reason for dealing with them separately is that they are not urgent and do not affect the existing functionality of the code. Second, I believe our test naming conventions relate to our ongoing conversation over coding style (coding style #30 (comment)); in particular, test naming conventions will come up when we move on to the second step of our coding style conversation:

    "After that, @martinholmer will open a separate issue that lists all of the classes of warnings that pylint generates and opens a discussion on which to keep or whether to use some alternative to pylint."

  2. @talumbau and I raised a point about allowing the user to specify a JSON file of tax parameters other than params.json. This too is not urgent for our users, and can therefore -- from a timing perspective -- be dealt with later. Moreover, @martinholmer raised the point that we should be doing some checking when such a file is read to ensure that the user supplied JSON is valid, which we do not currently do on master. When we reintroduce this feature, we ought to include some of this checking.
    As @zrisher has said,

    users will make eventually make every usage error you can think of. : )

An additional reason for separating both these issues into follow on work is that they might both require quite a bit of discussion, and this PR is already quite cluttered.

@talumbau, if this analysis seems reasonable to you, could you go ahead and merge this PR?

@talumbau
Copy link
Member

talumbau commented Sep 8, 2015

@MattHJensen OK, I'll merge this and create follow-on issues.

talumbau added a commit that referenced this pull request Sep 8, 2015
@talumbau talumbau merged commit 021c845 into PSLmodels:master Sep 8, 2015
@martinholmer martinholmer deleted the parameters-api-redesign branch May 7, 2016 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants