Skip to content
Merged
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
17 changes: 2 additions & 15 deletions src/post_processing/utils/core_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,6 @@ def get_count(
def get_labels_and_annotators(df: DataFrame) -> tuple[list, list]:
"""Extract and align annotation labels and annotators from an APLOSE DataFrame.

If only one label is present, it is duplicated to match the number of annotators.
Similarly, if one annotator is present, it is duplicated to match the labels.

Parameters
----------
df : DataFrame
Expand All @@ -397,18 +394,8 @@ def get_labels_and_annotators(df: DataFrame) -> tuple[list, list]:
msg = "`df` contains no data"
raise ValueError(msg)

annotators = df["annotator"].unique().tolist()
labels = df["annotation"].unique().tolist()
if len(labels) == 1:
labels = [labels[0]] * len(annotators)
if len(annotators) == 1:
annotators = [annotators[0]] * len(labels)

if len(annotators) != len(labels):
msg = f"{len(annotators)} annotators and {len(labels)} labels must match."
raise ValueError(msg)

return labels, annotators
unique_pairs = df[["annotator", "annotation"]].drop_duplicates()
return unique_pairs["annotation"].to_list(), unique_pairs["annotator"].to_list()


def localize_timestamps(timestamps: list[Timestamp], tz: tzinfo) -> list[Timestamp]:
Expand Down
9 changes: 0 additions & 9 deletions tests/test_core_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,6 @@ def test_single_annotator_multiple_labels(sample_df: DataFrame) -> None:
assert sorted(annotators) == ["ann1"] * 2


def test_mismatched_labels_and_annotators() -> None:
df = DataFrame({
"annotation": ["lbl1", "lbl2", "lbl3"],
"annotator": ["ann1", "ann2", "ann2"],
})
with pytest.raises(ValueError, match="annotators and .* labels must match"):
get_labels_and_annotators(df)


def test_get_labels_and_annotators_empty_dataframe() -> None:
with pytest.raises(ValueError, match="`df` contains no data"):
get_labels_and_annotators(DataFrame())
Expand Down