Skip to content

Commit

Permalink
Merge branch 'none-type-for-ca-x-mr-154209483' into rel-4.1.34
Browse files Browse the repository at this point in the history
  • Loading branch information
Crunch.io Jenkins Account committed Jan 12, 2018
2 parents d419375 + 3c8f522 commit 867ab5a
Show file tree
Hide file tree
Showing 8 changed files with 2,478 additions and 13 deletions.
25 changes: 21 additions & 4 deletions src/cr/cube/crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,35 @@ def _mr_proportions(self, axis, weighted):
return res[np.ix_(*valid_indices)]

if self.dimensions[0].type == 'multiple_response':
if len(table.shape) == 4:
# This is the case of MR x CA, special treatment
# Still haven'f figured out the percentages
if axis == 1:
res = (table[:, 0, :, :] /
np.sum(table[:, 0, :, :], 1))
else:
res = (table[:, 0, :, :] /
(table[:, 0, :, :] + table[:, 1, :, :]))

# The following are normal MR x something (not CA)
if axis == 1:
res = table[:, 0, :] / np.sum(table[:, 0, :], 1)[:, np.newaxis]
else:
res = table[:, 0, :] / (table[:, 0, :] + table[:, 1, :])
return res[np.ix_(*valid_indices)]

if self.dimensions[1].type == 'multiple_response':
elif self.dimensions[1].type == 'multiple_response':
if axis == 0:
res = table[:, :, 0] / np.sum(table[:, :, 0], 0)
else:
res = table[:, :, 0] / (table[:, :, 0] + table[:, :, 1])
return res[np.ix_(*valid_indices)]
elif self.dimensions[2].type == 'multiple_response':
margin = (
self.margin(axis=axis)[:, np.newaxis]
if axis == 1 else
self.margin(axis=0)
)
return self.as_array() / margin

return res[np.ix_(*valid_indices)]

def _proportions(self, axis=None, weighted=True, adjusted=False,
include_transforms_for_dims=None, include_missing=False):
Expand Down
33 changes: 25 additions & 8 deletions tests/integration/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
FIXT_CAT_X_MR = load_fixture(CUBES_DIR, 'cat-x-mr.json')
FIXT_ECON_GENDER_X_IDEOLOGY_WEIGHTED = load_fixture(
CUBES_DIR,
'econ-gender-x-ideology-weighted.json'
'econ-gender-x-ideology-weighted.json',
)
FIXT_CAT_X_CAT_GERMAN_WEIGHTED = load_fixture(CUBES_DIR,
'cat-x-cat-german-weighted.json')
FIXT_STATS_TEST = load_fixture(CUBES_DIR, 'stats_test.json')
FIXT_ECON_MEAN_AGE_BLAME_X_GENDER = load_fixture(
CUBES_DIR, 'econ-mean-age-blame-x-gender.json'
CUBES_DIR, 'econ-mean-age-blame-x-gender.json',
)
FIXT_ECON_MEAN_NO_DIMS = load_fixture(CUBES_DIR, 'econ-mean-no-dims.json')
FIXT_MR_X_CAT_PROFILES_STATS_WEIGHTED = load_fixture(
CUBES_DIR,
'mr-x-cat-profiles-stats-weighted.json'
'mr-x-cat-profiles-stats-weighted.json',
)
FIXT_ADMIT_X_DEPT_UNWEIGHTED = load_fixture(CUBES_DIR,
'admit-x-dept-unweighted.json')
Expand All @@ -55,25 +55,33 @@
FIXT_ECON_BLAME_WITH_HS = load_fixture(CUBES_DIR, 'econ-blame-with-hs.json')
FIXT_ECON_BLAME_WITH_HS_MISSING = load_fixture(
CUBES_DIR,
'econ-blame-with-hs-missing.json'
'econ-blame-with-hs-missing.json',
)
FIXT_ECON_BLAME_X_IDEOLOGY_ROW_HS = load_fixture(
CUBES_DIR,
'econ-blame-x-ideology-row-hs.json'
'econ-blame-x-ideology-row-hs.json',
)
FIXT_ECON_BLAME_X_IDEOLOGY_COL_HS = load_fixture(
CUBES_DIR,
'econ-blame-x-ideology-col-hs.json'
'econ-blame-x-ideology-col-hs.json',
)
FIXT_ECON_BLAME_X_IDEOLOGY_ROW_AND_COL_HS = load_fixture(
CUBES_DIR,
'econ-blame-x-ideology-row-and-col-hs.json'
'econ-blame-x-ideology-row-and-col-hs.json',
)
FIXT_SIMPLE_CA_HS = load_fixture(CUBES_DIR, 'simple-ca-hs.json')
FIXT_FRUIT_X_PETS = load_fixture(CUBES_DIR, 'fruit-x-pets.json')
FIXT_ECON_US_PROBLEM_X_BIGGER_PROBLEM = load_fixture(
CUBES_DIR,
'econ-us-problem-x-bigger-problem.json'
'econ-us-problem-x-bigger-problem.json',
)
FIXT_PETS_ARRAY_X_PETS = load_fixture(
CUBES_DIR,
'pets-array-x-pets.json',
)
FIXT_PETS_X_PETS_ARRAY = load_fixture(
CUBES_DIR,
'pets-x-pets-array.json',
)
FIXT_FRUIT_X_PETS_ARRAY = load_fixture(
CUBES_DIR,
Expand All @@ -85,3 +93,12 @@
)
FIXT_CA_SINGLE_CAT = load_fixture(CUBES_DIR, 'cat-arr-with-single-cat.json')
FIXT_MR_X_SINGLE_WAVE = load_fixture(CUBES_DIR, 'mr-x-single-wave.json')
FIXT_SELECTED_3_WAY_2 = load_fixture(
CUBES_DIR,
'selected-3way-2-filledmissing.json'
)
FIXT_SELECTED_3_WAY = load_fixture(
CUBES_DIR,
'selected-3way-filledmissing.json'
)
FIXT_ARRAY_X_MR = load_fixture(CUBES_DIR, 'array-by-mr.json')
Loading

0 comments on commit 867ab5a

Please sign in to comment.