-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for HS labels with missing
- Add test for a univariate CAT with missing categories and H&S, ensure that the labels of the missings are not returned - Restructure tests, prepare for the more signifficant refactor
- Loading branch information
1 parent
1f1ec74
commit 926cc8a
Showing
3 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1ac271769c1b4af381e8437717afbb56/cube/?filter=%5B%5D&query=%7B%22dimensions%22:%5B%7B%22variable%22:%22https:%2F%2Fapp.crunch.io%2Fapi%2Fdatasets%2F1ac271769c1b4af381e8437717afbb56%2Fvariables%2F000045%2F%22%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/1ac271769c1b4af381e8437717afbb56/variables/000045/" | ||
} | ||
], | ||
"weight": null | ||
}, | ||
"query_environment": { | ||
"filter": [] | ||
}, | ||
"result": { | ||
"dimensions": [ | ||
{ | ||
"derived": false, | ||
"references": { | ||
"alias": "exitpoll16", | ||
"view": { | ||
"show_counts": false, | ||
"show_numeric_values": false, | ||
"transform": { | ||
"insertions": [ | ||
{ | ||
"function": "subtotal", | ||
"args": [ | ||
1, | ||
2, | ||
3, | ||
4 | ||
], | ||
"name": "Whites", | ||
"anchor": "top" | ||
} | ||
] | ||
}, | ||
"include_missing": false, | ||
"column_width": null | ||
}, | ||
"description": "National Exit Poll Demographic Groups", | ||
"name": "exitpoll16" | ||
}, | ||
"type": { | ||
"ordinal": false, | ||
"class": "categorical", | ||
"categories": [ | ||
{ | ||
"numeric_value": 7, | ||
"id": 7, | ||
"name": "Non-voters", | ||
"missing": true | ||
}, | ||
{ | ||
"numeric_value": 1, | ||
"id": 1, | ||
"name": "White college women voters", | ||
"missing": false | ||
}, | ||
{ | ||
"numeric_value": 2, | ||
"id": 2, | ||
"name": "White non-college women voters", | ||
"missing": false | ||
}, | ||
{ | ||
"numeric_value": 3, | ||
"id": 3, | ||
"name": "White college men voters", | ||
"missing": false | ||
}, | ||
{ | ||
"numeric_value": 4, | ||
"id": 4, | ||
"name": "White non-college men voters", | ||
"missing": false | ||
}, | ||
{ | ||
"numeric_value": 5, | ||
"id": 5, | ||
"name": "Black voters", | ||
"missing": false | ||
}, | ||
{ | ||
"numeric_value": 6, | ||
"id": 6, | ||
"name": "Latino and other voters", | ||
"missing": false | ||
}, | ||
{ | ||
"numeric_value": 32766, | ||
"id": 32766, | ||
"name": "skipped", | ||
"missing": true | ||
}, | ||
{ | ||
"numeric_value": 32767, | ||
"id": 32767, | ||
"name": "not asked", | ||
"missing": true | ||
}, | ||
{ | ||
"numeric_value": null, | ||
"id": -1, | ||
"name": "No Data", | ||
"missing": true | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"missing": 324, | ||
"measures": { | ||
"count": { | ||
"data": [ | ||
324, | ||
181, | ||
275, | ||
171, | ||
251, | ||
131, | ||
167, | ||
0, | ||
0, | ||
0 | ||
], | ||
"n_missing": 324, | ||
"metadata": { | ||
"references": {}, | ||
"derived": true, | ||
"type": { | ||
"integer": true, | ||
"missing_rules": {}, | ||
"missing_reasons": { | ||
"No Data": -1 | ||
}, | ||
"class": "numeric" | ||
} | ||
} | ||
} | ||
}, | ||
"element": "crunch:cube", | ||
"counts": [ | ||
324, | ||
181, | ||
275, | ||
171, | ||
251, | ||
131, | ||
167, | ||
0, | ||
0, | ||
0 | ||
], | ||
"n": 1500 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from unittest import TestCase | ||
from mock import patch | ||
import numpy as np | ||
|
||
from cr.cube.crunch_cube import CrunchCube | ||
|
||
from .fixtures import MISSING_CAT_HS | ||
|
||
|
||
class TestCrunchCube(TestCase): | ||
def test_missing_cat_hs_labels(self): | ||
cube = CrunchCube(MISSING_CAT_HS) | ||
|
||
# Don't expect the missing category "Non voters" | ||
expected = [[ | ||
'Whites', | ||
'White college women voters', | ||
'White non-college women voters', | ||
'White college men voters', | ||
'White non-college men voters', | ||
'Black voters', | ||
'Latino and other voters', | ||
]] | ||
actual = cube.labels(include_transforms_for_dims=[0]) | ||
assert actual == expected |