Purging and embargo metadata

q.label.purging_metadata exports running label endpoints and the first safe observation after an optional bar embargo. It prepares canonical event-lifetime metadata; actual fold construction belongs in q.dataset.

The running maximum matters when a later event ends before an earlier, longer event.

import pandas as pd

import qrt as q

observations = pd.date_range("2026-01-01", periods=9, name="datetime")
end_times = pd.Series(
    observations[[5, 3, 7]],
    index=observations[[0, 1, 4]].rename("event_time"),
)
metadata = q.label.purging_metadata(
    observations,
    end_times,
    embargo=1,
)
metadata
end_time start_position end_position max_end_time max_end_position overlaps_previous next_safe_time next_safe_position
event_time
2026-01-01 2026-01-06 0 5 2026-01-06 5 False 2026-01-08 7
2026-01-02 2026-01-04 1 3 2026-01-06 5 True 2026-01-08 7
2026-01-05 2026-01-08 4 7 2026-01-08 7 True NaT <NA>

max_end_time is cumulative across ordered events. next_safe_time skips the observation immediately after that endpoint when embargo=1; missing values mean the safe point lies beyond available data.

Back to top