Skip to content

Commit 0f000a1

Browse files
Avoid unnecessary recomputation of yearly mappings (#104)
1 parent 418c5a5 commit 0f000a1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/map.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def apply_mapping(project, timeframes, output_dir, force_map):
3434
project_output_dir = output_dir / f'{project}'
3535
mapping = ledger_mapping[project](project, project_output_dir)
3636

37+
computed_yearly_mappings = set() # Keep track of computed yearly mappings to avoid recomputing them in the same run
3738
for timeframe in timeframes:
3839
output_file = project_output_dir / f'{timeframe}.csv'
3940
if not output_file.is_file() or force_map:
@@ -43,8 +44,9 @@ def apply_mapping(project, timeframes, output_dir, force_map):
4344
# This is needed because the Gini coefficient is computed over all entities per each year.
4445
year = timeframe[:4]
4546
year_file = project_output_dir / f'{year}.csv'
46-
if not year_file.is_file() or force_map:
47+
if not year_file.is_file() or (force_map and year not in computed_yearly_mappings):
4748
mapping.perform_mapping(year)
49+
computed_yearly_mappings.add(year)
4850

4951

5052
if __name__ == '__main__':

0 commit comments

Comments
 (0)