Skip to content

Patch bool coercion bug in conditional expectancy matrix enrichment #1

Description

@kvandre12-commits

Root cause identified in scripts/build_conditional_expectancy_matrix.py.

The pipeline is failing during enrich_metrics() because pandas logical OR operations are being applied between float64 columns (created via NaN/SQLite coercion) and boolean Series.

Current failing logic:

out["_direct_fill"] = (
    safe_num(out, ["direct_fill"], 0).fillna(0)
    | out["fill_path_type"].astype(str).str.upper().eq("DIRECT_FILL")
).astype(int)

and:

out["_failed_fill"] = (
    safe_num(out, ["failed_fill"], 0).fillna(0)
    | out["fill_path_type"].astype(str).str.upper().isin([
        "FAILED_FILL_CONTINUATION",
        "PARTIAL_FILL_REJECT",
        "LIQUIDITY_VACUUM_CONTINUATION",
    ])
).astype(int)

This produces:

TypeError: unsupported operand type(s) for | : 'float' and 'bool'

Recommended fix:

Add helper:

def safe_bool(df, candidates, default=False):
    return (
        safe_num(df, candidates, int(default))
        .fillna(0)
        .astype(bool)
    )

Then replace failing sections with:

out["_fill"] = safe_bool(
    out,
    ["filled", "gap_filled", "fill_success"]
).astype(int)

out["_direct_fill"] = (
    safe_bool(out, ["direct_fill"])
    | out["fill_path_type"]
        .astype(str)
        .str.upper()
        .eq("DIRECT_FILL")
).astype(int)

out["_failed_fill"] = (
    safe_bool(out, ["failed_fill"])
    | out["fill_path_type"]
        .astype(str)
        .str.upper()
        .isin([
            "FAILED_FILL_CONTINUATION",
            "PARTIAL_FILL_REJECT",
            "LIQUIDITY_VACUUM_CONTINUATION",
        ])
).astype(int)

Expected result:

  • classify auction fill paths succeeds
  • conditional_expectancy_matrix populates
  • SharpEdge 2.0 report loads matrix successfully
  • downstream report publishing restored

This is schema/dtype normalization rather than orchestration failure. The merged YAML workflow structure is now functioning correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions