code: def min_max_lag_order(lag_dict=None, agg_lag_dict=None):
      """Calculating min and max lag order needed given the prescribed lags
      in the model.
  
      :param lag_dict: dict
          dictionary with these fields:
  
              - "orders": Optional[List(int)]
               a list of positive integers or None
              - "max_order": Optional[int]
  
          see function "build_lag_df" arguments with same names
          to understand use case
      :param agg_lag_dict: dict
          dictionary with these items
  
              - "orders_list": List[List[int]], default: []
                  a list of lists of integers
              - "interval_list": List[tuple[int]], default: []
                  a list of int tuples of each with length 2
  
          see function "build_agg_lag_df" arguments with same names
          to understand use-case
  
      :return: dict[str, float]
          dictionary with two items with keys:
  
              - "max_order": the maximum lag used
              - "min_order": the mimimum lag used
      """
      max_order = 0
      min_order = np.inf
  
      if lag_dict is not None:
          if lag_dict.get("orders") is not None:
              max_order = np.nanmax(lag_dict["orders"])
              min_order = np.nanmin(lag_dict["orders"])
          elif lag_dict.get("max_order") is not None:
              max_order = np.nanmax([lag_dict["max_order"], max_order])
              # if max_order is not None in `lag_dict`
              # then lags 1, 2, ..., `max_order` are used
              # Therfore `min_order` is 1
              min_order = 1
  
      if agg_lag_dict is not None:
          orders_list = []
          if agg_lag_dict.get("orders_list") is not None:
              orders_list = orders_list + agg_lag_dict.get(
                  "orders_list"
              )
          if agg_lag_dict.get("interval_list") is not None:
              orders_list = orders_list + agg_lag_dict.get(
                  "interval_list"
              )
          flatten_orders = [
              order for sublist in orders_list for order in sublist
          ]
          max_order = np.nanmax(flatten_orders + [max_order])
          min_order = np.nanmin(flatten_orders + [min_order])
  
      return {"max_order": max_order, "min_order": min_order}
  
imports: import numpy
  import pandas
  from greykite.common import constants
label_desc: Use image node_id 2 for calling a global function with example usage: min_max_lag_order(lag_dict, agg_lag_dict) and returns: dict