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

Only Print Duplicates in Error Message #226

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions thicket/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: MIT

from collections import OrderedDict, defaultdict
from collections import Counter, OrderedDict, defaultdict
import warnings

import numpy as np
Expand Down Expand Up @@ -72,10 +72,11 @@ def _check_duplicate_inner_idx(df):
"""Check for duplicate values in the innermost indices."""
for node in set(df.index.get_level_values("node")):
inner_idx_values = sorted(df.loc[node].index.tolist())
inner_idx_values_set = sorted(list(set(inner_idx_values)))
if inner_idx_values != inner_idx_values_set:
counts = Counter(inner_idx_values)
duplicates = [item for item, count in counts.items() if count > 1]
if len(duplicates) > 0:
raise DuplicateIndexError(
f"Duplicate index {set(inner_idx_values)} found in DataFrame index."
f"Duplicate indices found in DataFrame index.\n\t{duplicates}"
)

def _check_missing_hnid(df):
Expand Down
Loading