Skip to content

Commit

Permalink
Fix labels to validate exported as floats (#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
J535D165 committed Jan 5, 2024
1 parent 07ec269 commit bc8558d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions asreview/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,19 @@ def to_dataframe(self, labels=None, ranking=None, keep_old_labels=False):

# if there are labels, add them to the frame
if labels is not None:
# unnest the nested (record_id, label) tuples
# unnest list of nested (record_id, label) tuples
labeled_record_ids = [x[0] for x in labels]
labeled_values = [x[1] for x in labels]

if keep_old_labels:
result_df["asreview_label_to_validate"] = result_df[col_label]
result_df["asreview_label_to_validate"] = \
result_df[col_label].replace(LABEL_NA, None).astype("Int64")

# remove the old results and write the values
result_df[col_label] = LABEL_NA
result_df.loc[labeled_record_ids, col_label] = labeled_values
result_df[col_label] = result_df[col_label] \
.replace(LABEL_NA, None).astype("Int64")

# if there is a ranking, apply this ranking as order
if ranking is not None:
Expand All @@ -494,11 +497,6 @@ def to_dataframe(self, labels=None, ranking=None, keep_old_labels=False):
# append a column with 1 to n
result_df["asreview_ranking"] = np.arange(1, len(result_df) + 1)

# replace labeled NA values by np.nan
if col_label in list(result_df):
result_df[col_label] = result_df[col_label].astype(object)
result_df.loc[result_df[col_label] == LABEL_NA, col_label] = np.nan

return result_df

def duplicated(self, pid="doi"):
Expand Down
2 changes: 1 addition & 1 deletion asreview/webapp/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ def api_export_dataset(project):
if "asreview_prior" in as_data.df:
as_data.df.drop("asreview_prior", axis=1, inplace=True)

state_df["asreview_prior"] = state_df.query_strategy.eq("prior").astype(int)
state_df["asreview_prior"] = state_df.query_strategy.eq("prior").astype("Int64")
as_data.df = as_data.df.join(state_df["asreview_prior"], on="record_id")

# Adding Notes from State file to the exported dataset
Expand Down

0 comments on commit bc8558d

Please sign in to comment.