Skip to content

Commit

Permalink
Merge pull request #21 from PolicyEngine/uprating
Browse files Browse the repository at this point in the history
Handle uprated-and-computed variables
  • Loading branch information
nikhilwoodruff committed Jan 26, 2022
2 parents 654ec6b + 8837359 commit 678e7f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.3] - 2022-01-26

### Fixed

* Variables with both a formula and an uprating index will now uprate only if there are non-zero values in the last time period.

## [0.2.2] - 2022-01-17

### Fixed
Expand Down
10 changes: 8 additions & 2 deletions openfisca_tools/model_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
max_,
min_,
)
from typing import Callable, Tuple, Union
from typing import Callable, Tuple, Type, Union
import numpy as np

ReformType = Union[Reform, Tuple[Reform]]
Expand Down Expand Up @@ -150,10 +150,12 @@ def uprated(by: str = None, start_year: int = 2015) -> Callable:
Callable: A class decorator.
"""

def uprater(variable: type) -> type:
def uprater(variable: Type[Variable]) -> type:
if hasattr(variable, f"formula_{start_year}"):
return variable

formula = variable.formula if hasattr(variable, "formula") else None

def formula_start_year(entity, period, parameters):
if by is None:
return entity(variable.__name__, period.last_year)
Expand All @@ -163,6 +165,10 @@ def formula_start_year(entity, period, parameters):
/ parameters(period.last_year).uprating[by]
)
old = entity(variable.__name__, period.last_year)
if (formula is not None) and (all(old) == 0):
# If no values have been inputted, don't uprate and
# instead use the previous formula on the current period.
return formula(entity, period, parameters)
return uprating * old

formula_start_year.__name__ = f"formula_{start_year}"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="OpenFisca-Tools",
version="0.2.2",
version="0.2.3",
author="PolicyEngine",
license="http://www.fsf.org/licensing/licenses/agpl-3.0.html",
url="https://github.com/policyengine/openfisca-tools",
Expand Down

0 comments on commit 678e7f7

Please sign in to comment.