Skip to content

Commit

Permalink
Add tests with bad subtotal anchors
Browse files Browse the repository at this point in the history
- The tests should break the CC functionality
- Tests contain anchor values (encountered in pruduction data) that
  are greater than the max number of dimension elements
- The idea is to 'normalize' these values (default them to 'bottom')
  • Loading branch information
slobodan-ilic committed Feb 5, 2018
1 parent b9443d4 commit 4da3b65
Show file tree
Hide file tree
Showing 4 changed files with 1,001 additions and 13 deletions.
32 changes: 24 additions & 8 deletions src/cr/cube/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,35 @@ def inserted_hs_indices(self):
for i, _ in enumerate(bottoms)]
return top_inds + middle_inds + bottom_inds

def _transform_anchor(self, subtotal):

if subtotal.anchor in ['top', 'bottom']:
return subtotal.anchor

element_ids = [el['id'] for el in self._elements]
if subtotal.anchor not in element_ids:
# In case of numeric value which is not a category ID, return
# default value 'bottom'
return 'bottom'

contiguous_anchors = [
i for (i, id_) in enumerate(element_ids)
if id_ == subtotal.anchor
]
# In case of more matches, return the first one (although there
# shouldn't be any)
return contiguous_anchors[0]

@property
def hs_indices(self):
'''Headers and Subtotals indices.'''
elms = self._elements
elements = self._elements

indices = [{
'anchor_ind': (
[i for (i, el) in enumerate(elms) if el['id'] == st.anchor][0]
if (st.anchor in [el['id'] for el in elms]) else
st.anchor
),
'inds': [i for (i, el) in enumerate(elms) if el['id'] in st.args],
} for st in self.subtotals]
'anchor_ind': self._transform_anchor(subtotal),
'inds': [i for (i, el) in enumerate(elements)
if el['id'] in subtotal.args],
} for subtotal in self.subtotals]

return indices

Expand Down
1 change: 1 addition & 0 deletions tests/integration/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@
CUBES_DIR, 'fruit-x-pets-hs-top-bottom.json'
)
FIXT_CA_X_SINGLE_CAT = load_fixture(CUBES_DIR, 'ca-x-single-cat.json')
FIXT_CA_WITH_NETS = load_fixture(CUBES_DIR, 'ca-with-nets.json')

0 comments on commit 4da3b65

Please sign in to comment.