Skip to content

Commit

Permalink
Minor edits (#56)
Browse files Browse the repository at this point in the history
* fix : .keys() removed from chains, exceptions and transporters

* fix : .keys() removed from pymilo_func

* fix : .keys() removed from tests

* fix : dependabot config updated

* fix : minor edit in codecov.yml
  • Loading branch information
sepandhaghighi authored Dec 7, 2023
1 parent ebf7bf4 commit daea116
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ updates:
time: "01:30"
open-pull-requests-limit: 10
target-branch: dev
assignees:
- "AHReccese"
3 changes: 0 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
codecov:
require_ci_to_pass: yes
notify:
after_n_builds: 1
wait_for_ci: yes

coverage:
precision: 2
Expand Down
4 changes: 2 additions & 2 deletions otherfiles/version_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
os.path.join("pymilo", "pymilo_param.py"): PARAMS_ITEMS,
}

TEST_NUMBER = len(FILES.keys())
TEST_NUMBER = len(FILES)


def print_result(failed=False):
Expand All @@ -48,7 +48,7 @@ def print_result(failed=False):


if __name__ == "__main__":
for file_name in FILES.keys():
for file_name in FILES:
try:
file_content = codecs.open(
file_name, "r", "utf-8", 'ignore').read()
Expand Down
8 changes: 4 additions & 4 deletions pymilo/chains/clustering_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def is_clusterer(model):
:return: check result as bool
"""
if isinstance(model, str):
return model in SKLEARN_CLUSTERING_TABLE.keys()
return model in SKLEARN_CLUSTERING_TABLE
else:
return type(model) in SKLEARN_CLUSTERING_TABLE.values()

Expand Down Expand Up @@ -77,7 +77,7 @@ def serialize_clusterer(clusterer_object):
:type clusterer_object: any sklearn clustering model
:return: the serialized json string of the given clusterer
"""
for transporter in CLUSTERING_CHAIN.keys():
for transporter in CLUSTERING_CHAIN:
CLUSTERING_CHAIN[transporter].transport(
clusterer_object, Command.SERIALIZE)
return clusterer_object.__dict__
Expand All @@ -94,10 +94,10 @@ def deserialize_clusterer(clusterer):
raw_model = SKLEARN_CLUSTERING_TABLE[clusterer.type]()
data = clusterer.data

for transporter in CLUSTERING_CHAIN.keys():
for transporter in CLUSTERING_CHAIN:
CLUSTERING_CHAIN[transporter].transport(
clusterer, Command.DESERIALZIE)
for item in data.keys():
for item in data:
setattr(raw_model, item, data[item])
return raw_model

Expand Down
8 changes: 4 additions & 4 deletions pymilo/chains/decision_tree_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def is_decision_tree(model):
:return: check result as bool
"""
if isinstance(model, str):
return model in SKLEARN_DECISION_TREE_TABLE.keys()
return model in SKLEARN_DECISION_TREE_TABLE
else:
return type(model) in SKLEARN_DECISION_TREE_TABLE.values()

Expand Down Expand Up @@ -79,7 +79,7 @@ def serialize_decision_tree(decision_tree_object):
:type decision_tree_object: any sklearn decision tree model
:return: the serialized json string of the given decision tree model
"""
for transporter in DECISION_TREE_CHAIN.keys():
for transporter in DECISION_TREE_CHAIN:
DECISION_TREE_CHAIN[transporter].transport(
decision_tree_object, Command.SERIALIZE)
return decision_tree_object.__dict__
Expand All @@ -96,10 +96,10 @@ def deserialize_decision_tree(decision_tree):
raw_model = SKLEARN_DECISION_TREE_TABLE[decision_tree.type]()
data = decision_tree.data

for transporter in DECISION_TREE_CHAIN.keys():
for transporter in DECISION_TREE_CHAIN:
DECISION_TREE_CHAIN[transporter].transport(
decision_tree, Command.DESERIALZIE)
for item in data.keys():
for item in data:
setattr(raw_model, item, data[item])
return raw_model

Expand Down
12 changes: 6 additions & 6 deletions pymilo/chains/linear_model_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def is_linear_model(model):
:return: check result as bool
"""
if isinstance(model, str):
return model in SKLEARN_LINEAR_MODEL_TABLE.keys()
return model in SKLEARN_LINEAR_MODEL_TABLE
else:
return type(model) in SKLEARN_LINEAR_MODEL_TABLE.values()

Expand Down Expand Up @@ -98,15 +98,15 @@ def serialize_linear_model(linear_model_object):
:return: the serialized json string of the given linear model
"""
# first serializing the inner linear models...
for key in linear_model_object.__dict__.keys():
for key in linear_model_object.__dict__:
if is_linear_model(linear_model_object.__dict__[key]):
linear_model_object.__dict__[key] = {
"inner-model-data": transport_linear_model(linear_model_object.__dict__[key], Command.SERIALIZE),
"inner-model-type": get_sklearn_type(linear_model_object.__dict__[key]),
"by-pass": True
}
# now serializing non-linear model fields
for transporter in LINEAR_MODEL_CHAIN.keys():
for transporter in LINEAR_MODEL_CHAIN:
LINEAR_MODEL_CHAIN[transporter].transport(
linear_model_object, Command.SERIALIZE)
return linear_model_object.__dict__
Expand All @@ -132,17 +132,17 @@ def deserialize_linear_model(linear_model, is_inner_model):
data = linear_model.data
# first deserializing the inner linear models(one depth inner linear
# models have been deserialized -> TODO full depth).
for key in data.keys():
for key in data:
if is_deserialized_linear_model(data[key]):
data[key] = transport_linear_model({
"data": data[key]["inner-model-data"],
"type": data[key]["inner-model-type"]
}, Command.DESERIALZIE, is_inner_model=True)
# now deserializing non-linear models fields
for transporter in LINEAR_MODEL_CHAIN.keys():
for transporter in LINEAR_MODEL_CHAIN:
LINEAR_MODEL_CHAIN[transporter].transport(
linear_model, Command.DESERIALZIE, is_inner_model)
for item in data.keys():
for item in data:
setattr(raw_model, item, data[item])
return raw_model

Expand Down
8 changes: 4 additions & 4 deletions pymilo/chains/neural_network_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def is_neural_network(model):
:return: check result as bool
"""
if isinstance(model, str):
return model in SKLEARN_NEURAL_NETWORK_TABLE.keys()
return model in SKLEARN_NEURAL_NETWORK_TABLE
else:
return type(model) in SKLEARN_NEURAL_NETWORK_TABLE.values()

Expand Down Expand Up @@ -85,7 +85,7 @@ def serialize_neural_network(neural_network_object):
:type neural_network_object: any sklearn neural network model
:return: the serialized json string of the given neural network model
"""
for transporter in NEURAL_NETWORK_CHAIN.keys():
for transporter in NEURAL_NETWORK_CHAIN:
NEURAL_NETWORK_CHAIN[transporter].transport(
neural_network_object, Command.SERIALIZE)
return neural_network_object.__dict__
Expand All @@ -102,10 +102,10 @@ def deserialize_neural_network(neural_network):
raw_model = SKLEARN_NEURAL_NETWORK_TABLE[neural_network.type]()
data = neural_network.data

for transporter in NEURAL_NETWORK_CHAIN.keys():
for transporter in NEURAL_NETWORK_CHAIN:
NEURAL_NETWORK_CHAIN[transporter].transport(
neural_network, Command.DESERIALZIE)
for item in data.keys():
for item in data:
setattr(raw_model, item, data[item])
return raw_model

Expand Down
2 changes: 1 addition & 1 deletion pymilo/exceptions/deserialize_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, meta_data):
DeSerilaizatoinErrorTypes.CORRUPTED_JSON_FILE: 'the given json file is not a valid .json file.',
DeSerilaizatoinErrorTypes.INVALID_MODEL: 'the given model is not supported or is not a valid model.',
DeSerilaizatoinErrorTypes.VALID_MODEL_INVALID_INTERNAL_STRUCTURE: 'the given model has some non-standard customized internal objects or functions.'}
if error_type in error_type_to_message.keys():
if error_type in error_type_to_message:
reason = error_type_to_message[error_type]
else:
reason = "an Unknown error occurred."
Expand Down
2 changes: 1 addition & 1 deletion pymilo/exceptions/serialize_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, meta_data):
error_type_to_message = {
SerilaizatoinErrorTypes.INVALID_MODEL: 'the given model is not supported or is not a valid model.',
SerilaizatoinErrorTypes.VALID_MODEL_INVALID_INTERNAL_STRUCTURE: 'the given model has some non-standard customized internal objects or functions.'}
if error_type in error_type_to_message.keys():
if error_type in error_type_to_message:
message += error_type_to_message[error_type]
else:
message += "an Unknown error occurred."
Expand Down
6 changes: 3 additions & 3 deletions pymilo/pymilo_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def compare_model_outputs(exported_output,
:type epsilon_error: float
:return: check result as bool
"""
if len(exported_output.keys()) != len(imported_output.keys()):
if len(exported_output) != len(imported_output):
return False # TODO: throw exception
total_error = 0
for key in exported_output.keys():
if key not in imported_output.keys():
for key in exported_output:
if key not in imported_output:
return False # TODO: throw exception
total_error += np.abs(imported_output[key] - exported_output[key])
return np.abs(total_error) < epsilon_error
6 changes: 3 additions & 3 deletions pymilo/transporters/general_data_structure_transporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def serialize_dict(self, dictionary):
:return: fully serializable dictionary
"""
black_list_key_values = []
for key in dictionary.keys():
for key in dictionary:
# check inner field as a np.ndarray
if isinstance(dictionary[key], np.ndarray):
dictionary[key] = self.ndarray_to_list(dictionary[key])
Expand Down Expand Up @@ -191,7 +191,7 @@ def get_deserialized_list(self, content):
for item in content:
if is_primitive(item):
new_list.append(item)
elif "np-type" in item.keys():
elif "np-type" in item:
new_list.append(
NUMPY_TYPE_DICT[item["np-type"]](item['value']))
else:
Expand Down Expand Up @@ -286,7 +286,7 @@ def list_to_ndarray(self, list_item):
else:
if is_primitive(list_item):
return list_item
elif isinstance(list_item, dict) and "np-type" in list_item.keys():
elif isinstance(list_item, dict) and "np-type" in list_item:
return NUMPY_TYPE_DICT[list_item["np-type"]
](list_item['value'])
else:
Expand Down
4 changes: 2 additions & 2 deletions pymilo/transporters/labelbinarizer_transporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_serialized_label_binarizer(self, label_binarizer):
:return: pymilo serialized output of label_binarizer object
"""
data = label_binarizer.__dict__
for key in data.keys():
for key in data:
if isinstance(data[key], np.ndarray):
data[key] = data[key].tolist()
return data
Expand Down Expand Up @@ -76,6 +76,6 @@ def get_deserialized_label_binarizer(self, content):
"""
raw_lb = KEYS_NEED_PREPROCESSING_BEFORE_DESERIALIZATION["_label_binarizer"](
)
for item in content.keys():
for item in content:
setattr(raw_lb, item, content[item])
return raw_lb
4 changes: 2 additions & 2 deletions pymilo/transporters/transporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def transport(self, request, command, is_inner_model=False):
if command == Command.SERIALIZE:
# request is a sklearn model
data = request.__dict__
for key in data.keys():
for key in data:
if self.bypass(data[key]):
continue # by-pass!!
data[key] = self.serialize(
Expand All @@ -125,7 +125,7 @@ def transport(self, request, command, is_inner_model=False):
else:
data = request.data
model_type = request.type
for key in data.keys():
for key in data:
data[key] = self.deserialize(data, key, model_type)
return

Expand Down
2 changes: 1 addition & 1 deletion tests/test_clusterings/test_clusterings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def reset_exported_models_directory():
os.remove(json_file)

def test_full():
for category in CLUSTERINGS.keys():
for category in CLUSTERINGS:
for model in CLUSTERINGS[category]:
model()
2 changes: 1 addition & 1 deletion tests/test_decision_trees/test_decision_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def reset_exported_models_directory():
os.remove(json_file)

def test_full():
for category in DECISION_TREES.keys():
for category in DECISION_TREES:
for model in DECISION_TREES[category]:
model()
2 changes: 1 addition & 1 deletion tests/test_exceptions/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

def test_full():
for category in EXCEPTION_TESTS.keys():
for category in EXCEPTION_TESTS:
category_all_test_pass = True
for test in EXCEPTION_TESTS[category]:
category_all_test_pass = category_all_test_pass and test()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_linear_models/test_linear_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def reset_exported_models_directory():
os.remove(json_file)

def test_full():
for category in LINEAR_MODELS.keys():
for category in LINEAR_MODELS:
for model in LINEAR_MODELS[category]:
if isinstance(model, tuple):
func, model_name = model
Expand Down
2 changes: 1 addition & 1 deletion tests/test_neural_networks/test_neural_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def reset_exported_models_directory():
os.remove(json_file)

def test_full():
for category in NEURAL_NETWORKS.keys():
for category in NEURAL_NETWORKS:
for model in NEURAL_NETWORKS[category]:
model()

0 comments on commit daea116

Please sign in to comment.