diff --git a/bpfin/lib/other.py b/bpfin/lib/other.py index 075ef93037be395b27518db7ca4d57e01c0ac55a..6c083675e0ea51bf30e3f1da6a775fc0607cca1d 100644 --- a/bpfin/lib/other.py +++ b/bpfin/lib/other.py @@ -3,23 +3,14 @@ import calendar import numpy as np from scipy.optimize import linprog - def add_year_dictionary(dict_1, dict_2): - summed_dictionary = {} - for year_1, item_1 in dict_1.items(): - for year_2, item_2 in dict_2.items(): - if year_1 == year_2: - summed_dictionary[year_1] = item_1 + item_2 - return summed_dictionary + summed_dict = {x: dict_1.get(x, 0) + dict_2.get(x, 0) for x in set(dict_1).union(dict_2)} + return summed_dict def subtract_year_dictionary(dict_1, dict_2): - summed_dictionary = {} - for year_1, item_1 in dict_1.items(): - for year_2, item_2 in dict_2.items(): - if year_1 == year_2: - summed_dictionary[year_1] = item_1 - item_2 - return summed_dictionary + summed_dict = {x: dict_1.get(x, 0) - dict_2.get(x, 0) for x in set(dict_1).union(dict_2)} + return summed_dict def add_list(obj_list, number): diff --git a/bpfin/tests/testdata/sample_data.py b/bpfin/tests/testdata/sample_data.py index a187a3cbe54ea9ff5e2517b4122c85642a57feac..5be9768c163292485775813cef3683961361756d 100644 --- a/bpfin/tests/testdata/sample_data.py +++ b/bpfin/tests/testdata/sample_data.py @@ -285,13 +285,13 @@ raw_income_input = { } } -dict_year_1 = {2012: 500, 2013: 1000, 2014: 2000} +dict_year_1 = {2012: 500, 2013: 1000, 2014: 2000, 2015: 200} -dict_year_2 = {2012: 200, 2013: 3000, 2014: 1000} +dict_year_2 = {2011: 100, 2012: 200, 2013: 3000, 2014: 1000} -dict_add = {2012: 700, 2013: 4000, 2014: 3000} +dict_add = {2011: 100, 2012: 700, 2013: 4000, 2014: 3000, 2015: 200} -dict_sub = {2012: 300, 2013: -2000, 2014: 1000} +dict_sub = {2011: -100, 2012: 300, 2013: -2000, 2014: 1000, 2015: 200} income_statement_full = { 2014: {