import pandas as pd
import pandas.api.types as pd_types


def is_datetime_index(index: pd.Index) -> bool:
    """
    Check if the given index is a DatetimeIndex.

    Parameters
    ----------
    index : pd.Index
        The index to check.

    Returns
    -------
    bool
        True if the index is a DatetimeIndex, False otherwise.
    """
    return pd_types.is_datetime64_any_dtype(index)


def raise_if_not_datetime_index(index: pd.Index) -> None:
    """
    Raise a ValueError if the given index is not a DatetimeIndex.

    Parameters
    ----------
    index : pd.Index
        The index to check.

    Raises
    ------
    ValueError
        If the index is not a DatetimeIndex.
    """
    if not is_datetime_index(index):
        raise ValueError("Index must be a DatetimeIndex")
