seer-pas-sdk 0.1.3__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ def validate_contrast(contrast, ngroups):
2
+ """
3
+ Validate the contrast.
4
+
5
+ Parameters
6
+ ----------
7
+ contrast : list or tuple
8
+ The contrast to validate.
9
+
10
+ ngroups : int
11
+ The number of groups in the contrast.
12
+
13
+ Returns
14
+ -------
15
+ list
16
+ The validated contrast.
17
+
18
+ Raises
19
+ ------
20
+ TypeError
21
+ If contrast is not a list or tuple.
22
+ If contrast is not a collection of integers.
23
+ ValueError
24
+ If contrast has less than 2 elements.
25
+ If contrast does not have the same number of elements as ngroups.
26
+ If contrast is not a list of -1, 0, or 1.
27
+ If contrast does not have exactly one 1.
28
+ If contrast does not have exactly one -1.
29
+ """
30
+ if not isinstance(contrast, (list, tuple)):
31
+ raise TypeError("contrast must be a list or tuple")
32
+ if len(contrast) < 2:
33
+ raise ValueError("contrast must have at least 2 elements")
34
+ if not all(isinstance(i, int) for i in contrast):
35
+ raise TypeError("contrast must be a list of integers")
36
+ if not len(contrast) == ngroups:
37
+ raise ValueError(f"contrast {contrast} must have {ngroups} elements")
38
+ if not all([i in range(-1, 2) for i in contrast]):
39
+ raise ValueError(f"contrast {contrast} must be a list of -1, 0, or 1")
40
+
41
+ # Check that the contrast has exactly one 1 and one -1
42
+ count_1 = 0
43
+ count_neg1 = 0
44
+
45
+ for item in contrast:
46
+ if item == 1:
47
+ count_1 += 1
48
+ elif item == -1:
49
+ count_neg1 += 1
50
+
51
+ if count_1 != 1:
52
+ raise ValueError(f"contrast {contrast} must have exactly one 1")
53
+ if count_neg1 != 1:
54
+ raise ValueError(f"contrast {contrast} must have exactly one -1")
55
+ return contrast