Skip to content

Commit

Permalink
Fix pruning for cubes that contain single CAT variables
Browse files Browse the repository at this point in the history
- Add tests that reproduce index error for single CAT pruning
- Modify a conditional statement in how pruning is processed
  • Loading branch information
slobodan-ilic committed Jan 31, 2018
1 parent aa233bd commit 150c9c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cr/cube/crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _as_array(self, include_missing=False, get_non_selected=False,

if prune and not self.has_mr:
# Remove columns and rows where marginal value is 0 or np.nan
if len(self.dimensions) == 1:
if len(self.dimensions) == 1 or len(res.shape) == 1:
margin = self.margin(
include_transforms_for_dims=include_transforms_for_dims,
axis=1,
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2005,3 +2005,11 @@ def test_row_unweighted_margin_when_has_means(self):
])
actual = cube.margin(axis=1, weighted=False, prune=True)
np.testing.assert_array_equal(actual, expected)

def test_ca_with_single_cat_pruning(self):
cube = CrunchCube(FIXT_CA_SINGLE_CAT)
# The last 0 of the expectation is not visible in whaam because of
# pruning, which is not the responsibility of cr.cube.
expected = np.array([79, 80, 70])
actual = cube.as_array(weighted=False, prune=True)
np.testing.assert_almost_equal(actual, expected)

0 comments on commit 150c9c7

Please sign in to comment.