Skip to content

Commit 161e9e9

Browse files
[178390751]: address comments 2part
1 parent ae30eb1 commit 161e9e9

File tree

11 files changed

+399
-300
lines changed

11 files changed

+399
-300
lines changed

src/cr/cube/cube.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -233,48 +233,6 @@ def __repr__(self):
233233
except Exception:
234234
return super(Cube, self).__repr__()
235235

236-
@lazyproperty
237-
def alpha_values(self):
238-
"""Pair (tuple) of confidence-interval thresholds to be used for t-tests.
239-
240-
The second value is optional and is None when no secondary alpha value was
241-
defined for the cube-set.
242-
"""
243-
value = self._transforms_dict.get("pairwise_indices", {}).get("alpha")
244-
245-
# --- handle omitted, None, [], (), {}, "", 0, and 0.0 cases ---
246-
if not value:
247-
return (0.05, None)
248-
249-
# --- reject invalid types ---
250-
if not isinstance(value, (float, list, tuple)):
251-
raise TypeError(
252-
"transforms.pairwise_indices.alpha, when defined, must be a list of 1 "
253-
"or 2 float values between 0.0 and 1.0 exclusive. Got %r" % value
254-
)
255-
256-
# --- legacy float "by-itself" case ---
257-
if isinstance(value, float):
258-
if not 0.0 < value < 1.0:
259-
raise ValueError(
260-
"alpha value, when provided, must be between 0.0 and 1.0 "
261-
"exclusive. Got %r" % value
262-
)
263-
return (value, None)
264-
265-
# --- sequence case ---
266-
for x in value[:2]:
267-
if not isinstance(x, float) or not 0.0 < x < 1.0:
268-
raise ValueError(
269-
"transforms.pairwise_indices.alpha must be a list of 1 or 2 float "
270-
"values between 0.0 and 1.0 exclusive. Got %r" % value
271-
)
272-
273-
if len(value) == 1:
274-
return (value[0], None)
275-
276-
return tuple(sorted(value[:2]))
277-
278236
@lazyproperty
279237
def available_measures(self):
280238
"""frozenset of available CUBE_MEASURE members in the cube response."""
@@ -431,21 +389,6 @@ def n_responses(self):
431389
"""Total (int) number of responses considered."""
432390
return self._cube_response["result"].get("n", 0)
433391

434-
@lazyproperty
435-
def only_larger(self):
436-
"""True if only the larger of reciprocal pairwise-t values should appear.
437-
438-
In general, pairwise-t tests are reciprocal. That is, if A is significant with
439-
respect to B, then B is significant with respect to A. Having a letter in both
440-
columns can produce a cluttered appearance. When this flag is set by the user,
441-
only the cell in the reciprocal pair having the largest value gets a letter.
442-
Defaults to True unless explicitly set False.
443-
"""
444-
only_larger_value = self._transforms_dict.get("pairwise_indices", {}).get(
445-
"only_larger"
446-
)
447-
return only_larger_value is not False
448-
449392
@lazyproperty
450393
def overlaps(self):
451394
"""Optional float64 ndarray of cube_overlaps if the measure exists.

src/cr/cube/cubepart.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,6 @@ def variable_name(self):
143143
"""str representing the name of the superheading variable."""
144144
return self._dimensions[0 if self.ndim < 2 else 1].name
145145

146-
@lazyproperty
147-
def _alpha(self):
148-
"""float confidence-interval threshold for pairwise-t (sig) tests."""
149-
# TODO: remove me when summary_pairwise_indices, summary_p_vals and
150-
# summary_t_stats will be moved from measures/pairwise_significance.py to
151-
# matrix/measures.py
152-
return self._cube.alpha_values[0]
153-
154-
@lazyproperty
155-
def _alpha_alt(self):
156-
"""Alternate float confidence-interval threshold or None.
157-
158-
This is an optional secondary confidence interval allowing two-level
159-
significance testing. Value is None if no alternate alpha was specified by user.
160-
"""
161-
# TODO: remove me when summary_pairwise_indices, summary_p_vals and
162-
# summary_t_stats will be moved from measures/pairwise_significance.py to
163-
# matrix/measures.py
164-
return self._cube.alpha_values[1]
165-
166146
@lazyproperty
167147
def _available_measures(self):
168148
"""sorted list of available CUBE_MEASURE members in the cube response."""
@@ -183,21 +163,6 @@ def _dimensions(self):
183163
"must be implemented by each subclass"
184164
) # pragma: no cover
185165

186-
@lazyproperty
187-
def _only_larger(self):
188-
"""True if only the larger of reciprocal pairwise-t values should appear.
189-
190-
In general, pairwise-t tests are reciprocal. That is, if A is significant with
191-
respect to B, then B is significant with respect to A. Having a letter in both
192-
columns can produce a cluttered appearance. When this flag is set by the user,
193-
only the cell in the reciprocal pair having the largest value gets a letter.
194-
Defaults to True unless explicitly set False.
195-
"""
196-
# TODO: remove me when summary_pairwise_indices, summary_p_vals and
197-
# summary_t_stats will be moved from measures/pairwise_significance.py to
198-
# matrix/measures.py
199-
return self._cube.only_larger
200-
201166
@lazyproperty
202167
def _transforms_dict(self):
203168
"""dict holding transforms for this partition, provided as `transforms` arg.
@@ -1236,6 +1201,26 @@ def zscores(self):
12361201

12371202
# ---implementation (helpers)-------------------------------------
12381203

1204+
@lazyproperty
1205+
def _alpha(self):
1206+
"""float confidence-interval threshold for pairwise-t (sig) tests."""
1207+
# TODO: remove me when summary_pairwise_indices, summary_p_vals and
1208+
# summary_t_stats will be moved from measures/pairwise_significance.py to
1209+
# matrix/measures.py
1210+
return self._columns_dimension.pairwise_significance_spec.alpha_values[0]
1211+
1212+
@lazyproperty
1213+
def _alpha_alt(self):
1214+
"""Alternate float confidence-interval threshold or None.
1215+
1216+
This is an optional secondary confidence interval allowing two-level
1217+
significance testing. Value is None if no alternate alpha was specified by user.
1218+
"""
1219+
# TODO: remove me when summary_pairwise_indices, summary_p_vals and
1220+
# summary_t_stats will be moved from measures/pairwise_significance.py to
1221+
# matrix/measures.py
1222+
return self._columns_dimension.pairwise_significance_spec.alpha_values[1]
1223+
12391224
@lazyproperty
12401225
def _assembler(self):
12411226
"""The Assembler object for this slice.
@@ -1279,6 +1264,21 @@ def _dimensions(self):
12791264
)
12801265
)
12811266

1267+
@lazyproperty
1268+
def _only_larger(self):
1269+
"""True if only the larger of reciprocal pairwise-t values should appear.
1270+
1271+
In general, pairwise-t tests are reciprocal. That is, if A is significant with
1272+
respect to B, then B is significant with respect to A. Having a letter in both
1273+
columns can produce a cluttered appearance. When this flag is set by the user,
1274+
only the cell in the reciprocal pair having the largest value gets a letter.
1275+
Defaults to True unless explicitly set False.
1276+
"""
1277+
# TODO: remove me when summary_pairwise_indices, summary_p_vals and
1278+
# summary_t_stats will be moved from measures/pairwise_significance.py to
1279+
# matrix/measures.py
1280+
return self._columns_dimension.pairwise_significance_spec.only_larger
1281+
12821282
@lazyproperty
12831283
def _row_variance(self):
12841284
"""2D np.float64 ndarray of row-percentage variance for each cell."""

src/cr/cube/dimension.py

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,23 +967,84 @@ def __init__(self, dimension, dimension_transforms_dict):
967967
self._dimension_transforms_dict = dimension_transforms_dict
968968

969969
@lazyproperty
970-
def column_idx(self):
970+
def alpha_values(self):
971+
"""Pair (tuple) of confidence-interval thresholds to be used for t-tests.
972+
973+
The second value is optional and is None when no secondary alpha value was
974+
defined for the cube-set.
975+
"""
976+
value = self._pairwise_sig_dict.get("pairwise_indices", {}).get("alpha")
977+
978+
# --- handle omitted, None, [], (), {}, "", 0, and 0.0 cases ---
979+
if not value:
980+
return (0.05, None)
981+
982+
# --- reject invalid types ---
983+
if not isinstance(value, (float, list, tuple)):
984+
raise TypeError(
985+
"transforms.pairwise_indices.alpha, when defined, must be a list of 1 "
986+
"or 2 float values between 0.0 and 1.0 exclusive. Got %r" % value
987+
)
988+
989+
# --- legacy float "by-itself" case ---
990+
if isinstance(value, float):
991+
if not 0.0 < value < 1.0:
992+
raise ValueError(
993+
"alpha value, when provided, must be between 0.0 and 1.0 "
994+
"exclusive. Got %r" % value
995+
)
996+
return (value, None)
997+
998+
# --- sequence case ---
999+
for x in value[:2]:
1000+
if not isinstance(x, float) or not 0.0 < x < 1.0:
1001+
raise ValueError(
1002+
"transforms.pairwise_indices.alpha must be a list of 1 or 2 float "
1003+
"values between 0.0 and 1.0 exclusive. Got %r" % value
1004+
)
1005+
1006+
if len(value) == 1:
1007+
return (value[0], None)
1008+
1009+
return tuple(sorted(value[:2]))
1010+
1011+
@lazyproperty
1012+
def only_larger(self):
1013+
"""True if only the larger of reciprocal pairwise-t values should appear.
1014+
1015+
In general, pairwise-t tests are reciprocal. That is, if A is significant with
1016+
respect to B, then B is significant with respect to A. Having a letter in both
1017+
columns can produce a cluttered appearance. When this flag is set by the user,
1018+
only the cell in the reciprocal pair having the largest value gets a letter.
1019+
Defaults to True unless explicitly set False.
1020+
"""
1021+
only_larger_value = self._pairwise_sig_dict.get("pairwise_indices", {}).get(
1022+
"only_larger"
1023+
)
1024+
return only_larger_value is not False
1025+
1026+
@lazyproperty
1027+
def reference_column_idx(self):
9711028
"""Optional int index of base column as reference for the pairwise sig tests."""
9721029
column_significance = self._pairwise_sig_dict.get("column_significance", {})
9731030
if column_significance is not None:
9741031
return column_significance.get("column_idx")
9751032
return None
9761033

9771034
@lazyproperty
978-
def insertion_idx(self):
1035+
def reference_insertion_idx(self):
9791036
"""Optional int index of insertion column as reference for the sig tests."""
9801037
if self._insertion_id:
9811038
return self._dimension.insertion_ids.index(self._insertion_id)
9821039
return None
9831040

9841041
@lazyproperty
9851042
def _insertion_id(self):
986-
"""int insertion-id in the "insertion_id" field of the transform dict."""
1043+
"""int insertion-id in the "insertion_id" field of the transform dict.
1044+
1045+
Identifies the reference column when the reference column is an insertion rather
1046+
than a `base` column.
1047+
"""
9871048
column_significance = self._pairwise_sig_dict.get("column_significance", {})
9881049
if column_significance is not None:
9891050
return column_significance.get("insertion_id")

0 commit comments

Comments
 (0)