diff --git a/src/cr/cube/crunch_cube.py b/src/cr/cube/crunch_cube.py index 40437337a..f5de609d3 100644 --- a/src/cr/cube/crunch_cube.py +++ b/src/cr/cube/crunch_cube.py @@ -240,10 +240,8 @@ def _transform(self, res, include_transforms_for_dims, valid_indices): ind_insertion = indices['anchor_ind'] + ind_offset if i == 0: value = sum(res[ind_subtotal_elements]) - # res = np.insert(res, ind_insertion + 1, value, axis=i) else: value = np.sum(res[:, ind_subtotal_elements], axis=1) - # res = np.insert(res, ind_insertion + 1, value, axis=i) insertions.append((ind_insertion, value)) for j, (ind_insertion, value) in enumerate(insertions): @@ -548,7 +546,6 @@ def _inflate_dim(self, array, axis): def _margin(self, axis=None, weighted=True, adjusted=False, include_transforms_for_dims=None, prune=False): - '''Calculate cube margin.''' # MR margins are calculated differently, so they need a separate method # for them. A good example of this is the rcrunch functionality. diff --git a/src/cr/cube/dimension.py b/src/cr/cube/dimension.py index 6cf7c3968..a0f081d7c 100644 --- a/src/cr/cube/dimension.py +++ b/src/cr/cube/dimension.py @@ -99,21 +99,17 @@ def _elements(self): @property def hs_indices(self): '''Headers and Subtotals indices.''' + elms = self._elements + indices = [{ - 'anchor_ind': [ - i - for (i, el) in enumerate(self._elements) - if el['id'] == subtotal.anchor - ][0] - if (subtotal.anchor in [el['id'] for el in self._elements]) else - subtotal.anchor, - # -1, - 'inds': [ - i - for (i, el) in enumerate(self._elements) - if el['id'] in subtotal.args - ], - } for subtotal in self.subtotals] + '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] + return indices @property @@ -179,7 +175,6 @@ def labels(self, include_missing=False, include_transforms=False, ind_insert = next(( i for (i, x) in enumerate(labels_with_cat_ids) if x.get('id') == subtotal.anchor - # ), -1) + 1 ), subtotal.anchor) if ind_insert == 'top': ind_insert = 0