isora-tax-administration / pipeline /tests /test_crosswalk.py
FrenchCastle's picture
ISORA FY2014-FY2024 v1.0.0: observations, indicators, indicator_history, jurisdictions, coverage, revisions + card, license, pipeline
cbd273f verified
Raw
History Blame Contribute Delete
2.48 kB
import pandas as pd
from isora_hf.crosswalk import build_indicator_history, label_similarity, normalize_label
def test_normalize_label_ignores_case_punctuation_and_spacing():
assert normalize_label("Annual report - prepared") == normalize_label(
"annual report prepared."
)
def test_similarity_is_one_for_equivalent_labels_and_none_when_missing():
assert label_similarity("Annual report - prepared", "Annual report prepared") == 1.0
assert label_similarity(None, "x") is None
def _indicators():
return pd.DataFrame(
[
{
"questionnaire_generation": "ISORA 2016",
"indicator_code": "A",
"label": "Staff total",
"indicator_type": "count",
},
{
"questionnaire_generation": "ISORA 2018",
"indicator_code": "A",
"label": "Staff total",
"indicator_type": "count",
},
{
"questionnaire_generation": "ISORA 2020+",
"indicator_code": "A",
"label": "Total staff (FTE)",
"indicator_type": "count",
},
{
"questionnaire_generation": "ISORA 2016",
"indicator_code": "B",
"label": "Old only",
"indicator_type": "binary",
},
]
)
def _observations():
return pd.DataFrame(
[
{"indicator_code": "A", "fiscal_year": 2014, "value_status": "value"},
{"indicator_code": "A", "fiscal_year": 2024, "value_status": "not_available"},
{"indicator_code": "B", "fiscal_year": 2015, "value_status": "value"},
]
)
def test_history_flags_label_changes_and_single_generation_codes():
hist = build_indicator_history(_indicators(), _observations()).set_index("indicator_code")
a = hist.loc["A"]
assert a["in_2016"] and a["in_2018"] and a["in_2020plus"]
assert a["label_changed_2016_to_2018"] is False or a["label_changed_2016_to_2018"] == False
assert a["label_changed_2018_to_2020plus"] == True
assert a["comparability_flag"] == "label_changed"
assert a["fiscal_years_with_data"] == [2014, 2024]
assert a["n_observations"] == 2 and a["n_observations_with_value"] == 1
b = hist.loc["B"]
assert b["comparability_flag"] == "single_generation"
assert pd.isna(b["label_2018"]) and b["n_generations"] == 1