Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions arch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"institutional_sector",
}
ALLOWED_AGGREGATIONS = {
"count",
"sum",
"mean",
"median",
Expand Down Expand Up @@ -245,7 +244,7 @@ def build_fact_key(fact: AggregateFact) -> str:
def build_label(fact: AggregateFact) -> str:
"""Build a human-readable label from fact metadata."""
concept = _humanize(fact.measure.concept)
aggregation = _humanize(fact.aggregation.method)
aggregation = _aggregation_label(fact)
entity = _humanize(fact.entity.name)
period = f"{fact.period.value} {_humanize(fact.period.type)}"
geography = fact.geography.name or fact.geography.id
Expand All @@ -259,6 +258,12 @@ def build_label(fact: AggregateFact) -> str:
return label


def _aggregation_label(fact: AggregateFact) -> str:
if fact.aggregation.method == "sum" and fact.measure.unit == "count":
return "count"
return _humanize(fact.aggregation.method)


def build_aggregate_constraints(
fact: AggregateFact,
) -> tuple[AggregateConstraint, ...]:
Expand Down
6 changes: 3 additions & 3 deletions arch/fixtures/consumer_facts.jsonl

Large diffs are not rendered by default.

160 changes: 80 additions & 80 deletions arch/fixtures/facts.jsonl

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions arch/jurisdictions/us/soi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
IRS_SOI_TOTAL_WAGES_SOURCE_CONCEPT = "irs_soi.total_wages"
IRS_SOI_TOTAL_WAGES_RETURNS_SOURCE_CONCEPT = "irs_soi.returns_with_total_wages"
AGI_CONCEPT_EVIDENCE_URL = (
"https://uscode.house.gov/view.xhtml?"
"req=(title:26%20section:62%20edition:prelim)"
"https://uscode.house.gov/view.xhtml?req=(title:26%20section:62%20edition:prelim)"
)
AGI_CONCEPT_EVIDENCE_NOTES = (
"IRS SOI Table 1.1 reports adjusted gross income for individual income tax "
Expand Down Expand Up @@ -171,7 +170,7 @@ def _legacy_soi_table_1_1_source_record_specs(
measure_id="return_count",
concept="irs_soi.individual_income_tax_returns",
unit="count",
aggregation="count",
aggregation="sum",
filters=filters,
),
_legacy_source_record_spec(
Expand Down Expand Up @@ -215,7 +214,7 @@ def _legacy_soi_table_1_1_source_record_specs(
measure_id="income_tax_after_credits_returns",
concept="irs_soi.returns_with_income_tax_after_credits",
unit="count",
aggregation="count",
aggregation="sum",
filters=filters,
),
]
Expand Down Expand Up @@ -280,9 +279,7 @@ def _legacy_source_record_spec(
legal_vintage: str | None = None,
value_scale: int = 1,
) -> SourceRecordSpec:
source_record_id = (
f"irs_soi.ty{year}.table_1_1.{range_id}.{measure_id}"
)
source_record_id = f"irs_soi.ty{year}.table_1_1.{range_id}.{measure_id}"
return SourceRecordSpec(
source_record_id=source_record_id,
selector=CellSelectorSpec(
Expand Down
19 changes: 15 additions & 4 deletions arch/source_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import yaml

from arch.core import (
ALLOWED_AGGREGATIONS,
Aggregation,
AggregateConstraint,
EntityDimension,
Expand Down Expand Up @@ -1065,9 +1066,7 @@ def _validate_record_set_authoring(
errors.append(
SourcePackageIssue(
code="malformed_row_column",
message=(
"Row column must be an Excel column name like B or AA."
),
message=("Row column must be an Excel column name like B or AA."),
record_set_id=record_set.record_set_id,
row_id=row.value_id,
)
Expand Down Expand Up @@ -1100,6 +1099,18 @@ def _validate_record_set_authoring(
measure_id=measure.measure_id,
)
)
if measure.aggregation not in ALLOWED_AGGREGATIONS:
errors.append(
SourcePackageIssue(
code="malformed_measure_aggregation",
message=(
"Measure aggregation must be one of "
f"{sorted(ALLOWED_AGGREGATIONS)!r}."
),
record_set_id=record_set.record_set_id,
measure_id=measure.measure_id,
)
)
if measure.concept_relation == "exact" and not (
measure.concept_evidence_url or measure.concept_evidence_notes
):
Expand Down Expand Up @@ -1835,5 +1846,5 @@ def _scaffold_template(
column: B
concept: TODO_concept
unit: count
aggregation: count
aggregation: sum
"""
Loading
Loading