def timestamp_as_unit(date: pd.Timestamp, unit: PDDatetimeUnitOptions) -> pd.Timestamp:
    """Convert the underlying int64 representation to the given unit.

    Compatibility function for pandas issue where "as_unit" is not defined
    for pandas.Timestamp in pandas versions < 2.2. Can be removed minimum
    pandas version is >= 2.2.
    """
    if hasattr(date, "as_unit"):
        date = date.as_unit(unit)
    elif hasattr(date, "_as_unit"):
        date = date._as_unit(unit)
    return date
Convert the underlying int64 representation to the given unit.

    Compatibility function for pandas issue where "as_unit" is not defined
    for pandas.Timestamp in pandas versions < 2.2. Can be removed minimum
    pandas version is >= 2.2.
    
xarray/compat/pdcompat.py