Skip to content

mostlyright.core.source_identity

Canonical home for the assert_source_identity source-pinning gate.

assert_source_identity is a source-identity VALIDATOR utility, not a “mode”. Phase 30 (D-04) relocates its canonical implementation here from the deprecated mostlyright.mode2 module and re-exports it from mostlyright.core, so callers reach it as from mostlyright.core import assert_source_identity without touching the deprecated module path.

Import direction is one-way: core DEFINES the function; mode2 back-imports it for backward compatibility. The reverse (core importing mode2) would be a partial-initialization cycle — mode2 already imports mostlyright.core.exceptions at module load.

assert_source_identity(df, expected_source, *)Raise SourceMismatchError if any row’s source != expected.

mostlyright.core.source_identity.assert_source_identity(df, expected_source, , role=‘observations’)

Section titled “mostlyright.core.source_identity.assert_source_identity(df, expected_source, , role=‘observations’)”

Raise SourceMismatchError if any row’s source != expected.

A defense-in-depth per-row gate: mirrors the per-row check in mostlyright.core.validator.validate_dataframe() but at the source-pinned dispatch layer so callers get a role-flavored error message when a pinned single-source frame carries a foreign row.

  • Parameters:
    • df (DataFrame) – The DataFrame to check. If it has no source column the function is a silent no-op (the Validator handles that case).
    • expected_source (str) – The source every row must carry.
    • role (str) – The role label surfaced on the raised error (default "observations").
  • Raises: SourceMismatchError – when one or more rows carry a source other than expected_source.
  • Return type: None