code: def date_to_index(
      date: str | dt.date | dt.datetime | np.datetime64 | Timestamp,
      date_index: DatetimeIndex | NDArray | Series[Timestamp],
  ) -> int:
      """
      Looks up a date in an array of dates
  
      Parameters
      ----------
      date : {str, datetime, datetime64, Timestamp}
          Date to use when returning the index
      date_index : {DatetimeIndex, ndarray}
          Index data containing datetime64 values
  
      Returns
      -------
      int
          Index location
  
      Notes
      -----
      Assumes dates are increasing and unique.
      """
      if not is_datetime64_any_dtype(date_index):
          raise ValueError("date_index must be a datetime64 array")
      values = (
          date_index.values
          if isinstance(date_index, DatetimeIndex)
          else np.asarray(date_index)
      )
      if not np.all((np.diff(values).astype(dtype=np.int64)) > 0):
          raise ValueError("date_index is not monotonic and unique")
      if not isinstance(
          date, (dt.datetime, np.datetime64, str, Timestamp)
      ):
          raise ValueError(
              "date must be a datetime, datetime64, Timestamp or string"
          )
  
      if isinstance(date, Timestamp):
          assert isinstance(date_index, DatetimeIndex)
          if date_index.tzinfo is not None:
              date = date.tz_convert("GMT").tz_localize(None)
          date_64 = date.to_datetime64()
      elif isinstance(date, dt.datetime):
          date_64 = np.datetime64(date)
      elif isinstance(date, str):
          pd_dt = to_datetime(date, errors="coerce")
          if pd_dt is NaT:
              raise ValueError(
                  f"date: {date} cannot be parsed to a date."
              )
          assert isinstance(pd_dt, Timestamp)
          date_64 = pd_dt.to_datetime64()
      else:
          assert isinstance(date, np.datetime64)
          date_64 = date
  
      if isinstance(date_index, DatetimeIndex):
          if date_index.tzinfo is not None:
              date_index = date_index.tz_convert("GMT").tz_localize(
                  None
              )
          date_index = date_index.to_numpy()
  
      date_index = np.asarray(date_index)
  
      locs = np.nonzero(date_index <= date_64)[0]
      if locs.shape[0] == 0:
          return 0
  
      loc = locs.max()
      in_array = np.any(date_index == date_64)
      if not in_array:
          loc += 1
  
      return int(loc)
  
imports: from __future__ import annotations
  from arch.compat.pandas import is_datetime64_any_dtype
  from abc import ABCMeta
  from collections.abc import Hashable, Sequence
  import datetime
  from functools import cached_property
  from typing import Any, Literal, overload
  import numpy
  from pandas import DataFrame, DatetimeIndex, Index, NaT, Series, Timestamp, to_datetime
  from arch.typing import AnyPandas, ArrayLike, DateLike, NDArray
label_desc: Use image node_id 6 for calling a global function with example usage: date_to_index(date, date_index) and returns: int, int