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

Using 0/1 for boolean/integer parameter produces error #1969

Closed
hdoupe opened this issue Apr 13, 2018 · 5 comments
Closed

Using 0/1 for boolean/integer parameter produces error #1969

hdoupe opened this issue Apr 13, 2018 · 5 comments

Comments

@hdoupe
Copy link
Collaborator

hdoupe commented Apr 13, 2018

I came across this issue while trying to get to 100% test coverage in PR #1952. If you have a parameter that can be either boolean or an integer that is 0 or 1, you will get an error when the parameter is set to 0 or 1.

The code below is using the master branch of Tax-Calculator.

import taxcalc

dd = taxcalc.Policy.default_data(start_year=2017, metadata=True)
print('is boolean value', dd['_ALD_InvInc_ec_base_RyanBrady']['boolean_value'])
print('is integer value', dd['_ALD_InvInc_ec_base_RyanBrady']['integer_value'])

reform = {2017: {'_ALD_InvInc_ec_base_RyanBrady': [1]}}
print('reform', reform)

pol = taxcalc.Policy()
pol.ignore_reform_errors()
pol.implement_reform(reform)

which gives output:

is boolean value True
is integer value True
reform {2017: {'_ALD_InvInc_ec_base_RyanBrady': [1]}}
Traceback (most recent call last):
  File "int_bool_test.py", line 12, in <module>
    pol.implement_reform(reform)
  File "/Users/henrydoupe/Documents/Tax-Calculator/taxcalc/policy.py", line 232, in implement_reform
    raise ValueError('\n' + self.reform_errors)
ValueError: 
ERROR: 2017 _ALD_InvInc_ec_base_RyanBrady value 1 is not boolean

One possible fix for this is:

# Policy._validate_parameter_names_types line 490
pval_is_bool = type(pval) == bool or pval in (0, 1)

instead of:

# Policy._validate_parameter_names_types line 490
pval_is_bool = type(pval) == bool
@martinholmer
Copy link
Collaborator

@hdoupe, The _ALD_InvInc_ec_base_RyanBrady parameter is boolean, so it must have a value of True or False. It cannot have a numerical value following the merge of pull request #1960. So the "fix" is to specify the reform not this way:

reform = {2017: {'_ALD_InvInc_ec_base_RyanBrady': [1]}}

but this way:

reform = {2017: {'_ALD_InvInc_ec_base_RyanBrady': [True]}}

@hdoupe
Copy link
Collaborator Author

hdoupe commented Apr 13, 2018

Ok, I see. So, for all boolean parameters, the JSON file should have "integer_type" be false and "boolean_type" be true?

@martinholmer
Copy link
Collaborator

@hdoupe said:

Ok, I see. So, for all boolean parameters, the JSON file should have "integer_type" be false and "boolean_type" be true?

Yes and I'm now preparing a pull request that makes those changes to the JSON parameter files and to the source code to accommodate the new and less confusing data type information.

@hdoupe
Copy link
Collaborator Author

hdoupe commented Apr 13, 2018

Ok, thanks @martinholmer.

@martinholmer
Copy link
Collaborator

martinholmer commented Apr 13, 2018

Pull request #1970 clarifies the documentation of parameter datatypes, the need for which was indicated by @hdoupe's reading of the old documentation in issue #1969.

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

No branches or pull requests

2 participants