Coverage for src/extratools_core/tabletools.py: 0%

6 statements  

« prev     ^ index     » next       coverage.py v7.8.1, created at 2025-05-23 02:47 -0700

1from collections.abc import Iterable, Sequence 

2from itertools import combinations 

3 

4from toolz import isdistinct 

5 

6from .itertools import filter_by_others 

7 

8 

9def candidate_keys[T]( 

10 cols: Sequence[Sequence[T]], 

11 *, 

12 max_cols: int = 1, 

13) -> Iterable[tuple[int, ...]]: 

14 return map(tuple, filter_by_others( 

15 # Note that `x > y` (means x is superset of any y) is different from 

16 # `not x <= y` (means x is not subset of any y) 

17 lambda x, y: not x <= y, 

18 map(set, ( 

19 col_ids 

20 for i in range(1, max_cols + 1) 

21 for col_ids in combinations(range(len(cols)), i) 

22 if isdistinct(zip(*[cols[col_id] for col_id in col_ids], strict=True)) 

23 )), 

24 ))