Skip to content

Commit

Permalink
Merge e4ec10a into a395d1b
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodan-ilic committed Jul 25, 2018
2 parents a395d1b + e4ec10a commit 8bce21b
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cr/cube/crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,14 @@ def hs_dims_for_den(hs_dims, axis):
include_transforms_for_dims=hs_dims,
)
if isinstance(arr, np.ma.core.MaskedArray):

inflate_ind = [
None if d.is_mr_selections(self.all_dimensions) else slice(None)
for i, d in enumerate(self.all_dimensions)
(
None
if d.is_mr_selections(self.all_dimensions) or n <= 1 else
slice(None)
)
for d, n in zip(self.all_dimensions, table.shape)
]
mask = np.logical_or(
np.zeros(den.shape, dtype=bool),
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 @@ -138,3 +138,4 @@ def _load(cube_file):
)
MR_X_CAT_X_MR_PRUNE = _load('mr-x-cat-x-mr-prune.json')
HUFFPOST_ACTIONS_X_HOUSEHOLD = _load('huffpost-actions-x-household.json')
GENDER_X_WEIGHT = _load('gender-x-weight.json')
140 changes: 140 additions & 0 deletions tests/integration/fixtures/cubes/gender-x-weight.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"element": "shoji:view",
"self": "https://app.crunch.io/api/datasets/13574cd25b61457b8f9e18187408b428/cube/?filter=%5B%5D&query=%7B%22dimensions%22:%5B%7B%22variable%22:%22https:%2F%2Fapp.crunch.io%2Fapi%2Fdatasets%2F13574cd25b61457b8f9e18187408b428%2Fvariables%2F000205%2F%22%7D,%7B%22function%22:%22bin%22,%22args%22:%5B%7B%22variable%22:%22https:%2F%2Fapp.crunch.io%2Fapi%2Fdatasets%2F13574cd25b61457b8f9e18187408b428%2Fvariables%2F956bcfea419f4b32a9faacd4d3a1dacb%2F%22%7D%5D%7D%5D,%22measures%22:%7B%22count%22:%7B%22function%22:%22cube_count%22,%22args%22:%5B%5D%7D%7D,%22weight%22:null%7D",
"value": {
"query": {
"measures": {
"count": {
"function": "cube_count",
"args": []
}
},
"dimensions": [
{
"variable": "https://app.crunch.io/api/datasets/13574cd25b61457b8f9e18187408b428/variables/000205/"
},
{
"function": "bin",
"args": [
{
"variable": "https://app.crunch.io/api/datasets/13574cd25b61457b8f9e18187408b428/variables/956bcfea419f4b32a9faacd4d3a1dacb/"
}
]
}
],
"weight": null
},
"query_environment": {
"filter": []
},
"result": {
"dimensions": [
{
"derived": false,
"references": {
"alias": "profile_gender",
"name": "Gender",
"description": "Are you male or female?"
},
"type": {
"ordinal": false,
"class": "categorical",
"categories": [
{
"numeric_value": null,
"id": 1,
"name": "Male",
"missing": false
},
{
"numeric_value": null,
"id": 2,
"name": "Female",
"missing": false
},
{
"numeric_value": null,
"id": 32766,
"name": "skipped",
"missing": true
},
{
"numeric_value": null,
"id": 32767,
"name": "not asked",
"missing": true
},
{
"numeric_value": null,
"id": -1,
"name": "No Data",
"missing": true
}
]
}
},
{
"references": {
"alias": "weight",
"name": "weight"
},
"derived": true,
"type": {
"subtype": {
"missing_rules": {},
"missing_reasons": {
"No Data": -1
},
"class": "numeric"
},
"elements": [
{
"id": 1,
"value": [
0.0,
1.0
],
"missing": false
}
],
"class": "enum"
}
}
],
"missing": 0,
"measures": {
"count": {
"data": [
59,
149,
0,
0,
0
],
"n_missing": 0,
"metadata": {
"references": {},
"derived": true,
"type": {
"integer": true,
"missing_rules": {},
"missing_reasons": {
"No Data": -1
},
"class": "numeric"
}
}
}
},
"element": "crunch:cube",
"counts": [
59,
149,
0,
0,
0
],
"n": 208
}
}
}
7 changes: 7 additions & 0 deletions tests/integration/test_crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from .fixtures import CA_X_MR_WEIGHTED_HS
from .fixtures import MR_X_CAT_X_MR_PRUNE
from .fixtures import HUFFPOST_ACTIONS_X_HOUSEHOLD
from .fixtures import GENDER_X_WEIGHT


class TestCrunchCube(TestCase):
Expand Down Expand Up @@ -1749,3 +1750,9 @@ def test_mr_x_cat_hs_prune_indices(self):
actual = cube.prune_indices(transforms=[0, 1])
np.testing.assert_array_equal(actual[0], expected[0])
np.testing.assert_array_equal(actual[1], expected[1])

def test_gender_x_weight_pruning(self):
cube = CrunchCube(GENDER_X_WEIGHT)
expected = 208
actual = cube.margin(prune=True)
np.testing.assert_array_equal(actual, expected)

0 comments on commit 8bce21b

Please sign in to comment.