Skip to content

Commit

Permalink
Implement pruning for 1D MR
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodan-ilic committed Apr 3, 2018
1 parent aa4a474 commit 24560c6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/cr/cube/crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,26 @@ def _as_array(self, include_missing=False, get_non_selected=False,
)
res = res + adjusted

if prune and not self.has_mr:
if prune:
return self._prune(res, include_transforms_for_dims)

return res

def _mr_prune(self, res):
margin = self.margin(axis=0)
ind_prune = margin == 0
return res[~ind_prune]

def _prune(self, res, transforms=None):
'''Prune the result based on margins content.
Pruning is the removal of rows or columns, whose corresponding
marginal elements are either 0 or not defined (np.nan).
'''

if self.has_mr:
return self._mr_prune(res)

# Note: If the cube contains transforms (H&S), and they happen to
# have the marginal value 0 (or NaN), they're NOT pruned. This is
# done to achieve parity with how the front end client works (whaam).
Expand Down

0 comments on commit 24560c6

Please sign in to comment.