33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
"""What this module covers: `models.annotations`: `@checked_frame` fails a node whose frame breaks its schema without
|
|
quoting the values.
|
|
|
|
Fixtures: none; each test builds a one-function graph with `ad_hoc_utils`.
|
|
"""
|
|
|
|
import pandas as pd
|
|
import pandera.pandas as pandera
|
|
import pytest
|
|
from hamilton import ad_hoc_utils, driver
|
|
from hamilton.data_quality.base import DataValidationError
|
|
|
|
from models.annotations import checked_frame
|
|
|
|
MEMBERS = pandera.DataFrameSchema({"pac_id": pandera.Column(int, pandera.Check.gt(0))}, name="members")
|
|
|
|
|
|
def test_a_failing_frame_check_names_columns_and_counts_not_values():
|
|
"""Pins down: `@checked_frame` stops the node and says which column and check failed and how often, without the
|
|
failing values, which are members' data. Fails if the message goes back to pandera's report of failure cases."""
|
|
@checked_frame(MEMBERS)
|
|
def members(cohort: pd.DataFrame) -> pd.DataFrame:
|
|
return cohort
|
|
|
|
dr = driver.Builder().with_modules(ad_hoc_utils.create_temporary_module(members)).build()
|
|
|
|
with pytest.raises(DataValidationError) as failed:
|
|
dr.execute(["members"], inputs={"cohort": pd.DataFrame({"pac_id": [-48213, -48214, 7]})})
|
|
|
|
message = str(failed.value)
|
|
assert "pac_id" in message and "failed 2 time(s)" in message
|
|
assert "48213" not in message and "48214" not in message
|