Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust keep_cols logic #109

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crossfit/data/sparse/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ def to_pytrec(self, is_run=False):

qrel = {}
for i in range(self.indices.shape[0]):
query_id = f"q{i+1}"
query_id = f"q{i + 1}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qrel[query_id] = {}

row = sparse_matrix[i]
for j, score in zip(row.indices, row.data):
doc_id = f"d{j+1}"
doc_id = f"d{j + 1}"
qrel[query_id][doc_id] = int(score) if is_run else float(score)

return qrel
Expand Down
5 changes: 5 additions & 0 deletions crossfit/op/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def __init__(
suffix: str = "labels",
axis=-1,
):
if keep_cols is not None and suffix in keep_cols:
# suffix is already kept as a column
# and will raise an error if it is in keep_cols
keep_cols.remove(suffix)

super().__init__(pre=pre, cols=cols, keep_cols=keep_cols)
self.labels = labels
self.suffix = suffix
Expand Down
6 changes: 3 additions & 3 deletions examples/dask_aggregate_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
t0 = time.time()
result = aggregate(ddf, agg, to_frame=True)
tf = time.time()
print(f"\nWall Time: {tf-t0} seconds\n")
print(f"\nWall Time: {tf - t0} seconds\n")

# View result
print(f"Result:\n{result}\n")
Expand All @@ -76,12 +76,12 @@
t0 = time.time()
std = ddf.groupby(groupby).std().compute()
tf = time.time()
print(f"\nddf.groupby().std() takes {tf-t0} seconds, and returns:\n")
print(f"\nddf.groupby().std() takes {tf - t0} seconds, and returns:\n")
print(f"\n{std}\n")
else:
# Compare to ddf.std()
t0 = time.time()
std = ddf.std().compute()
tf = time.time()
print(f"\nddf.std() takes {tf-t0} seconds, and returns:\n")
print(f"\nddf.std() takes {tf - t0} seconds, and returns:\n")
print(f"\n{std}\n")
10 changes: 5 additions & 5 deletions tests/pytrec_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def create_qrel(relevance_scores, ids=None):

qrel = {}
for i, query_scores in enumerate(relevance_scores):
query_id = ids[i] if ids is not None else f"q{i+1}"
query_id = ids[i] if ids is not None else f"q{i + 1}"
qrel[query_id] = {}
for j, score in enumerate(query_scores):
_score = int(score.item())

if _score > 0:
doc_id = f"d{j+1}"
doc_id = f"d{j + 1}"
qrel[query_id][doc_id] = int(score.item())

return qrel
Expand All @@ -41,10 +41,10 @@ def create_run(predicted_scores, ids=None):

run = {}
for i, query_scores in enumerate(predicted_scores):
query_id = ids[i] if ids is not None else f"q{i+1}"
query_id = ids[i] if ids is not None else f"q{i + 1}"
run[query_id] = {}
for j, score in enumerate(query_scores):
doc_id = f"d{j+1}"
doc_id = f"d{j + 1}"
run[query_id][doc_id] = float(score.item())

return run
Expand All @@ -60,6 +60,6 @@ def create_results(metric_arrays):
for k, v in metric_arrays.items():
q_out[k] = float(v[i])

outputs[f"q{i+1}"] = q_out
outputs[f"q{i + 1}"] = q_out

return outputs
Loading