Skip to content

Commit

Permalink
Merge 50ce06b into e1d5046
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodan-ilic committed Aug 9, 2018
2 parents e1d5046 + 50ce06b commit a5c63ca
Show file tree
Hide file tree
Showing 4 changed files with 725 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/cr/cube/measures/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,29 @@ def prune(self):
@lazyproperty
def data(self):
'''Return table index by margin.'''
if self.cube.has_mr:
return self._mr_index()
margin = (
self.cube.margin(axis=0, weighted=self.weighted, prune=self.prune) /
self.cube.margin(weighted=self.weighted, prune=self.prune)
)
proportions = self.cube.proportions(
axis=1, weighted=self.weighted, prune=self.prune
)
return proportions / margin
result = []
for slice_ in self.cube.slices:
if self.cube.has_mr:
return self._mr_index()
margin = (
slice_.margin(axis=0, weighted=self.weighted, prune=self.prune) /
slice_.margin(weighted=self.weighted, prune=self.prune)
)
proportions = slice_.proportions(
axis=1, weighted=self.weighted, prune=self.prune
)
result.append(proportions / margin)

if len(result) == 1 and self.cube.ndim < 3:
result = result[0]
else:
if self.prune:
mask = np.array([slice_.mask for slice_ in result])
result = np.ma.masked_array(result, mask)
else:
result = np.array(result)

return result

def _mr_index(self):
# mr by mr
Expand Down
1 change: 1 addition & 0 deletions tests/integration/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ def _load(cube_file):
HUFFPOST_ACTIONS_X_HOUSEHOLD = _load('huffpost-actions-x-household.json')
GENDER_X_WEIGHT = _load('gender-x-weight.json')
CAT_X_CAT_PRUNING_HS = _load('cat-x-cat-pruning-hs.json')
CA_ITEMS_X_CA_CAT_X_CAT = _load('ca-items-x-ca-cat-x-cat.json')
Loading

0 comments on commit a5c63ca

Please sign in to comment.