Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed May 8, 2024
2 parents 0717429 + 31e307c commit e88dd2e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ docs/_build/
**/*.h5
**/iframe_figures/
.idea
.env
.venv
.vscode
venv
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions policyengine_core/enums/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions policyengine_core/parameters/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions policyengine_core/simulations/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"][()]

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

setup(
name="policyengine-core",
version="2.20.0",
version="2.21.2",
author="PolicyEngine",
author_email="[email protected]",
classifiers=[
Expand Down

0 comments on commit e88dd2e

Please sign in to comment.