Skip to content

Commit

Permalink
fix: coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodan-ilic committed Mar 23, 2021
1 parent a5e08b5 commit b52419f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cr/cube/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def valid_overlaps(self):
the extra subvariables dimension as the last dimension.
"""
if self._measures.valid_overlaps is None:
return None
return None # pragma: no cover
return self._measures.valid_overlaps.raw_cube_array[self._valid_idxs].astype(
np.float64
)
Expand Down
12 changes: 10 additions & 2 deletions src/cr/cube/cubepart.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,11 @@ def pairwise_significance_t_stats(self):
"""

# If overlaps are defined, calculate significance based on them
if self.dimension_types[-1] == DT.MR and self._cube.overlaps is not None:
if (
self.dimension_types[-1] == DT.MR
and self._cube.overlaps is not None
and self._cube.valid_overlaps is not None
):
return self._assembler.pairwise_significance_t_stats

# Wrap the legacy objects in a 3D ndarray, so that's interpretable by exporter
Expand All @@ -639,7 +643,11 @@ def pairwise_significance_p_vals(self):
"""

# If overlaps are defined, calculate significance based on them
if self.dimension_types[-1] == DT.MR and self._cube.overlaps is not None:
if (
self.dimension_types[-1] == DT.MR
and self._cube.overlaps is not None
and self._cube.valid_overlaps is not None
):
return self._assembler.pairwise_significance_p_vals

# Wrap the legacy objects in a 3D ndarray, so that's interpretable by exporter
Expand Down
8 changes: 6 additions & 2 deletions src/cr/cube/matrix/cubemeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,13 @@ def factory(cls, cube, dimensions, slice_idx):
Raises `ValueError` if the cube-result does not include a cube-means measure.
"""
if cube.overlaps is None:
raise ValueError("cube-result does not contain cube-overlaps measure")
raise ValueError(
"cube-result does not contain cube-overlaps measure"
) # pragma: no cover
if cube.valid_overlaps is None:
raise ValueError("cube-result does not contain cube-valid-overlaps measure")
raise ValueError(
"cube-result does not contain cube-valid-overlaps measure"
) # pragma: no cover
return _CatXMrOverlaps(
dimensions,
cube.overlaps[cls._slice_idx_expr(cube, slice_idx)],
Expand Down
45 changes: 45 additions & 0 deletions tests/integration/test_pairwise_significance.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ def test_ca_subvar_hs_x_cat_hs_pairwise_t_tests(self):
np.testing.assert_array_almost_equal(
actual.p_vals, load_python_expression("ca-subvar-hs-x-cat-hs-pw-pvals")
)
# check new api also
np.testing.assert_array_almost_equal(
slice_.pairwise_significance_t_stats[1],
load_python_expression("ca-subvar-hs-x-cat-hs-pw-tstats"),
)
np.testing.assert_array_almost_equal(
slice_.pairwise_significance_p_vals[1],
load_python_expression("ca-subvar-hs-x-cat-hs-pw-pvals"),
)

def test_cat_nps_numval_x_cat_scale_means_pariwise_t_tests(self):
slice_ = Cube(SM.CAT_NPS_NUMVAL_X_CAT).partitions[0]
Expand Down Expand Up @@ -179,6 +188,15 @@ def test_cat_x_cat_pairwise_t_tests(self):
np.testing.assert_almost_equal(
actual.p_vals, load_python_expression("cat-x-cat-pw-pvals")
)
# test new api also
np.testing.assert_almost_equal(
slice_.pairwise_significance_t_stats[2],
load_python_expression("cat-x-cat-pw-tstats"),
)
np.testing.assert_almost_equal(
slice_.pairwise_significance_p_vals[2],
load_python_expression("cat-x-cat-pw-pvals"),
)

def test_cat_x_cat_hs_pairwise_t_tests(self):
slice_ = Cube(CR.PAIRWISE_HIROTSU_ILLNESS_X_OCCUPATION_WITH_HS).partitions[0]
Expand All @@ -191,6 +209,15 @@ def test_cat_x_cat_hs_pairwise_t_tests(self):
np.testing.assert_almost_equal(
p_vals, load_python_expression("cat-x-cat-hs-pw-pvals")
)
# test new api also
np.testing.assert_almost_equal(
slice_.pairwise_significance_t_stats[0],
load_python_expression("cat-x-cat-hs-pw-tstats"),
)
np.testing.assert_almost_equal(
slice_.pairwise_significance_p_vals[0],
load_python_expression("cat-x-cat-hs-pw-pvals"),
)

def test_cat_x_cat_hs_scale_means_pairwise_t_tests(self):
slice_ = Cube(CR.PAIRWISE_HIROTSU_ILLNESS_X_OCCUPATION_WITH_HS).partitions[0]
Expand Down Expand Up @@ -301,6 +328,15 @@ def test_cat_x_cat_wgtd_pairwise_t_tests(self):
pairwise_indices,
np.array(load_python_expression("cat-x-cat-wgtd-pw-indices"), dtype=tuple),
)
# test new api also
np.testing.assert_almost_equal(
slice_.pairwise_significance_t_stats[0],
load_python_expression("cat-x-cat-wgtd-pw-tstats"),
)
np.testing.assert_almost_equal(
slice_.pairwise_significance_p_vals[0],
load_python_expression("cat-x-cat-wgtd-pw-pvals"),
)

def test_cat_x_cat_wgtd_scale_means_pariwise_t_tests(self):
slice_ = Cube(CR.CAT_X_CAT_WEIGHTED_TTESTS).partitions[0]
Expand All @@ -324,6 +360,15 @@ def test_mr_x_mr_pairwise_t_tests(self):
np.testing.assert_array_almost_equal(
actual.p_vals, load_python_expression("mr-x-mr-pw-pvals")
)
# test new api also
np.testing.assert_array_almost_equal(
slice_.pairwise_significance_t_stats[1],
load_python_expression("mr-x-mr-pw-tstats"),
)
np.testing.assert_array_almost_equal(
slice_.pairwise_significance_p_vals[1],
load_python_expression("mr-x-mr-pw-pvals"),
)


class TestOverlapsCounts(TestCase):
Expand Down

0 comments on commit b52419f

Please sign in to comment.