Skip to content

Commit

Permalink
additional cases -> integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoarbitrio committed Nov 18, 2024
1 parent eefc004 commit a014cc7
Showing 1 changed file with 69 additions and 24 deletions.
93 changes: 69 additions & 24 deletions tests/integration/test_headers_and_subtotals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2806,30 +2806,55 @@ def it_computes_diff_for_cat_date(self):
)
)

def it_computes_diff_for_cat_x_cat_date_with_subdiffs_on_column(self):
slice_ = Cube(
CR.CAT_X_CAT_DATE,
def it_computes_nan_diff_for_cat_date_with_multiple_addend_or_subtrahend(self):
strand = Cube(
CR.CAT_DATE,
transforms={
"columns_dimension": {
"rows_dimension": {
"insertions": [
{
"function": "subtotal",
"args": [1],
"kwargs": {"positive": [3], "negative": [2]},
"kwargs": {"positive": [19, 20], "negative": [21]},
"anchor": "top",
"name": "diff1",
},
{
"function": "subtotal",
"args": [1],
"kwargs": {"positive": [1, 2]},
"kwargs": {"positive": [21, 23]},
"anchor": "top",
"name": "sub1",
},
]
}
},
).partitions[0]
assert np.isnan(
strand.table_proportions[0]
) # nan insertion because the diff subtotal has multiple positive terms

def it_computes_diff_for_cat_x_cat_date_with_subdiffs_on_column(self):
insertions = [
{
"function": "subtotal",
"args": [1],
"kwargs": {"positive": [3], "negative": [2]},
"anchor": "top",
"name": "diff1",
},
{
"function": "subtotal",
"args": [1],
"kwargs": {"positive": [1, 2]},
"anchor": "top",
"name": "sub1",
},
]
slice_ = Cube(
CR.CAT_X_CAT_DATE,
transforms={"columns_dimension": {"insertions": insertions}},
).partitions[0]
assert slice_.diff_column_idxs == (0,)
assert slice_.column_proportions == pytest.approx(
np.array(
Expand All @@ -2844,6 +2869,16 @@ def it_computes_diff_for_cat_x_cat_date_with_subdiffs_on_column(self):
),
rel=1e-4,
)
# change the insertion to test that multiple addend or subtrahend will generate
# a nan value
insertions[0]["kwargs"]["negative"].append(1)
slice2 = Cube(
CR.CAT_X_CAT_DATE,
transforms={"columns_dimension": {"insertions": insertions}},
).partitions[0]
assert slice2.column_proportions[:, 0] == pytest.approx(
np.array([np.nan, np.nan, np.nan, np.nan, np.nan]), nan_ok=True
)

def it_computes_diff_for_cat_x_cat_date_with_subdiffs_on_both(self):
slice_ = Cube(
Expand Down Expand Up @@ -3011,27 +3046,26 @@ def it_computes_diff_for_cat_date_x_cat_with_subdiffs_on_both(self):
)

def it_computes_diff_for_cat_date_x_cat_with_subdiffs_on_rows(self):
insertions = [
{
"function": "subtotal",
"args": [1],
"kwargs": {"positive": [3], "negative": [2]},
"anchor": "top",
"name": "diff_row1",
},
{
"function": "subtotal",
"args": [1],
"kwargs": {"positive": [1, 2]},
"anchor": "top",
"name": "subtot_row1",
},
]
slice_ = Cube(
CR.CAT_DATE_X_CAT,
transforms={
"rows_dimension": {
"insertions": [
{
"function": "subtotal",
"args": [1],
"kwargs": {"positive": [3], "negative": [2]},
"anchor": "top",
"name": "diff_row1",
},
{
"function": "subtotal",
"args": [1],
"kwargs": {"positive": [1, 2]},
"anchor": "top",
"name": "subtot_row1",
},
]
},
"rows_dimension": {"insertions": insertions},
},
).partitions[0]
assert slice_.diff_row_idxs == (0,)
Expand All @@ -3053,6 +3087,17 @@ def it_computes_diff_for_cat_date_x_cat_with_subdiffs_on_rows(self):
]
)
)
# change the insertion to test that multiple addend or subtrahend will generate
# a nan value
insertions[0]["kwargs"]["negative"].append(1)
slice2 = Cube(
CR.CAT_DATE_X_CAT,
transforms={"rows_dimension": {"insertions": insertions}},
).partitions[0]
assert slice2.row_proportions[0] == pytest.approx(
np.array([np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]),
nan_ok=True,
)

def it_computes_measures_for_1D_cat_with_subdiffs(self):
strand = Cube(
Expand Down

0 comments on commit a014cc7

Please sign in to comment.