Skip to content

Commit

Permalink
Merge pull request #129 from Crunch-io/can-compare-pairwise
Browse files Browse the repository at this point in the history
Check if slice can compare pairwise
  • Loading branch information
slobodan-ilic committed Jan 18, 2019
2 parents 5702ca1 + adbdfea commit e75b7ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cr/cube/cube_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def col_dim_ind(self):
"""Return 1 if not categorical array as 0th, 0 otherwise."""
return 1 if not self.ca_as_0th else 0

@lazyproperty
def can_compare_pairwise(self):
return self.dim_types == (DT.CAT, DT.CAT)

@lazyproperty
def dim_types(self):
"""Tuple of DIMENSION_TYPE member for each dimension of slice."""
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/test_cube_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,41 @@ def it_knows_whether_its_a_double_mr(self, is_double_mr_fixture, dim_types_prop_

assert is_double_mr is expected_value

def it_can_compare_pairwise(
self, cube_, dim_types_prop_, pairwise_comparisons_fixture
):
dim_types, slice_can_show = pairwise_comparisons_fixture
dim_types_prop_.return_value = dim_types
slice_ = CubeSlice(cube_, None)

assert slice_.can_compare_pairwise == slice_can_show

# fixtures -------------------------------------------------------

@pytest.fixture(
params=[
((DT.CAT,), False),
((DT.MR,), False),
((DT.BINNED_NUMERIC,), False),
((DT.DATETIME,), False),
((DT.LOGICAL,), False),
((DT.TEXT,), False),
((DT.CA_CAT,), False),
((DT.CA_SUBVAR, DT.CA_CAT), False),
((DT.CA_SUBVAR, DT.MR, DT.CA_CAT), False),
((DT.MR, DT.CAT), False),
((DT.BINNED_NUMERIC, DT.CAT), False),
((DT.DATETIME, DT.CAT), False),
((DT.LOGICAL, DT.CAT), False),
((DT.TEXT, DT.CAT), False),
((DT.CA_CAT, DT.CAT), False),
((DT.CAT, DT.CAT), True),
]
)
def pairwise_comparisons_fixture(self, request):
dim_types, slice_can_show = request.param
return dim_types, slice_can_show

@pytest.fixture(
params=[
((DT.CAT,), (DT.CAT,)),
Expand Down

0 comments on commit e75b7ef

Please sign in to comment.