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

Add ability to delete existing value objects #38

Merged
merged 3 commits into from Mar 7, 2019

Conversation

Projects
None yet
1 participant
@hdoupe
Copy link
Collaborator

commented Mar 7, 2019

This PR adds the ability to delete existing value objects by setting their value to None. For example,

In [1]: from paramtools import Parameters                                                                                                                                                                                                                                       

In [2]: class TaxParams(Parameters): 
   ...:     schema = "taxparams-demo/schema.json" 
   ...:     defaults = "taxparams-demo/defaults.json" 
   ...:                                                                                                                                                                                                                                                                         

In [3]: params = TaxParams()                                                                                                                                                                                                                                                    

In [4]: params.standard_deduction                                                                                                                                                                                                                                               
Out[4]: 
[{'value': 13673.68, 'marital_status': 'single', 'year': 2024},
 {'value': 27347.36, 'marital_status': 'joint', 'year': 2024},
 {'value': 13673.68, 'marital_status': 'separate', 'year': 2024},
 {'value': 20510.52, 'marital_status': 'headhousehold', 'year': 2024},
 {'value': 27347.36, 'marital_status': 'widow', 'year': 2024},
 {'value': 13967.66, 'marital_status': 'single', 'year': 2025},
 {'value': 27935.33, 'marital_status': 'joint', 'year': 2025},
 {'value': 13967.66, 'marital_status': 'separate', 'year': 2025},
 {'value': 20951.49, 'marital_status': 'headhousehold', 'year': 2025},
 {'value': 27935.33, 'marital_status': 'widow', 'year': 2025},
 {'value': 7690.0, 'marital_status': 'single', 'year': 2026},
 {'value': 15380.0, 'marital_status': 'joint', 'year': 2026},
 {'value': 7690.0, 'marital_status': 'separate', 'year': 2026},
 {'value': 11323.0, 'marital_status': 'headhousehold', 'year': 2026},
 {'value': 15380.0, 'marital_status': 'widow', 'year': 2026}]

In [5]: params.adjust({"standard_deduction": [{"year": 2026, "value": None}]})                                                                                                                                                                                                  

In [6]: params.standard_deduction                                                                                                                                                                                                                                               
Out[6]: 
[{'value': 13673.68, 'marital_status': 'single', 'year': 2024},
 {'value': 27347.36, 'marital_status': 'joint', 'year': 2024},
 {'value': 13673.68, 'marital_status': 'separate', 'year': 2024},
 {'value': 20510.52, 'marital_status': 'headhousehold', 'year': 2024},
 {'value': 27347.36, 'marital_status': 'widow', 'year': 2024},
 {'value': 13967.66, 'marital_status': 'single', 'year': 2025},
 {'value': 27935.33, 'marital_status': 'joint', 'year': 2025},
 {'value': 13967.66, 'marital_status': 'separate', 'year': 2025},
 {'value': 20951.49, 'marital_status': 'headhousehold', 'year': 2025},
 {'value': 27935.33, 'marital_status': 'widow', 'year': 2025}]

In [7]:                                                                                                                                                                                                                                                                         

A subtle bug was also fixed with this PR. By default, Parameters.specification only returns values that are selected by the query or do not contain any of the dimensions specified in the query. Parameters.set_state uses Parameters.specifications to update the instance attributes of each parameter. If a parameter is not active in the current state (i.e. it does not meet the query dimensions in state), then it is not returned by the specification call. Therefore, the instance attribute isn't updated. This PR adds an include_empty keyword to specification that requires it to return all parameters, including ones that are not active in the state.

@hdoupe hdoupe merged commit 4f35e9c into master Mar 7, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@hdoupe hdoupe deleted the none-delete branch Mar 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.