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

New property in cubepart for data validity #181

Merged
merged 2 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions src/cr/cube/cubepart.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ def inserted_column_idxs(self):
def inserted_row_idxs(self):
return tuple(i for i, row in enumerate(self._matrix.rows) if row.is_insertion)

@lazyproperty
def is_empty(self):
return any(s == 0 for s in self.shape)

@lazyproperty
def means(self):
return np.array([row.means for row in self._matrix.rows])
Expand Down Expand Up @@ -504,6 +508,10 @@ def bases(self):
def counts(self):
return tuple(row.count for row in self._stripe.rows)

@lazyproperty
def is_empty(self):
return any(s == 0 for s in self._shape)

@lazyproperty
def inserted_row_idxs(self):
# TODO: add integration-test coverage for this.
Expand Down Expand Up @@ -717,6 +725,10 @@ class _Nub(CubePartition):
def base_count(self):
return self._cube.base_counts

@lazyproperty
def is_empty(self):
return False if self.base_count else True

@lazyproperty
def means(self):
return self._scalar.means
Expand Down
90 changes: 90 additions & 0 deletions tests/fixtures/econ-nodata-no-dims.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"element": "shoji:view",
"self": "https://app.crunch.io/api/datasets/43f0d19eb1f241a39b7d5c547a0a6b6e/cube/?filter=%5B%5D&query=%7B%22dimensions%22:%5B%5D,%22measures%22:%7B%22count%22:%7B%22function%22:%22cube_count%22,%22args%22:%5B%5D%7D,%22mean%22:%7B%22function%22:%22cube_mean%22,%22args%22:%5B%7B%22variable%22:%22https:%2F%2Fapp.crunch.io%2Fapi%2Fdatasets%2F43f0d19eb1f241a39b7d5c547a0a6b6e%2Fvariables%2F00000c%2F%22%7D%5D%7D%7D,%22weight%22:null%7D",
"value": {
"query": {
"measures": {
"count": {
"function": "cube_count",
"args": [

]
},
"mean": {
"function": "cube_mean",
"args": [
{
"variable": "https://app.crunch.io/api/datasets/43f0d19eb1f241a39b7d5c547a0a6b6e/variables/00000c/"
}
]
}
},
"dimensions": [

],
"weight": null
},
"query_environment": {
"filter": [

]
},
"result": {
"dimensions": [

],
"missing": 0,
"measures": {
"count": {
"data": [
null
],
"n_missing": 0,
"metadata": {
"references": {

},
"derived": true,
"type": {
"integer": true,
"missing_rules": {

},
"missing_reasons": {
"No Data": -1
},
"class": "numeric"
}
}
},
"mean": {
"data": [
null
],
"n_missing": 0,
"metadata": {
"references": {

},
"derived": true,
"type": {
"integer": null,
"missing_rules": {

},
"missing_reasons": {
"No Data": -1
},
"class": "numeric"
}
}
}
},
"element": "crunch:cube",
"counts": [
null
],
"n": null
}
}
}
105 changes: 105 additions & 0 deletions tests/fixtures/om-sgp8334215-vn-2019-sep-19-strand.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"result": {
"dimensions": [
{
"derived": true,
"references": {
"alias": "VCAO2_open1",
"notes": "Base: Those using other specified streaming platforms",
"name": "Device for consumption of free TV and video content - Other specified",
"description": "Which of the following devices do you use to watch free television and video content? Please select all that apply. : Other Specify"
},
"type": {
"subtype": {
"missing_rules": {
"No data": {
"function": "==",
"args": [
{
"variable": "000009"
},
{
"value": "__NA__"
}
]
}
},
"missing_reasons": {
"No Data": -1,
"No data": 1
},
"class": "text"
},
"elements": [
{
"id": 0,
"value": {
"?": -1
},
"missing": true
}
],
"class": "enum"
}
}
],
"measures": {
"count": {
"data": [
1044.9999999999
],
"n_missing": 1045,
"metadata": {
"references": {},
"derived": true,
"type": {
"integer": false,
"class": "numeric",
"missing_reasons": {
"No Data": -1
},
"missing_rules": {}
}
}
}
},
"n": 1045,
"filter_stats": {
"filtered_complete": {
"unweighted": {
"selected": 1045,
"other": 0,
"missing": 0
},
"weighted": {
"selected": 1044.9999999999,
"other": 0,
"missing": 0
}
},
"filtered": {
"unweighted": {
"selected": 1045,
"other": 0,
"missing": 0
},
"weighted": {
"selected": 1044.9999999999,
"other": 0,
"missing": 0
}
}
},
"unfiltered": {
"unweighted_n": 1045,
"weighted_n": 1044.9999999999
},
"filtered": {
"unweighted_n": 1045,
"weighted_n": 1044.9999999999
},
"counts": [
1045
]
}
}
Loading