Skip to content

Commit

Permalink
Fix MR H&S for proportions, and support with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodan-ilic committed Mar 26, 2018
1 parent db354d7 commit d418bcd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/cr/cube/crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,11 @@ def _mr_proportions(self, axis, weighted, include_transforms_for_dims=None):

# The following are normal MR x something (not CA)
if axis == 1:
return self.as_array() / self.margin(axis=1)[:, np.newaxis]
num = self.as_array(
include_transforms_for_dims=include_transforms_for_dims
)
den = self.margin(axis=1)[:, np.newaxis]
return num / den
else:
res = table[:, 0, :] / (table[:, 0, :] + table[:, 1, :])
elif self.mr_dim_ind == 1:
Expand Down
20 changes: 19 additions & 1 deletion tests/integration/test_headers_and_subtotals.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,29 @@ def test_mr_x_cat_hs_counts(self):
actual = cube.as_array(include_transforms_for_dims=[0, 1])
np.testing.assert_array_equal(actual, expected)

def test_mr_x_cat_hs_props(self):
def test_mr_x_cat_hs_props_by_cell(self):
cube = CrunchCube(PETS_X_FRUIT_HS)
# TODO: Change expectation once the MR cell props are fixed.
expected = (3, 3)
actual = cube.proportions(
axis=None, include_transforms_for_dims=[0, 1]
).shape
np.testing.assert_array_equal(actual, expected)

def test_mr_x_cat_hs_props_by_row(self):
cube = CrunchCube(PETS_X_FRUIT_HS)
# TODO: Change expectation once the MR cell props are fixed.
expected = (3, 3)
actual = cube.proportions(
axis=0, include_transforms_for_dims=[0, 1]
).shape
np.testing.assert_array_equal(actual, expected)

def test_mr_x_cat_hs_props_by_col(self):
cube = CrunchCube(PETS_X_FRUIT_HS)
# TODO: Change expectation once the MR cell props are fixed.
expected = (3, 3)
actual = cube.proportions(
axis=1, include_transforms_for_dims=[0, 1]
).shape
np.testing.assert_array_equal(actual, expected)

0 comments on commit d418bcd

Please sign in to comment.