Skip to content

Commit

Permalink
Merge pull request #11 from liamdugan/fix_evaluate
Browse files Browse the repository at this point in the history
Fix `run_evaluation` bug
  • Loading branch information
liamdugan authored Sep 11, 2024
2 parents f900e6d + d5345ae commit 6625fc6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion raid/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.6"
__version__ = "0.0.7"
7 changes: 5 additions & 2 deletions raid/detect.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
def run_detection(f, df):
# Make a copy of the IDs of the original dataframe to avoid editing in place
scores_df = df[["id"]].copy()

# Run the detector function on the dataset and put output in score column
df["score"] = f(df["generation"])
scores_df["score"] = f(df["generation"])

# Convert scores and ids to dict in 'records' format for seralization
# e.g. [{'id':'...', 'score':0}, {'id':'...', 'score':1}, ...]
results = df[["id", "score"]].to_dict(orient="records")
results = scores_df[["id", "score"]].to_dict(orient="records")

return results
4 changes: 4 additions & 0 deletions raid/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def load_detection_result(df, results):
# Load the dataframe and read in the scores
scores_df = pd.DataFrame.from_records(results)

# If df has a pre-existing score column, remove it before merging
if "score" in df.columns:
df = df.drop(columns=["score"])

# Merge dataframes based on the id and validate that ids are unique
return df.join(scores_df.set_index("id"), on="id", validate="one_to_one")

Expand Down

0 comments on commit 6625fc6

Please sign in to comment.