Skip to content

Commit

Permalink
Use isinstance instead of type
Browse files Browse the repository at this point in the history
  • Loading branch information
AmenRa committed Sep 2, 2023
1 parent f2dde80 commit dbd50b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ranx/meta/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def compare(
Report: See report.
"""
metrics = format_metrics(metrics)
assert all(type(m) == str for m in metrics), "Metrics error"
assert all(isinstance(m, str) for m in metrics), "Metrics error"

model_names = []
results = defaultdict(dict)
Expand Down
8 changes: 4 additions & 4 deletions ranx/meta/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def format_metrics(metrics: Union[List[str], str]) -> List[str]:
if type(metrics) == str:
if isinstance(metrics, str):
metrics = [metrics]
return metrics

Expand Down Expand Up @@ -43,15 +43,15 @@ def extract_metric_and_params(metric):
def convert_qrels(qrels):
if type(qrels) == Qrels:
return qrels.to_typed_list()
elif type(qrels) == dict:
elif isinstance(qrels, dict):
return python_dict_to_typed_list(qrels, sort=True)
return qrels


def convert_run(run):
if type(run) == Run:
return run.to_typed_list()
elif type(run) == dict:
elif isinstance(run, dict):
return python_dict_to_typed_list(run, sort=True)
return run

Expand Down Expand Up @@ -133,7 +133,7 @@ def evaluate(
_qrels = convert_qrels(qrels)
_run = convert_run(run)
metrics = format_metrics(metrics)
assert all(type(m) == str for m in metrics), "Metrics error"
assert all(isinstance(m, str) for m in metrics), "Metrics error"

# Compute metrics ----------------------------------------------------------
metric_scores_dict = {}
Expand Down
2 changes: 1 addition & 1 deletion ranx/meta/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def plot(

_qrels = qrels.to_typed_list()

if type(runs) == list:
if isinstance(runs, list):
_runs = [run.to_typed_list() for run in runs]
names = [
run.name if run.name is not None else f"run_{i+1}"
Expand Down

0 comments on commit dbd50b1

Please sign in to comment.