Skip to content

Commit

Permalink
cube: add Cube.title
Browse files Browse the repository at this point in the history
  • Loading branch information
scanny committed May 2, 2020
1 parent 415e8c5 commit 2b2750d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/cr/cube/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def dimension_types(self):

@lazyproperty
def dimensions(self):
"""_ApparentDimension object providing access to visible dimensions.
"""_ApparentDimensions object providing access to visible dimensions.
A cube involving a multiple-response (MR) variable has two dimensions
for that variable (subvariables and categories dimensions), but is
Expand Down Expand Up @@ -360,7 +360,7 @@ def title(self):
use-case it is a stand-in for the columns-dimension name since a strand has no
columns dimension.
"""
raise NotImplementedError
return self._cube_dict.get("title", "Untitled")

@lazyproperty
def _all_dimensions(self):
Expand Down
4 changes: 3 additions & 1 deletion tests/fixtures/cat-x-cat.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"derived": false,
"references": {
"alias": "v4",
"description": "Pet Owners",
"name": "v4"
},
"type": {
Expand Down Expand Up @@ -146,5 +147,6 @@
},
"missing": 5,
"n": 20
}
},
"title": "Pony Owners"
}
3 changes: 2 additions & 1 deletion tests/fixtures/univariate-categorical.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@
},
"missing": 5,
"n": 20
}
},
"title": "Registered Voters"
}
3 changes: 1 addition & 2 deletions tests/integration/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
class DescribeIntegratedCube(object):
"""Integration-test suite for `cr.cube.cube.Cube` object."""

@pytest.mark.xfail(reason="WIP", strict=True)
def it_provides_values_for_cat_x_cat(self):
cube = Cube(CR.CAT_X_CAT)

Expand All @@ -35,7 +34,7 @@ def it_provides_values_for_cat_x_cat(self):
cube.counts_with_missings, [[5, 3, 2, 0], [5, 2, 3, 0], [0, 0, 0, 0]]
)
assert cube.cube_index == 0
assert cube.description == ""
assert cube.description == "Pet Owners"
assert cube.dimension_types == (DT.CAT, DT.CAT)
assert isinstance(cube.dimensions, _ApparentDimensions)
assert cube.has_means is False
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/test_cubepart.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def it_provides_values_for_cat_x_cat(self):
assert slice_.columns_dimension_name == "v7"
assert slice_.columns_dimension_type == DT.CAT
assert slice_.cube_is_mr_by_itself is False
assert slice_.description == ""
assert slice_.description == "Pet Owners"
np.testing.assert_almost_equal(
slice_.row_proportions, np.array([[0.71428571, 0.28571429], [0.625, 0.375]])
)
Expand All @@ -39,7 +39,7 @@ def it_provides_values_for_cat_x_cat(self):
],
)
assert slice_.row_labels == ("B", "C")
assert slice_.rows_dimension_description == ""
assert slice_.rows_dimension_description == "Pet Owners"
assert slice_.rows_dimension_fills == (None, None)
assert slice_.rows_dimension_name == "v4"
assert slice_.rows_dimension_type == DT.CAT
Expand Down Expand Up @@ -1017,7 +1017,6 @@ def it_knows_its_insertions(self):
class Describe_Strand(object):
"""Integration-test suite for `cr.cube.cubepart._Strand` object."""

@pytest.mark.xfail(reason="WIP", strict=True)
def it_provides_values_for_univariate_cat(self):
strand = Cube(CR.UNIVARIATE_CATEGORICAL).partitions[0]

Expand Down Expand Up @@ -1055,7 +1054,6 @@ def it_provides_values_for_univariate_cat(self):
assert pytest.approx(strand.var_scale_mean) == 0.8888888
assert strand.variable_name == "v7"

@pytest.mark.xfail(reason="WIP", strict=True)
def it_provides_values_for_cat_with_means_and_insertions(self):
strand = Cube(CR.CAT_WITH_MEANS_AND_INSERTIONS).partitions[0]

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ def it_knows_if_it_is_mr_by_itself(

assert is_mr_by_itself is expected_value

@pytest.mark.parametrize(
("cube_dict", "expected_value"),
(({}, "Untitled"), ({"title": "Hipsters"}, "Hipsters")),
)
def it_knows_its_title(self, _cube_dict_prop_, cube_dict, expected_value):
_cube_dict_prop_.return_value = cube_dict
assert Cube(None).title == expected_value

def it_provides_access_to_the_cube_response_dict_to_help(self):
assert Cube({"cube": "dict"})._cube_dict == {"cube": "dict"}

Expand Down Expand Up @@ -392,6 +400,10 @@ def but_it_raises_on_other_cube_response_types(self, cube_response, expected_val

# fixture components ---------------------------------------------

@pytest.fixture
def _cube_dict_prop_(self, request):
return property_mock(request, Cube, "_cube_dict")

@pytest.fixture
def dimension_types_prop_(self, request):
return property_mock(request, Cube, "dimension_types")
Expand Down

0 comments on commit 2b2750d

Please sign in to comment.