Skip to content
Snippets Groups Projects
Commit 09fb2374 authored by dh00601's avatar dh00601
Browse files

removed all the deepcopy calls. They slow things down, alot. and I think they are not necessary

parent 140ea866
No related branches found
No related tags found
No related merge requests found
......@@ -61,11 +61,11 @@ def recursive_change_key_to_float(input_dict):
try:
num_key = float(key)
new_dict[num_key] = recursive_change_key_to_float(
copy.deepcopy(input_dict[key])
input_dict[key]
)
except ValueError:
new_dict[key] = recursive_change_key_to_float(
copy.deepcopy(input_dict[key])
input_dict[key]
)
else:
try:
......@@ -89,11 +89,11 @@ def recursive_change_key_to_string(input_dict):
if isinstance(key, (int, float)):
string_key = "{:g}".format(key)
new_dict[string_key] = recursive_change_key_to_string(
copy.deepcopy(input_dict[key])
input_dict[key]
)
else:
new_dict[key] = recursive_change_key_to_string(
copy.deepcopy(input_dict[key])
input_dict[key]
)
else:
if isinstance(key, (int, float)):
......@@ -223,10 +223,8 @@ def subtract_dicts(dict_1: dict, dict_2: dict) -> dict:
if new_dict[key] == 0:
del new_dict[key]
# Else, to be safe we should deepcopy them
elif isinstance(dict_1[key], dict):
copy_dict = copy.deepcopy(dict_1[key])
new_dict[key] = copy_dict
new_dict[key] = dict_1[key]
else:
msg = "Error: using unsupported type for key {}: {}".format(
key, type(dict_1[key])
......@@ -289,7 +287,6 @@ def subtract_dicts(dict_1: dict, dict_2: dict) -> dict:
if new_dict[key] == 0:
del new_dict[key]
# Else, to be safe we should deepcopy them
elif isinstance(dict_1[key], dict):
new_dict[key] = subtract_dicts(dict_1[key], dict_2[key])
......@@ -428,22 +425,10 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict:
# Add the unique keys to the new dict
for key in unique_to_dict_1:
# If these items are ints or floats, then just put them in
if isinstance(dict_1[key], (float, int)):
new_dict[key] = dict_1[key]
# Else, to be safe we should deepcopy them
else:
copy_dict = copy.deepcopy(dict_1[key])
new_dict[key] = copy_dict
new_dict[key] = dict_1[key]
for key in unique_to_dict_2:
# If these items are ints or floats, then just put them in
if isinstance(dict_2[key], (float, int)):
new_dict[key] = dict_2[key]
# Else, to be safe we should deepcopy them
else:
copy_dict = copy.deepcopy(dict_2[key])
new_dict[key] = copy_dict
new_dict[key] = dict_2[key]
# Go over the common keys:
for key in overlapping_keys:
......@@ -566,22 +551,10 @@ def update_dicts(dict_1: dict, dict_2: dict) -> dict:
# Add the unique keys to the new dict
for key in unique_to_dict_1:
# If these items are ints or floats, then just put them in
if isinstance(dict_1[key], (float, int)):
new_dict[key] = dict_1[key]
# Else, to be safe we should deepcopy them
else:
copy_dict = copy.deepcopy(dict_1[key])
new_dict[key] = copy_dict
new_dict[key] = dict_1[key]
for key in unique_to_dict_2:
# If these items are ints or floats, then just put them in
if isinstance(dict_2[key], (float, int)):
new_dict[key] = dict_2[key]
# Else, to be safe we should deepcopy them
else:
copy_dict = copy.deepcopy(dict_2[key])
new_dict[key] = copy_dict
new_dict[key] = dict_2[key]
# Go over the common keys:
for key in overlapping_keys:
......@@ -684,7 +657,7 @@ def custom_sort_dict(input_dict):
sorted_keys = sorted(keys)
for key in sorted_keys:
new_dict[key] = custom_sort_dict(copy.deepcopy(input_dict[key]))
new_dict[key] = custom_sort_dict(input_dict[key])
return new_dict
return input_dict
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment