Skip to content

Commit

Permalink
Merge branch 'bring-coverage-to-100-percent-#157720119' into rel-5.2.123
Browse files Browse the repository at this point in the history
  • Loading branch information
Crunch.io Jenkins Account committed Jun 29, 2018
2 parents 74f7f51 + 39d5db6 commit 0ca416f
Show file tree
Hide file tree
Showing 9 changed files with 6,018 additions and 82 deletions.
53 changes: 0 additions & 53 deletions src/cr/cube/crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,29 +512,6 @@ def _adjust_axis(self, axis):

return tuple(new_axis)

def _transform_table(self, table, include_transforms_for_dims):
table = self._transform(
table,
include_transforms_for_dims,
inflate=True,
)
return table

def _inflate_dim(self, array, axis):
# Explicitly check if axis is tuple (which could be the case for doing
# cell percentages across 3D cube, when the axis is set to (1, 2)).
# Python 3 doesn't support tuple to int conversion, and we have to
# check it manually.
if (axis and not isinstance(axis, tuple) and
axis > 0 and len(array.shape) == 1):
# If any of the dimensions has only one element, it's flattened
# from the resulting array (as a part of the MR pre-processing).
# This can lead to a potential inconsistency between dimensions
# and axes, and we need to restore one dimension in this case.
array = array[:, np.newaxis]

return array

@lazyproperty
def is_univariate_ca(self):
'''Check if cube is a just the CA ("ca x cat" or "cat x ca" dims)'''
Expand Down Expand Up @@ -568,19 +545,6 @@ def dim_types(self):
def ndim(self):
return len(self.dimensions)

@lazyproperty
def ind_selected(self):
return self._get_mr_slice()

@lazyproperty
def ind_non_selected(self):
return self._get_mr_slice(selected=False)

@lazyproperty
def valid_indices(self):
'''Valid indices of all dimensions (exclude missing).'''
return [dim.valid_indices(False) for dim in self.dimensions]

@property
def valid_indices_with_selections(self):
'''Get all valid indices (including MR selections).'''
Expand Down Expand Up @@ -631,23 +595,6 @@ def is_double_mr(self):
'''Check if cube has 2 MR dimensions.'''
return True if isinstance(self.mr_dim_ind, tuple) else False

@lazyproperty
def double_mr_non_selected_inds(self):
'''Gets all combinations of non-selected slices for any double MR cube.
For double MR cubes, we need combinations of (selected) with
(selected + non_selected) for all combinations of MR x MR, but we also
need other potential dimensions included
'''
# This represents an index in between MR dimensions (at this point we
# know there are two). It's used subsequently, for creating the
# combined conditional slices, where we have to take 'selected' for
# one MR, and selected AND non-selected for the other.
inflect = self.mr_dim_ind[1] + 1
ind_ns_0 = self.ind_selected[:inflect] + self.ind_non_selected[inflect:]
ind_ns_1 = self.ind_non_selected[:inflect] + self.ind_selected[inflect:]
return self.ind_non_selected, ind_ns_0, ind_ns_1

# Static methods

@staticmethod
Expand Down
30 changes: 23 additions & 7 deletions src/cr/cube/cube_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ def _update_args(self, kwargs):
if self.ca_as_0th:
axis = kwargs.get('axis', False)
if axis is None:
# TODO: Write detailed explanation here in comments.
# Special case for CA slices (in multitables).
# Special case for CA slices (in multitables). In this case,
# we need to calculate a measurement across CA categories
# dimension (and not across items, because it's not
# allowed). The value for the axis parameter of None, would
# incur the items dimension, and we don't want that.
kwargs['axis'] = 1
return kwargs

Expand Down Expand Up @@ -118,7 +121,7 @@ def _update_result(self, result):
def _call_cube_method(self, method, *args, **kwargs):
kwargs = self._update_args(kwargs)
result = getattr(self._cube, method)(*args, **kwargs)
if method in ('labels', 'inserted_hs_indices'):
if method == 'inserted_hs_indices':
if not self.ca_as_0th:
result = result[-2:]
return result
Expand Down Expand Up @@ -156,19 +159,32 @@ def mr_dim_ind(self):
mr_dim_ind = self._cube.mr_dim_ind
if self.ndim == 3:
if isinstance(mr_dim_ind, int):
if mr_dim_ind == 0:
# If only the 0th dimension of a 3D is an MR, the sliced
# don't actuall have the MR... Thus return None.
return None
return mr_dim_ind - 1
elif isinstance(mr_dim_ind, tuple):
return tuple(i - 1 for i in mr_dim_ind)
# If MR dimension index is a tuple, that means that the cube
# (only a 3D one if it reached this path) has 2 MR dimensions.
# If any of those is 0 ind dimension we don't need to include
# in the slice dimension (because the slice doesn't see the tab
# that it's on). If it's 1st and 2nd dimension, then subtract 1
# from those, and present them as 0th and 1st dimension of the
# slice. This can happend e.g. in a CAT x MR x MR cube (which
# renders MR x MR slices).
mr_dim_ind = tuple(i - 1 for i in mr_dim_ind if i)
return mr_dim_ind if len(mr_dim_ind) > 1 else mr_dim_ind[0]

return mr_dim_ind

@property
def ca_main_axis(self):
'''For univariate CA, the main axis is the categorical axis'''
ca_ind = self.dim_types.index('categorical_array')
if ca_ind is not None:
try:
ca_ind = self.dim_types.index('categorical_array')
return 1 - ca_ind
else:
except:
return None

def labels(self, hs_dims=None, prune=False):
Expand Down
5 changes: 0 additions & 5 deletions src/cr/cube/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ def _transform_anchor(self, subtotal):
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
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ def _load(cube_file):
FOOD_GROOPS_X_STARTTIME_X_NORDIC_COUNTRIES = _load(
'food-groops-x-starttime-x-nordic-countries.json',
)
MR_X_CAT_X_MR_PRUNE = _load('mr-x-cat-x-mr-prune.json')
HUFFPOST_ACTIONS_X_HOUSEHOLD = _load('huffpost-actions-x-household.json')
Loading

0 comments on commit 0ca416f

Please sign in to comment.