Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract measures #117

Merged
merged 30 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6722cda
rfctr: rename CrunchCube._cube to _cube_dict
scanny Nov 2, 2018
130a01d
rfctr: remove real-work from initializer
scanny Nov 3, 2018
2c3aa9f
test: remove deprecated cube.index() calls
scanny Nov 3, 2018
b2dce84
rfctr: remove 'adjusted' arg from ._as_array()
scanny Nov 5, 2018
648eced
cube: add xfails to drive _Measures TDD
scanny Nov 5, 2018
63cd839
cube: add _Measures.is_weighted
scanny Nov 6, 2018
4067b5f
cube: add _Measures.means
scanny Nov 6, 2018
6e1b177
cube: add _Measures.missing_count
scanny Nov 6, 2018
16c112d
cube: add _MeanMeasure.missing_count
scanny Nov 6, 2018
7e87398
cube: add _Measures.population_fraction
scanny Nov 6, 2018
263fe2d
cube: add _Measures.unweighted_counts
scanny Nov 6, 2018
c32dea4
cube: add _Measures.unweighted_n
scanny Nov 6, 2018
f1075b9
cube: add _Measures.weighted_counts
scanny Nov 6, 2018
c2e6f97
cube: add _Measures.weighted_n
scanny Nov 6, 2018
e8ad515
tdd: add xfails for _BaseMeasure subclasses
scanny Nov 6, 2018
3a933bd
cube: add _BaseMeasure.raw_cube_array
scanny Nov 6, 2018
ee91586
cube: add _MeanMeasure._flat_values
scanny Nov 6, 2018
9387d75
cube: add _UnweightedCountMeasure._flat_values
scanny Nov 6, 2018
4de0e30
cube: add _WeightedCountMeasure._flat_values
scanny Nov 6, 2018
f642554
rfctr: reimplement CrunchCube.count()
scanny Nov 6, 2018
3af112e
cube: add CrunchCube._measures
scanny Nov 6, 2018
f083e75
rfctr: reimplement CrunchCube.has_means
scanny Nov 6, 2018
4400638
rfctr: reimplement CrunchCube.is_weighted
scanny Nov 6, 2018
76a6bca
rfctr: reimplement CrunchCube.missing
scanny Nov 6, 2018
1da96ce
rfctr: reimplement CrunchCube.population_fraction
scanny Nov 6, 2018
bcc1144
cube: add CrunchCube._measure()
scanny Nov 6, 2018
05b6c15
rfctr: remove `margin` param from _as_array()
scanny Nov 6, 2018
195470e
cube: add CrunchCube._counts()
scanny Nov 6, 2018
7068262
rfctr: replace CrunchCube._data()
scanny Nov 6, 2018
6e10548
test: scrub overall test coverage
scanny Nov 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
394 changes: 271 additions & 123 deletions src/cr/cube/crunch_cube.py

Large diffs are not rendered by default.

379 changes: 379 additions & 0 deletions tests/fixtures/cat-x-cat-mean-wgtd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,379 @@
{
"query": {
"dimensions": [
{
"variable": "https://alpha.crunch.io/api/datasets/aefd8b1483754d639b46f5ee8f6d7821/variables/000000/"
},
{
"variable": "https://alpha.crunch.io/api/datasets/aefd8b1483754d639b46f5ee8f6d7821/variables/000004/"
}
],
"measures": {
"count": {
"args": [],
"function": "cube_count"
},
"mean": {
"args": [
{
"variable": "https://alpha.crunch.io/api/datasets/aefd8b1483754d639b46f5ee8f6d7821/variables/00000c/"
}
],
"function": "cube_mean"
}
},
"weight": "https://alpha.crunch.io/api/datasets/aefd8b1483754d639b46f5ee8f6d7821/variables/0af6163c3e694b9b80071ed691fd4f28/"
},
"query_environment": {
"filter": []
},
"result": {
"counts": [
156,
129,
0,
0,
0,
197,
199,
0,
0,
0,
101,
141,
0,
0,
0,
2,
4,
0,
0,
0,
26,
42,
0,
0,
0,
3,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"dimensions": [
{
"derived": false,
"references": {
"alias": "ShutdownBlame",
"description": "If President Obama and the Republicans in Congress do not reach a budget agreement in time to avoid a shutdown of the federal government, who do you think will more to blame--President Obama or the Republican Congress?",
"name": "ShutdownBlame",
"view": {
"column_width": null,
"include_missing": true,
"show_counts": false,
"show_numeric_values": false,
"transforms": {
"insertions": [
{
"anchor": 5,
"args": [
5,
4
],
"function": "subtotal",
"name": "test new"
}
]
}
}
},
"type": {
"categories": [
{
"id": 1,
"missing": false,
"name": "President Obama",
"numeric_value": 1
},
{
"id": 2,
"missing": false,
"name": "Republicans in Congress",
"numeric_value": 2
},
{
"id": 3,
"missing": false,
"name": "Both",
"numeric_value": 3
},
{
"id": 4,
"missing": false,
"name": "Neither",
"numeric_value": 4
},
{
"id": 5,
"missing": false,
"name": "Not sure",
"numeric_value": 5
},
{
"id": 8,
"missing": true,
"name": "Skipped",
"numeric_value": 8
},
{
"id": 9,
"missing": true,
"name": "Not Asked",
"numeric_value": 9
},
{
"id": -1,
"missing": true,
"name": "No Data",
"numeric_value": null
}
],
"class": "categorical",
"ordinal": false
}
},
{
"derived": false,
"references": {
"alias": "Gender",
"description": "Are you male or female?",
"name": "Gender"
},
"type": {
"categories": [
{
"id": 1,
"missing": false,
"name": "Male",
"numeric_value": 1
},
{
"id": 2,
"missing": false,
"name": "Female",
"numeric_value": 2
},
{
"id": 8,
"missing": true,
"name": "Skipped",
"numeric_value": 8
},
{
"id": 9,
"missing": true,
"name": "Not Asked",
"numeric_value": 9
},
{
"id": -1,
"missing": true,
"name": "No Data",
"numeric_value": null
}
],
"class": "categorical",
"ordinal": false
}
}
],
"element": "crunch:cube",
"measures": {
"count": {
"data": [
160.82474226804146,
125.24271844660174,
0,
0,
0,
203.0927835051553,
193.20388349514528,
0,
0,
0,
104.12371134020616,
136.89320388349492,
0,
0,
0,
2.061855670103093,
3.883495145631068,
0,
0,
0,
26.804123711340207,
40.776699029126206,
0,
0,
0,
3.0927835051546397,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"metadata": {
"derived": true,
"references": {},
"type": {
"class": "numeric",
"integer": false,
"missing_reasons": {
"No Data": -1
},
"missing_rules": {}
}
},
"n_missing": 3
},
"mean": {
"data": [
52.78205128205122,
49.9069767441861,
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
50.43654822335009,
48.20100502512572,
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
51.5643564356436,
47.602836879432715,
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
58,
29,
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
37.53846153846155,
39.45238095238095,
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
36.666666666666664,
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
},
{
"?": -8
}
],
"metadata": {
"derived": true,
"references": {},
"type": {
"class": "numeric",
"integer": false,
"missing_reasons": {
"NaN": -8,
"No Data": -1
},
"missing_rules": {}
}
},
"n_missing": 3
}
},
"missing": 3,
"n": 1000
}
}
Loading