Skip to content

Commit 4b0de3c

Browse files
committed
format
1 parent 7a8fa15 commit 4b0de3c

1 file changed

Lines changed: 36 additions & 12 deletions

File tree

policyengine_uk/simulation.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def __init__(
8080
self.invalidated_caches = set()
8181
self.debug: bool = False
8282
self.trace: bool = trace
83-
self.tracer: SimpleTracer = SimpleTracer() if not trace else FullTracer()
83+
self.tracer: SimpleTracer = (
84+
SimpleTracer() if not trace else FullTracer()
85+
)
8486
self.opt_out_cache: bool = False
8587
self.max_spiral_loops: int = 10
8688
self.memory_config = None
@@ -155,7 +157,9 @@ def apply_parameter_changes(self, changes: dict):
155157
self.tax_benefit_system.reset_parameters()
156158

157159
for parameter in changes:
158-
p: Parameter = self.tax_benefit_system.parameters.get_child(parameter)
160+
p: Parameter = self.tax_benefit_system.parameters.get_child(
161+
parameter
162+
)
159163
if isinstance(changes[parameter], dict):
160164
# Time-period specific changes
161165
for time_period in changes[parameter]:
@@ -174,7 +178,9 @@ def build_from_situation(self, situation: Dict) -> None:
174178
Args:
175179
situation: Dictionary describing household composition and characteristics
176180
"""
177-
self.build_from_populations(self.tax_benefit_system.instantiate_entities())
181+
self.build_from_populations(
182+
self.tax_benefit_system.instantiate_entities()
183+
)
178184
from policyengine_core.simulations.simulation_builder import (
179185
SimulationBuilder,
180186
) # Import here to avoid circular dependency
@@ -198,7 +204,9 @@ def build_from_url(self, url: str) -> None:
198204
ValueError: If URL is not a HuggingFace URL
199205
"""
200206
if "hf://" not in url:
201-
raise ValueError(f"Non-HuggingFace URLs are currently not supported.")
207+
raise ValueError(
208+
f"Non-HuggingFace URLs are currently not supported."
209+
)
202210

203211
# Parse HuggingFace URL components
204212
owner, repo, filename = url.split("/")[-3:]
@@ -276,7 +284,9 @@ def build_from_dataset(self, dataset: Dataset) -> None:
276284
Args:
277285
dataset: PolicyEngine Dataset object containing simulation data
278286
"""
279-
data: Dict[str, Dict[str, Union[float, int, str]]] = dataset.load_dataset()
287+
data: Dict[str, Dict[str, Union[float, int, str]]] = (
288+
dataset.load_dataset()
289+
)
280290

281291
first_variable = data[list(data.keys())[0]]
282292
first_time_period = list(first_variable.keys())[0]
@@ -305,7 +315,9 @@ def get_first_array(variable_name: str) -> np.ndarray:
305315
for time_period in data[variable]:
306316
if variable not in self.tax_benefit_system.variables:
307317
continue
308-
self.set_input(variable, time_period, data[variable][time_period])
318+
self.set_input(
319+
variable, time_period, data[variable][time_period]
320+
)
309321

310322
# Now convert to the new UKSingleYearDataset
311323
self.input_variables = self.get_known_variables()
@@ -318,7 +330,9 @@ def get_first_array(variable_name: str) -> np.ndarray:
318330
self.build_from_multi_year_dataset(multi_year_dataset)
319331
self.dataset = multi_year_dataset
320332

321-
def build_from_single_year_dataset(self, dataset: UKSingleYearDataset) -> None:
333+
def build_from_single_year_dataset(
334+
self, dataset: UKSingleYearDataset
335+
) -> None:
322336
"""Build simulation from a single-year UK dataset.
323337
324338
Args:
@@ -329,7 +343,9 @@ def build_from_single_year_dataset(self, dataset: UKSingleYearDataset) -> None:
329343
self.build_from_multi_year_dataset(dataset)
330344
self.dataset = dataset
331345

332-
def build_from_multi_year_dataset(self, dataset: UKMultiYearDataset) -> None:
346+
def build_from_multi_year_dataset(
347+
self, dataset: UKMultiYearDataset
348+
) -> None:
333349
"""Build simulation from a multi-year UK dataset.
334350
335351
Args:
@@ -490,7 +506,9 @@ def get_variable_dependencies(self, variable_name: str, depth: int = 1):
490506
trace=True,
491507
)
492508
self._example_simulation.calculate("hbai_household_net_income")
493-
for variable in self._example_simulation.tax_benefit_system.variables:
509+
for (
510+
variable
511+
) in self._example_simulation.tax_benefit_system.variables:
494512
try:
495513
dependencies = get_variable_dependencies(
496514
variable, self._example_simulation
@@ -511,7 +529,9 @@ def get_variable_dependencies(self, variable_name: str, depth: int = 1):
511529
all_dependencies = set(dependencies)
512530
for dep in dependencies:
513531
try:
514-
sub_dependencies = self.get_variable_dependencies(dep, depth - 1)
532+
sub_dependencies = self.get_variable_dependencies(
533+
dep, depth - 1
534+
)
515535
all_dependencies.update(sub_dependencies)
516536
except ValueError:
517537
continue
@@ -542,9 +562,13 @@ def compare(
542562
df_self = self.calculate_dataframe(variables, period=period)
543563
df_other = other.calculate_dataframe(variables, period=period)
544564

545-
df_combined = pd.concat([df_self, df_other], axis=1, keys=["self", "other"])
565+
df_combined = pd.concat(
566+
[df_self, df_other], axis=1, keys=["self", "other"]
567+
)
546568
# Reset columns, then order by variable name first then self/other
547-
df_combined.columns = [f"{var}_{entity}" for entity, var in df_combined.columns]
569+
df_combined.columns = [
570+
f"{var}_{entity}" for entity, var in df_combined.columns
571+
]
548572
# Add change where applicable (numeric only)
549573
for variable in variables:
550574
self_col = f"{variable}_self"

0 commit comments

Comments
 (0)