Skip to content

expect_dataframe

Snapshot testing and expectations for dataframes.

DataframeExpect

DataframeExpect(
    settings: Settings, snappylapy_session: SnapshotSession
)

Bases: BaseSnapshot['pd.DataFrame']

Snapshot testing for dataframes.

Initialize the base snapshot.

column_not_to_contain_nulls

column_not_to_contain_nulls(
    column_name: str,
) -> DataframeExpect

Check that a column does not contain null values.

columns_not_to_contain_nulls

columns_not_to_contain_nulls(
    column_names: list[str] | None = None,
) -> DataframeExpect

Check that multiple columns do not contain null values.

columns_to_match_regex

columns_to_match_regex(
    column_to_regex: dict[str, str],
) -> DataframeExpect

Check that columns match regex.

dict[str, str]

Dictionary of column names to regex patterns. The column name is the key and the regex pattern is the value.

compare_snapshot_data

compare_snapshot_data(
    snapshot_data: bytes, test_data: bytes
) -> None

Compare snapshot data with test data.

Optimizations is needed for large data since difflib used in the pytest_assertion plugin rewrites are very slow when there are many diffs in large strings.

to_align_with_snapshot

to_align_with_snapshot() -> None

Non-deterministic snapshot alignment.

Data structure specific implementations, can fuzzy match strings or compare data structures. The default behavior defined is always accepting the snapshot, but fails if the snapshot has not been created yet.

to_match_snapshot

to_match_snapshot() -> None

Assert test results match the snapshot.

require_pandas

require_pandas(func: F) -> F

Decorate to require pandas for the function.