Skip to content

Commit

Permalink
Merge branch 'index-not-defined-for-col-direction-154248138' into rel…
Browse files Browse the repository at this point in the history
…-4.2.15
  • Loading branch information
Crunch.io Jenkins Account committed Jan 23, 2018
2 parents ae049a0 + 0647d56 commit 86bcc3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
11 changes: 5 additions & 6 deletions src/cr/cube/crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,8 @@ def _mr_index(self, axis, weighted):

if self.dimensions[0].type == 'multiple_response':
if axis != 0:
raise ValueError(
'MR x CAT index table only defined for column direction'
)
# MR x CAT index table only defined for column direction.
return np.full(self.as_array().shape, np.nan)
selected = (
table[:, 0, :, 0]
if self.is_double_mr else
Expand All @@ -889,9 +888,9 @@ def _mr_index(self, axis, weighted):

if self.dimensions[1].type == 'multiple_response':
if axis == 0:
raise ValueError(
'CAT x MR index table not defined for column direction'
)
# CAT x MR index table not defined for column direction.
return np.full(self.as_array().shape, np.nan)

selected = table[:, :, 0]
non_selected = table[:, :, 1]
margin = np.sum(selected, 0) / np.sum(selected + non_selected, 0)
Expand Down
23 changes: 11 additions & 12 deletions tests/integration/test_crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1823,10 +1823,9 @@ def test_cat_x_mr_index_by_cell(self):

def test_cat_x_mr_index_by_col(self):
cube = CrunchCube(FIXT_CAT_X_MR)
with self.assertRaises(ValueError) as ctx:
cube.index(axis=0)
expected = 'CAT x MR index table not defined for column direction'
self.assertEqual(ctx.exception.args[0], expected)
expected = np.full(cube.as_array().shape, np.nan)
actual = cube.index(axis=0)
np.testing.assert_array_equal(actual, expected)

def test_mr_x_cat_index_by_col(self):
cube = CrunchCube(FIXT_PETS_X_FRUIT)
Expand All @@ -1840,17 +1839,17 @@ def test_mr_x_cat_index_by_col(self):

def test_mr_x_cat_index_by_row(self):
cube = CrunchCube(FIXT_PETS_X_FRUIT)
with self.assertRaises(ValueError) as ctx:
cube.index(axis=1)
expected = 'MR x CAT index table only defined for column direction'
self.assertEqual(ctx.exception.args[0], expected)
expected = np.full(cube.as_array().shape, np.nan)
# with self.assertRaises(ValueError) as ctx:
actual = cube.index(axis=1)
np.testing.assert_array_equal(actual, expected)

def test_mr_x_cat_index_by_cell(self):
cube = CrunchCube(FIXT_PETS_X_FRUIT)
with self.assertRaises(ValueError) as ctx:
cube.index(axis=None)
expected = 'MR x CAT index table only defined for column direction'
self.assertEqual(ctx.exception.args[0], expected)
expected = np.full(cube.as_array().shape, np.nan)
# with self.assertRaises(ValueError) as ctx:
actual = cube.index(axis=None)
np.testing.assert_array_equal(actual, expected)

def test_mr_x_mr_index_by_col(self):
cube = CrunchCube(FIXT_PETS_X_PETS)
Expand Down

0 comments on commit 86bcc3b

Please sign in to comment.