Skip to content

Commit 3132442

Browse files
authored
Albrja/mic-6334/Rename strata to stratifications (#75)
Albrja/mic-6334/Rename strata to stratifications Rename uses of strata to stratifications to keep naming consistent - *Category*: Refactor - *JIRA issue*: https://jira.ihme.washington.edu/browse/MIC-6334 Changes and notes -rename strata to stratifications ### Testing <!-- Details on how code was verified, any unit tests local for the repo, regression testing, etc. At a minimum, this should include an integration test for a framework change. Consider: plots, images, (small) csv file. -->
1 parent 8885646 commit 3132442

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/vivarium_testing_utils/automated_validation/comparison.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ def _align_datasets(
284284
for x in self.reference_data.index.names
285285
if x not in reference_indexes_to_drop
286286
]
287-
aggregated_reference_data = self._aggregate_strata_reference(
287+
aggregated_reference_data = self._aggregate_reference_stratifications(
288288
self.reference_data,
289-
strata=stratifications,
289+
stratifications=stratifications,
290290
)
291291

292292
# If the test data has any index levels that are not in the reference data, marginalize
@@ -323,23 +323,25 @@ def _align_datasets(
323323
## At this point, the only non-common index levels should be scenarios and draws.
324324
return stratified_test_data, aggregated_reference_data
325325

326-
def _aggregate_strata_reference(
327-
self, data: pd.DataFrame, strata: Collection[str] = ()
326+
def _aggregate_reference_stratifications(
327+
self, data: pd.DataFrame, stratifications: Collection[str] = ()
328328
) -> pd.DataFrame:
329-
for stratum in strata:
329+
for stratification in stratifications:
330330
if (
331-
stratum not in data.index.names
332-
and stratum not in self.reference_weights.index.names
331+
stratification not in data.index.names
332+
and stratification not in self.reference_weights.index.names
333333
):
334334
raise ValueError(
335-
f"Stratum '{stratum}' not found in reference data or weights."
335+
f"Stratum '{stratification}' not found in reference data or weights."
336336
)
337337

338-
strata = list(strata)
338+
stratifications = list(stratifications)
339339
# Retain input_draw, _aggregate_over_draws is the only place we should aggregate over draws.
340-
if DRAW_INDEX in data.index.names and DRAW_INDEX not in strata:
341-
strata.append(DRAW_INDEX)
342-
weighted_avg = calculations.weighted_average(data, self.reference_weights, strata)
340+
if DRAW_INDEX in data.index.names and DRAW_INDEX not in stratifications:
341+
stratifications.append(DRAW_INDEX)
342+
weighted_avg = calculations.weighted_average(
343+
data, self.reference_weights, stratifications
344+
)
343345
# Reference data can be a float or dataframe. Convert floats so dataframes are aligned
344346
if not isinstance(weighted_avg, pd.DataFrame):
345347
weighted_avg = pd.DataFrame(

tests/automated_validation/test_comparison.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,13 @@ def test_fuzzy_comparison_align_datasets_calculation(
456456
)
457457

458458

459-
def test_aggregate_strata(
459+
def test_aggregate_stratifications(
460460
mock_ratio_measure: RatioMeasure,
461461
test_data: dict[str, pd.DataFrame],
462462
reference_data: pd.DataFrame,
463463
reference_weights: pd.DataFrame,
464464
) -> None:
465-
"""Test that aggregate_strata correctly aggregates data."""
465+
"""Test that aggregate_stratifications correctly aggregates data."""
466466
comparison = FuzzyComparison(
467467
mock_ratio_measure,
468468
DataSource.SIM,
@@ -472,7 +472,9 @@ def test_aggregate_strata(
472472
reference_weights,
473473
)
474474

475-
aggregated = comparison._aggregate_strata_reference(reference_data, ["age", "sex"])
475+
aggregated = comparison._aggregate_reference_stratifications(
476+
reference_data, ["age", "sex"]
477+
)
476478
# (0, Male) = (0.12 * 0.15 + 0.29 * 0.35) / (0.15 + 0.35)
477479
expected = pd.DataFrame(
478480
{
@@ -493,7 +495,7 @@ def test_aggregate_strata(
493495
pd.testing.assert_frame_equal(aggregated, expected)
494496

495497
with pytest.raises(ValueError, match="not found in reference data or weights"):
496-
comparison._aggregate_strata_reference(reference_data, ["dog", "cat"])
498+
comparison._aggregate_reference_stratifications(reference_data, ["dog", "cat"])
497499

498500

499501
def _add_draws_to_dataframe(df: pd.DataFrame, draw_values: list[int]) -> pd.DataFrame:

0 commit comments

Comments
 (0)