diff --git a/src/cr/cube/crunch_cube.py b/src/cr/cube/crunch_cube.py index 4e5aeb634..da85ede25 100644 --- a/src/cr/cube/crunch_cube.py +++ b/src/cr/cube/crunch_cube.py @@ -1016,18 +1016,6 @@ def percentages(self, axis=None): ''' return self.proportions(axis) * 100 - @lazyproperty - def population_fraction(self): - try: - unfiltered, filtered = self.counts - num = filtered.get('weighted_n') - den = unfiltered.get('weighted_n') - return num / den - except ZeroDivisionError: - return np.nan - except: - return 1 - def population_counts(self, population_size, weighted=True, include_missing=False, include_transforms_for_dims=None, prune=False): @@ -1060,7 +1048,7 @@ def population_counts(self, population_size, weighted=True, include_missing=include_missing, include_transforms_for_dims=include_transforms_for_dims, prune=prune - ) * population_size * self.population_fraction + ) * population_size def index(self, weighted=True, prune=False): '''Get cube index measurement.''' diff --git a/src/cr/cube/mixins/data_table.py b/src/cr/cube/mixins/data_table.py index 74a2ac089..b6b106c31 100644 --- a/src/cr/cube/mixins/data_table.py +++ b/src/cr/cube/mixins/data_table.py @@ -132,12 +132,6 @@ def flat_values(self, weighted, margin=False): def _shape(self): return tuple([dim.shape for dim in self.all_dimensions]) - @lazyproperty - def counts(self): - unfiltered = self._cube['result'].get('unfiltered') - filtered = self._cube['result'].get('filtered') - return unfiltered, filtered - def data(self, weighted, margin=False): '''Get the data in non-flattened shape. diff --git a/tests/integration/fixtures/__init__.py b/tests/integration/fixtures/__init__.py index 4b713cbb5..aab53a16b 100644 --- a/tests/integration/fixtures/__init__.py +++ b/tests/integration/fixtures/__init__.py @@ -142,4 +142,3 @@ def _load(cube_file): CAT_X_CAT_PRUNING_HS = _load('cat-x-cat-pruning-hs.json') CA_ITEMS_X_CA_CAT_X_CAT = _load('ca-items-x-ca-cat-x-cat.json') CAT_X_MR_X_CAT = _load('cat-x-mr-x-cat.json') -CAT_X_CAT_FILTERED_POP = _load('cat-x-cat-filtered-population.json') diff --git a/tests/integration/fixtures/cubes/cat-x-cat-filtered-population.json b/tests/integration/fixtures/cubes/cat-x-cat-filtered-population.json deleted file mode 100644 index 5a67ae236..000000000 --- a/tests/integration/fixtures/cubes/cat-x-cat-filtered-population.json +++ /dev/null @@ -1,371 +0,0 @@ -{ - "query": { - "measures": { - "count": { - "function": "cube_count", - "args": [] - } - }, - "dimensions": [ - { - "variable": "https://alpha.crunch.io/api/datasets/41fb7b1179bb4c948a63afb1de66303c/variables/000000/" - }, - { - "variable": "https://alpha.crunch.io/api/datasets/41fb7b1179bb4c948a63afb1de66303c/variables/000001/" - } - ], - "weight": null - }, - "query_environment": { - "filter": [ - "https://alpha.crunch.io/api/datasets/41fb7b1179bb4c948a63afb1de66303c/filters/a1c21b17d9fc4664ab87bb7ace4dc139/" - ] - }, - "result": { - "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": { - "show_counts": false, - "column_width": null, - "transform": { - "insertions": [ - { - "function": "subtotal", - "args": [ - 3, - 4 - ], - "name": "HS Both + Neither", - "anchor": 3 - } - ] - }, - "include_missing": false, - "show_numeric_values": false - } - }, - "type": { - "ordinal": false, - "class": "categorical", - "categories": [ - { - "numeric_value": 1, - "missing": false, - "id": 1, - "name": "President Obama" - }, - { - "numeric_value": 2, - "missing": false, - "id": 2, - "name": "Republicans in Congress" - }, - { - "numeric_value": 3, - "missing": false, - "id": 3, - "name": "Both" - }, - { - "numeric_value": 4, - "missing": false, - "id": 4, - "name": "Neither" - }, - { - "numeric_value": 5, - "missing": false, - "id": 5, - "name": "Not sure" - }, - { - "numeric_value": 8, - "missing": true, - "id": 8, - "name": "Skipped" - }, - { - "numeric_value": 9, - "missing": true, - "id": 9, - "name": "Not Asked" - }, - { - "numeric_value": null, - "missing": true, - "id": -1, - "name": "No Data" - } - ] - } - }, - { - "derived": false, - "references": { - "alias": "RespondentIdeology", - "view": { - "show_counts": false, - "show_numeric_values": false, - "transform": { - "insertions": [ - { - "function": "subtotal", - "args": [ - 4 - ], - "name": "HS Conservative", - "anchor": 3 - } - ] - }, - "include_missing": false, - "column_width": null - }, - "description": "In general, how would you describe your own political viewpoint?", - "name": "RespondentIdeology" - }, - "type": { - "ordinal": false, - "class": "categorical", - "categories": [ - { - "numeric_value": 1, - "missing": false, - "id": 1, - "name": "Very liberal" - }, - { - "numeric_value": 2, - "missing": false, - "id": 2, - "name": "Liberal" - }, - { - "numeric_value": 3, - "missing": false, - "id": 3, - "name": "Moderate" - }, - { - "numeric_value": 4, - "missing": false, - "id": 4, - "name": "Conservative" - }, - { - "numeric_value": 5, - "missing": false, - "id": 5, - "name": "Very Conservative" - }, - { - "numeric_value": 6, - "missing": false, - "id": 6, - "name": "Not sure" - }, - { - "numeric_value": 8, - "missing": true, - "id": 8, - "name": "Skipped" - }, - { - "numeric_value": 9, - "missing": true, - "id": 9, - "name": "Not Asked" - }, - { - "numeric_value": null, - "missing": true, - "id": -1, - "name": "No Data" - } - ] - } - } - ], - "missing": 0, - "measures": { - "count": { - "data": [ - 3, - 14, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 59, - 132, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 6, - 29, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 3, - 6, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "n_missing": 0, - "metadata": { - "references": {}, - "derived": true, - "type": { - "integer": true, - "missing_rules": {}, - "missing_reasons": { - "No Data": -1 - }, - "class": "numeric" - } - } - } - }, - "n": 254, - "unfiltered": { - "unweighted_n": 1000, - "weighted_n": 1000 - }, - "filtered": { - "unweighted_n": 254, - "weighted_n": 254 - }, - "counts": [ - 3, - 14, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 59, - 132, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 6, - 29, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 3, - 6, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "element": "crunch:cube" - } -} \ No newline at end of file diff --git a/tests/integration/test_crunch_cube.py b/tests/integration/test_crunch_cube.py index 320746d1e..86222577e 100644 --- a/tests/integration/test_crunch_cube.py +++ b/tests/integration/test_crunch_cube.py @@ -55,7 +55,6 @@ from .fixtures import HUFFPOST_ACTIONS_X_HOUSEHOLD from .fixtures import GENDER_X_WEIGHT from .fixtures import CAT_X_MR_X_CAT -from .fixtures import CAT_X_CAT_FILTERED_POP from . import assert_scale_means_equal @@ -395,17 +394,6 @@ def test_population_counts_cat_x_cat(self): actual = cube.population_counts(9001) np.testing.assert_almost_equal(actual, expected) - def test_filtered_population_counts(self): - cube = CrunchCube(CAT_X_CAT_FILTERED_POP) - expected = np.array([ - [ 300000., 1400000., 0., 0., 0., 0.], - [5900000., 13200000., 0., 0., 0., 0.], - [ 600000., 2900000., 0., 0., 0., 0.], - [ 100000., 100000., 0., 0., 0., 0.], - [ 300000., 600000., 0., 0., 0., 0.]]) - actual = cube.population_counts(100000000) - np.testing.assert_almost_equal(actual, expected) - def test_labels_cat_x_cat_exclude_missing(self): cube = CrunchCube(CAT_X_CAT) expected = [ diff --git a/tests/unit/test_crunch_cube.py b/tests/unit/test_crunch_cube.py index 146090ca5..0375409d8 100644 --- a/tests/unit/test_crunch_cube.py +++ b/tests/unit/test_crunch_cube.py @@ -1,5 +1,4 @@ '''Unit tests for the CrunchCube class.''' - from unittest import TestCase from mock import Mock from mock import patch @@ -931,39 +930,4 @@ def test_ca_dim_ind_is_none(self): cc = CrunchCube({}) actual = cc.ca_dim_ind expected = None - assert actual == expected - - def test_population_fraction(self): - - # Assert fraction is 1 when none of the counts are specified - cc = CrunchCube({}) - actual = cc.population_fraction - assert actual == 1 - - # Assert fraction is 1 when only some counts are specified - cc = CrunchCube({'result': {'unfiltered': {'unweighted_n': 10}}}) - assert cc.population_fraction == 1 - cc = CrunchCube({'result': {'unfiltered': {'weighted_n': 10}}}) - assert cc.population_fraction == 1 - cc = CrunchCube({'result': {'unfiltered': {'weighted_n': 10, 'unweighted_n': 10}}}) - assert cc.population_fraction == 1 - cc = CrunchCube({'result': {'filtered': {'weighted_n': 10, 'unweighted_n': 10}}}) - assert cc.population_fraction == 1 - - # Assert fraction is calculated when correct counts are specified - cc = CrunchCube({ - 'result': { - 'filtered': {'weighted_n': 5}, - 'unfiltered': {'weighted_n': 10}, - } - }) - assert cc.population_fraction == 0.5 - - # Assert fraction is NaN, when denominator is zero - cc = CrunchCube({ - 'result': { - 'filtered': {'weighted_n': 5}, - 'unfiltered': {'weighted_n': 0}, - } - }) - assert np.isnan(cc.population_fraction) + assert actual == expected \ No newline at end of file diff --git a/tests/unit/test_data_table.py b/tests/unit/test_data_table.py deleted file mode 100644 index 884a63cdb..000000000 --- a/tests/unit/test_data_table.py +++ /dev/null @@ -1,20 +0,0 @@ -# encoding: utf-8 - -from mock import Mock - -from cr.cube.mixins.data_table import DataTable - - -def test_cube_counts(): - dt = DataTable({'result': {}}) - assert dt.counts == (None, None) - - fake_count = Mock() - dt = DataTable({'result': {'unfiltered': fake_count}}) - assert dt.counts == (fake_count, None) - - dt = DataTable({'result': {'filtered': fake_count}}) - assert dt.counts == (None, fake_count) - - dt = DataTable({'result': {'unfiltered': fake_count, 'filtered': fake_count}}) - assert dt.counts == (fake_count, fake_count)