code: def to_labels(
      lists: Union[
          List[Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]],
          Dict[
              str,
              List[
                  Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]
              ],
          ],
      ],
      time_index: pd.DatetimeIndex,
      freq_as_period: bool = True,
  ) -> Union[pd.Series, pd.DataFrame]:
      """Convert event list to binary series along a time index.
  
      Parameters
      ----------
      lists: list or dict
          A list of events, or a dict of lists of events.
  
          - If list, a list of events where an event is a pandas Timestamp if it
            is instantaneous or a 2-tuple of pandas Timestamps if it is a closed
            time interval.
          - If dict, each key-value pair represents an independent list of
            events.
  
      time_index: pandas DatatimeIndex
          Time index to build the label series.
  
      freq_as_period: bool, optional
          Whether to regard time index with regular frequency (i.e. attribute
          `freq` of time index is not None) as time intervals.
  
          For example, DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03',
          '2017-01-04', '2017-01-05'], dtype='datetime64[ns]', freq='D') has
          daily frequency. If freq_as_period=True, each time piont represents
          that day, and that day will be marked positive if an event in the event
          list overlaps with the period of that day (24 hours). Otherwsie, each
          time point represents the instantaneous time instance of 00:00:00 on
          that day, and that time point will be marked positive if an event in
          the event list covers it.
  
          Default: True.
  
      Returns
      -------
      pandas Series or DataFrame
          Series of binary labels.
  
          - If input is asingle list, the output is a Series.
          - If input is a dict of lists, the output is a DataFrame where each
            column corresponds a list in the dict.
  
      """
  
      if not isinstance(time_index, pd.DatetimeIndex):
          raise TypeError(
              "Time index must be a pandas DatetimeIndex object."
          )
  
      if not time_index.is_monotonic_increasing:
          raise ValueError("Time index must be monotoic increasing.")
  
      if isinstance(lists, list):
          labels = pd.Series(False, index=time_index)  # type: pd.Series
          lists = validate_events(lists)
          if freq_as_period and (time_index.freq is not None):
              period_end = pd.date_range(
                  start=time_index[1],
                  periods=len(time_index),
                  freq=time_index.freq,
              ) - pd.Timedelta(
                  "1ns"
              )  # type: pd.DatetimeIndex
              for event in lists:
                  isOverlapped = pd.Series(
                      index=time_index, dtype=bool
                  )  # type: pd.Series
                  if isinstance(event, tuple):
                      isOverlapped = (time_index <= event[1]) & (
                          period_end >= event[0]
                      )
                  else:
                      isOverlapped = (time_index <= event) & (
                          period_end >= event
                      )
                  labels.loc[isOverlapped] = True
          else:
              for event in lists:
                  if isinstance(event, tuple):
                      labels.loc[
                          (labels.index >= event[0])
                          & (labels.index <= event[1])
                      ] = True
                  else:
                      labels.loc[labels.index == event] = True
          return labels
      elif isinstance(lists, dict):
          labels_df = pd.DataFrame(
              False, index=time_index, columns=lists.keys()
          )  # pd.DataFrame
          for col, key in zip(labels_df.columns, lists.keys()):
              labels_df[col] = to_labels(
                  lists[key], time_index, freq_as_period
              )
          return labels_df
      else:
          raise TypeError("Argument `lists` must be a list or a dict.")
  
file_path: adtk/src/adtk/data/_data.py
imports: from typing import Dict, List, Optional, Tuple, Union, overload
  import numpy
  import pandas
label_desc: Use image node_id 8 for calling a global function with example usage: to_labels(lists, time_index, freq_as_period) and returns: labels, labels_df