mask(frame, binary, keep_value=1.0, name=None, metadata=None)

Apply mask to long-form panel inputs.

Parameters

frame : Panel | Graph
Input numeric Panel or single-output Graph. binary : Panel | Graph
Binary projection input. Cells equal to 1 are retained; other cells are masked. keep_value : float, default 1.0
keep_value argument. name : str | None, default None
Optional graph-node name. A generated name is used when omitted. metadata : Mapping[str, Any] | None, default None
Optional metadata stored on the graph node.

Returns

Graph
Lazy single-output graph. Call .compute() to materialize a Panel.

Examples

import polars as pl

from bagelquant_core import Domain, Panel
from bagelquant_core.composer import mask

domain = Domain(calendar=["2024-01-02", "2024-01-03", "2024-01-04"], universe=["a", "b"])
left = Panel.from_domain(
    pl.DataFrame({
        "time": ["2024-01-02", "2024-01-03", "2024-01-04"] * 2,
        "asset_id": ["a"] * 3 + ["b"] * 3,
        "value": [1.0, 2.0, 4.0, 2.0, 3.0, 8.0],
    }),
    domain,
)
right = Panel.from_domain(
    pl.DataFrame({
        "time": ["2024-01-02", "2024-01-03", "2024-01-04"] * 2,
        "asset_id": ["a"] * 3 + ["b"] * 3,
        "value": [1.0, 1.0, 2.0, 1.0, 2.0, 4.0],
    }),
    domain,
)

result = mask(left, right, keep_value=1.0).compute().data
print(result)

Notes

Inputs are aligned by (time, asset_id) before the operation runs.