diff --git a/.gitignore b/.gitignore index 4b1f16b7..60cec3f1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,7 @@ docs/_build/ **/*.h5 **/iframe_figures/ .idea +.env +.venv .vscode venv \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 73539965..4a310ceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,24 @@ 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). +## [2.21.2] - 2024-05-08 08:44:48 + +### Fixed + +- Generation of enum-typed variables + +## [2.21.1] - 2024-05-07 15:44:58 + +### Fixed + +- Bug in macro caching logic. + +## [2.21.0] - 2024-05-07 12:16:05 + +### Added + +- Ability to turn off read and write features in the macro cache. + ## [2.20.0] - 2024-05-06 14:24:08 ### Added @@ -628,6 +646,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +[2.21.2]: https://github.com/PolicyEngine/policyengine-core/compare/2.21.1...2.21.2 +[2.21.1]: https://github.com/PolicyEngine/policyengine-core/compare/2.21.0...2.21.1 +[2.21.0]: https://github.com/PolicyEngine/policyengine-core/compare/2.20.0...2.21.0 [2.20.0]: https://github.com/PolicyEngine/policyengine-core/compare/2.19.2...2.20.0 [2.19.2]: https://github.com/PolicyEngine/policyengine-core/compare/2.19.1...2.19.2 [2.19.1]: https://github.com/PolicyEngine/policyengine-core/compare/2.19.0...2.19.1 diff --git a/changelog.yaml b/changelog.yaml index c06fbbf1..ce602b80 100644 --- a/changelog.yaml +++ b/changelog.yaml @@ -524,3 +524,18 @@ fixed: - Uprating bugs. date: 2024-05-06 14:24:08 +- bump: minor + changes: + added: + - Ability to turn off read and write features in the macro cache. + date: 2024-05-07 12:16:05 +- bump: patch + changes: + fixed: + - Bug in macro caching logic. + date: 2024-05-07 15:44:58 +- bump: patch + changes: + fixed: + - Generation of enum-typed variables + date: 2024-05-08 08:44:48 diff --git a/policyengine_core/enums/enum.py b/policyengine_core/enums/enum.py index dcad5c6b..584b1bd4 100644 --- a/policyengine_core/enums/enum.py +++ b/policyengine_core/enums/enum.py @@ -49,17 +49,18 @@ def encode(cls, array: Union[EnumArray, np.ndarray]) -> EnumArray: if isinstance(array, EnumArray): return array - if array.dtype.kind == "b": + # if array.dtype.kind == "b": + if isinstance(array == 0, bool): # Convert boolean array to string array array = array.astype(str) - if array.dtype.kind in {"U", "S"}: + if isinstance(array, np.ndarray) and array.dtype.kind in {"U", "S"}: # String array indices = np.select( [array == item.name for item in cls], [item.index for item in cls], ) - elif array.dtype.kind == "O": + elif isinstance(array, np.ndarray) and array.dtype.kind == "O": # Enum items array if len(array) > 0: first_item = array[0] diff --git a/policyengine_core/parameters/parameter.py b/policyengine_core/parameters/parameter.py index 57d04b43..da185e18 100644 --- a/policyengine_core/parameters/parameter.py +++ b/policyengine_core/parameters/parameter.py @@ -210,6 +210,8 @@ def update(self, period=None, start=None, stop=None, value=None): self.parent.clear_parent_cache() + self.mark_as_modified() + def mark_as_modified(self): self.modified = True self.parent.mark_as_modified() diff --git a/policyengine_core/simulations/simulation.py b/policyengine_core/simulations/simulation.py index e6dbed5d..b158a60f 100644 --- a/policyengine_core/simulations/simulation.py +++ b/policyengine_core/simulations/simulation.py @@ -69,6 +69,12 @@ class Simulation: is_over_dataset: bool = False """Whether this simulation is built over a dataset.""" + macro_cache_read: bool = True + """Whether to read from the macro cache.""" + + macro_cache_write: bool = True + """Whether to write to the macro cache.""" + def __init__( self, tax_benefit_system: "TaxBenefitSystem" = None, @@ -1367,6 +1373,8 @@ def _get_macro_cache_value( """ Get the value of a variable from a cache file. """ + if not self.macro_cache_read: + return None with h5py.File(cache_file_path, "r") as f: return f["values"][()] @@ -1378,6 +1386,8 @@ def _set_macro_cache_value( """ Set the value of a variable in a cache file. """ + if not self.macro_cache_write: + return None with h5py.File(cache_file_path, "w") as f: f.create_dataset("values", data=value) diff --git a/setup.py b/setup.py index 87420399..c099ea91 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ setup( name="policyengine-core", - version="2.20.0", + version="2.21.2", author="PolicyEngine", author_email="hello@policyengine.org", classifiers=[