Skip to content

Commit f4f992e

Browse files
add additional tests
1 parent f1a7fd0 commit f4f992e

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/cr/cube/matrix/subtotals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def subtotal_rows(cls, base_values, counts, default_insertions, dimensions):
408408
@lazyproperty
409409
def _column_subtotals(self):
410410
"""Sequence of _Subtotal object for each subtotal in columns-dimension."""
411-
return self._dimensions[-1].subtotals
411+
return self._dimensions[1].subtotals
412412

413413
def _multiple_subtrahends_or_addends(self, subtotal):
414414
"""Returns true if the subtotal has multiple addend or subtrahend terms."""
@@ -459,7 +459,7 @@ def _subtotal_columns(self):
459459

460460
def _subtotal_column(self, subtotal, default):
461461
"""Return (n_rows,) ndarray of values for `subtotal` column."""
462-
if self._dimensions[-1].dimension_type == DT.CAT_DATE and any(
462+
if self._dimensions[1].dimension_type == DT.CAT_DATE and any(
463463
subtotal.subtrahend_idxs
464464
):
465465
if self._multiple_subtrahends_or_addends(subtotal):

tests/integration/test_headers_and_subtotals.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,43 @@ def it_provide_residual_test_stats_including_hs(self):
27642764
class DescribeIntegrated_SubtotalDifferences:
27652765
"""TDD driver(s) for Subtotal Difference insertions."""
27662766

2767+
def it_computes_diff_for_cat_date_on_a_3D_cube(self):
2768+
cube = Cube(
2769+
CR.CAT_X_MR_X_CAT_DATE,
2770+
transforms={
2771+
"columns_dimension": {
2772+
"insertions": [
2773+
{
2774+
"function": "subtotal",
2775+
"args": [1],
2776+
"kwargs": {"positive": [1], "negative": [2]},
2777+
"anchor": "top",
2778+
"name": "diff1",
2779+
},
2780+
{
2781+
"function": "subtotal",
2782+
"args": [1],
2783+
"kwargs": {"positive": [2, 3]},
2784+
"anchor": "top",
2785+
"name": "sub1",
2786+
},
2787+
]
2788+
}
2789+
},
2790+
)
2791+
slice_ = cube.partitions[0]
2792+
assert len(cube.dimensions) == 3
2793+
# first 2 cols are the insertions
2794+
assert slice_.row_proportions[:, :2] == pytest.approx(
2795+
np.array(
2796+
[
2797+
[-0.26136364, 0.77272727],
2798+
[0.29411765, 0.47058824],
2799+
[-0.20338983, 0.74576271],
2800+
]
2801+
)
2802+
)
2803+
27672804
def it_computes_diff_for_cat_date(self):
27682805
strand = Cube(
27692806
CR.CAT_DATE,

0 commit comments

Comments
 (0)