Skip to content

Commit fbde71e

Browse files
authored
Merge pull request #410 from Crunch-io/ZC-79-return-types
[ZC-79]: fix return type of _Strand.table_percentages
2 parents d4fc9c8 + 7e8997a commit fbde71e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/cr/cube/cubepart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2405,7 +2405,7 @@ def table_percentages(self):
24052405
Table-percentage is the fraction of the table weighted-N contributed by each
24062406
row, expressed as a percentage (float between 0.0 and 100.0 inclusive).
24072407
"""
2408-
return tuple(self.table_proportions * 100)
2408+
return self.table_proportions * 100
24092409

24102410
@lazyproperty
24112411
def table_proportion_moes(self):

tests/unit/test_cubepart.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Unit test suite for `cr.cube.cubepart` module."""
44

55
import mock
6+
import numpy as np
67
import pytest
78

89
from cr.cube.cube import Cube
@@ -405,6 +406,17 @@ def test_it_provides_the_population_counts_moe(self, cube_):
405406
strand_ = _Strand(cube_, None, population, None, None, None)
406407
assert strand_.population_counts_moe == pytest.approx(0.6 * 1.959964)
407408

409+
def test_it_provides_the_table_percentage_as_numpy(self, cube_):
410+
with mock.patch(
411+
"cr.cube.cubepart._Strand.table_proportions", new=np.array([0.321, 0.253])
412+
):
413+
strand_ = _Strand(cube_, None, None, None, None, None)
414+
415+
actual = strand_.table_percentages
416+
417+
# assert type(actual) is np.ndarray
418+
assert actual == pytest.approx(np.array([32.1, 25.3]))
419+
408420
def test_it_knows_its_selected_categories_labels(self, _dimensions_prop_):
409421
_dimensions_prop_.return_value = [Dimension({"references": {}}, None, None)]
410422
strand_ = _Strand(None, None, None, None, None, None)

0 commit comments

Comments
 (0)