Skip to content

Commit

Permalink
Merge e04b7c3 into dd04970
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoarbitrio committed Mar 4, 2021
2 parents dd04970 + e04b7c3 commit 1cb9645
Show file tree
Hide file tree
Showing 26 changed files with 4,118 additions and 555 deletions.
270 changes: 168 additions & 102 deletions src/cr/cube/cube.py

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions src/cr/cube/cubepart.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ def evaluate(self, measure_expr):
raise NotImplementedError("Function {} is not available.".format(function))
return SingleSidedMovingAvgSmoother(self, measure_expr).values

@lazyproperty
def has_means(self):
"""True if cube-result includes means values."""
return self._cube.has_means

@lazyproperty
def ndim(self):
"""int count of dimensions for this partition."""
Expand Down Expand Up @@ -927,6 +922,15 @@ def smoothed_dimension_dict(self):
# from the matrix later on.
return self._columns_dimension._dimension_dict

@lazyproperty
def sum(self):
"""2D optional np.float64 ndarray of sum value for each table cell.
Cell value is `np.nan` for each cell corresponding to an inserted subtotal
(sum of addend cells cannot simply be added to get the sum of the subtotal).
Raises `ValueError` if the cube-result does not include a sum cube-measure.
"""
return self._assembler.sum

@lazyproperty
def summary_pairwise_indices(self):
return PairwiseSignificance(
Expand Down Expand Up @@ -1258,10 +1262,6 @@ def means(self):
Raises ValueError when accessed on a cube-result that does not contain a means
cube-measure.
"""
if not self._cube.has_means:
raise ValueError(
"`.means` is undefined for a cube-result without a means measure"
)
return self._assembler.means

@lazyproperty
Expand Down Expand Up @@ -1412,6 +1412,14 @@ def smoothed_dimension_dict(self):
"""dict, row dimension definition"""
return self._rows_dimension._dimension_dict

@lazyproperty
def sum(self):
"""1D np.float64 ndarray of sum for each row of strand.
Raises ValueError when accessed on a cube-result that does not contain a sum
cube-measure.
"""
return self._assembler.sum

@lazyproperty
def table_base_range(self):
"""[min, max] np.int64 ndarray range of unweighted-N for this stripe.
Expand Down Expand Up @@ -1569,4 +1577,4 @@ def _dimensions(self):
@lazyproperty
def _scalar(self):
"""The pre-transforms data-array for this slice."""
return MeansScalar(self._cube.counts, self._cube.unweighted_counts)
return MeansScalar(self._cube.means, self._cube.unweighted_counts)
4 changes: 4 additions & 0 deletions src/cr/cube/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ class MEASURE(enum.Enum):
COL_INDEX = "col_index"
COL_PERCENT = "col_percent"
MEAN = "mean"
SUM = "sum"
TABLE_STDERR = "table_stderr"
UNWEIGHTED_COUNT = "count_unweighted"
WEIGHTED_COUNT = "count_weighted"
Z_SCORE = "z_score"


NUMERIC_MEASURES = {MEASURE.SUM.value, MEASURE.MEAN.value}
14 changes: 9 additions & 5 deletions src/cr/cube/matrix/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ def means(self):
Raises `ValueError` if the cube-result does not include a means cube-measure.
"""
if not self._cube.has_means:
raise ValueError("cube-result does not include a means cube-measure")
return self._assemble_matrix(
NanSubtotals.blocks(self._cube_result_matrix.means, self._dimensions)
)
return self._assemble_matrix(self._measures.means.blocks)

@lazyproperty
def pvalues(self):
Expand Down Expand Up @@ -254,6 +250,14 @@ def rows_margin(self):
self._cube_result_matrix.rows_margin, self._row_subtotals, self._row_order
)

@lazyproperty
def sum(self):
"""2D optional np.float64 ndarray of sum for each cell.
Raises `ValueError` if the cube-result does not include a sum cube-measure.
"""
return self._assemble_matrix(self._measures.sum.blocks)

@lazyproperty
def table_base(self):
"""Scalar, 1D, or 2D ndarray of np.int64 unweighted-N for this slice.
Expand Down
Loading

0 comments on commit 1cb9645

Please sign in to comment.