Skip to content

Commit 4b0ec45

Browse files
committed
Type check with isinstance instead of type() ==
1 parent 2623152 commit 4b0ec45

9 files changed

Lines changed: 11 additions & 9 deletions

File tree

openml/datasets/functions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ def __list_datasets(api_call, output_format="dict"):
192192
datasets_dict = xmltodict.parse(xml_string, force_list=("oml:dataset",))
193193

194194
# Minimalistic check if the XML is useful
195-
assert type(datasets_dict["oml:data"]["oml:dataset"]) == list, type(datasets_dict["oml:data"])
195+
assert isinstance(datasets_dict["oml:data"]["oml:dataset"], list), type(
196+
datasets_dict["oml:data"]
197+
)
196198
assert datasets_dict["oml:data"]["@xmlns:oml"] == "http://openml.org/openml", datasets_dict[
197199
"oml:data"
198200
]["@xmlns:oml"]

openml/evaluations/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def __list_evaluations(api_call, output_format="object"):
197197
"Error in return XML, does not contain " '"oml:evaluations": %s' % str(evals_dict)
198198
)
199199

200-
assert type(evals_dict["oml:evaluations"]["oml:evaluation"]) == list, type(
200+
assert isinstance(evals_dict["oml:evaluations"]["oml:evaluation"], list), type(
201201
evals_dict["oml:evaluations"]
202202
)
203203

openml/flows/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def __list_flows(api_call: str, output_format: str = "dict") -> Union[Dict, pd.D
341341
flows_dict = xmltodict.parse(xml_string, force_list=("oml:flow",))
342342

343343
# Minimalistic check if the XML is useful
344-
assert type(flows_dict["oml:flows"]["oml:flow"]) == list, type(flows_dict["oml:flows"])
344+
assert isinstance(flows_dict["oml:flows"]["oml:flow"], list), type(flows_dict["oml:flows"])
345345
assert flows_dict["oml:flows"]["@xmlns:oml"] == "http://openml.org/openml", flows_dict[
346346
"oml:flows"
347347
]["@xmlns:oml"]

openml/runs/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ def __list_runs(api_call, output_format="dict"):
11391139
'"http://openml.org/openml": %s' % str(runs_dict)
11401140
)
11411141

1142-
assert type(runs_dict["oml:runs"]["oml:run"]) == list, type(runs_dict["oml:runs"])
1142+
assert isinstance(runs_dict["oml:runs"]["oml:run"], list), type(runs_dict["oml:runs"])
11431143

11441144
runs = OrderedDict()
11451145
for run_ in runs_dict["oml:runs"]["oml:run"]:

openml/setups/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def __list_setups(api_call, output_format="object"):
220220
'"%s": %s' % (openml_uri, str(setups_dict))
221221
)
222222

223-
assert type(setups_dict["oml:setups"]["oml:setup"]) == list, type(setups_dict["oml:setups"])
223+
assert isinstance(setups_dict["oml:setups"]["oml:setup"], list), type(setups_dict["oml:setups"])
224224

225225
setups = dict()
226226
for setup_ in setups_dict["oml:setups"]["oml:setup"]:

openml/study/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def __list_studies(api_call, output_format="object") -> Union[Dict, pd.DataFrame
595595
study_dict = xmltodict.parse(xml_string, force_list=("oml:study",))
596596

597597
# Minimalistic check if the XML is useful
598-
assert type(study_dict["oml:study_list"]["oml:study"]) == list, type(
598+
assert isinstance(study_dict["oml:study_list"]["oml:study"], list), type(
599599
study_dict["oml:study_list"]
600600
)
601601
assert study_dict["oml:study_list"]["@xmlns:oml"] == "http://openml.org/openml", study_dict[

openml/tasks/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def __list_tasks(api_call, output_format="dict"):
246246
'"http://openml.org/openml": %s' % str(tasks_dict)
247247
)
248248

249-
assert type(tasks_dict["oml:tasks"]["oml:task"]) == list, type(tasks_dict["oml:tasks"])
249+
assert isinstance(tasks_dict["oml:tasks"]["oml:task"], list), type(tasks_dict["oml:tasks"])
250250

251251
tasks = dict()
252252
procs = _get_estimation_procedure_list()

openml/tasks/split.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, name, description, split):
4343

4444
def __eq__(self, other):
4545
if (
46-
type(self) != type(other)
46+
(not isinstance(self, type(other)))
4747
or self.name != other.name
4848
or self.description != other.description
4949
or self.split.keys() != other.split.keys()

tests/test_runs/test_run_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _assert_predictions_equal(self, predictions, predictions_prime):
150150
for col_idx in compare_slice:
151151
val_1 = predictions["data"][idx][col_idx]
152152
val_2 = predictions_prime["data"][idx][col_idx]
153-
if type(val_1) == float or type(val_2) == float:
153+
if isinstance(val_1, float) or isinstance(val_2, float):
154154
self.assertAlmostEqual(
155155
float(val_1),
156156
float(val_2),

0 commit comments

Comments
 (0)