Skip to content

Commit e7ac6c7

Browse files
committed
Helper function to show as log repeated labels in Matrix exception
1 parent c64ad64 commit e7ac6c7

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/diffupy/matrix.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import numpy as np
99

10-
from .utils import get_label_ix_mapping, get_label_list_graph, get_laplacian, decode_labels, get_idx_scores_mapping
10+
from .utils import get_label_ix_mapping, get_label_list_graph, get_laplacian, decode_labels, get_idx_scores_mapping, \
11+
get_repeated_labels
1112

1213
log = logging.getLogger(__name__)
1314

@@ -117,7 +118,8 @@ def validate_labels(self):
117118
if self.rows_labels:
118119
self.rows_labels = decode_labels(self.rows_labels)
119120
if len(self.rows_labels) != len(set(self.rows_labels)):
120-
raise Exception('Duplicate row labels in Matrix.')
121+
dup = get_repeated_labels(self.rows_labels)
122+
raise Exception('Duplicate row labels in Matrix. /n duplicated number: {} /n duplicated list: {}'.format(len(dup), dup))
121123

122124
if hasattr(self, '_cols_labels'):
123125
self._cols_labels = decode_labels(self.cols_labels)

src/diffupy/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ def get_label_list_graph(graph: nx.Graph, label: str) -> List:
8585
raise Warning('Could not get a label list from graph.')
8686

8787

88+
def get_repeated_labels(labels):
89+
90+
seen = set()
91+
rep = []
92+
for x in labels:
93+
if x in seen:
94+
rep.append(x)
95+
seen.add(x)
96+
97+
return rep
98+
99+
88100
def get_label_ix_mapping(labels):
89101
"""Get label to mat index mappings."""
90102
return {label: i for i, label in enumerate(labels)}

0 commit comments

Comments
 (0)