lair.pcaps.build_pcap_mask#

lair.pcaps.build_pcap_mask(index, events)[source]#

Build a boolean mask for PCAP events.

Parameters:
  • index (pd.Index) – The datetime-like index to build the mask for. Naive times follow the UTC rule; tz-aware times are converted.

  • events (pd.DataFrame) – The DataFrame of PCAP events (naive UTC or tz-aware start/end).

Returns:

pd.Series – A boolean mask where True indicates a time within a PCAP event.

Return type:

Series

See also

determine_pcap_events

Finds the events.

filter_pcap_events

Drops the rows the mask marks.

Examples

>>> import pandas as pd
>>> from lair.pcaps import build_pcap_mask
>>> events = pd.DataFrame(
...     {
...         "start": pd.to_datetime(["2024-01-01 12:00"]),
...         "end": pd.to_datetime(["2024-01-03 11:59:59"]),
...     }
... )
>>> times = pd.date_range("2024-01-01 00:00", periods=6, freq="12h")
>>> build_pcap_mask(times, events).astype(int).tolist()
[0, 1, 1, 1, 1, 0]