
    dt                       U d Z ddlmZ ddlZddlZddlZddlmZ ddlZ	ddl
ZddlmZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZ 	 ddlZn# e$ r dZY nw xY wd
ZdZdZded<   	 ej        j        e fZ!n# e"$ r e fZ!Y nw xY wd Z#d Z$d Z%d1dZ& e&dd          Z' e&            Z( e&d          Z)e'e(e)gZ*d Z+d Z,d Z-d Z.d2dZ/d  Z0d! Z1d3d$Z2	 	 	 	 d4d%Z3d5d&Z4 G d' d(ej5                  Z6d) Z7d* Z8d+ Z9d, Z:d- Z;d. Z<d/ Z=d0 Z>dS )6z0DatetimeIndex analog for cftime.datetime objects    )annotationsN	timedelta)Version)_STANDARD_CALENDARScftime_to_nptimeinfer_calendar_name)_contains_cftime_datetimes)OPTIONS)	is_scalar   d   
   ztuple[type[Exception], ...]OUT_OF_BOUNDS_TIMEDELTA_ERRORSc                    d| z   dz   |z   dz   S )Nz(?P<>) )namepatterns     9lib/python3.11/site-packages/xarray/coding/cftimeindex.pynamedr   P   s    D=3(3..    c                    d| z   dz   S )Nz(?:z)?r   )xs    r   optionalr   T   s    19tr   c                d    | sdS | d         t          t          | dd                              z   S )N r      )r   trailing_optional)xss    r   r    r    X   s7     ra58-bf556666r   \-T\:c                    d| ddf| ddf|ddf|ddf|ddfg}g }|D ]0\  }}}|                     |r|ndt          ||          z              1d	t          |          z   d
z   S )N)Nyearz\d{4}monthz\d{2}dayhourminutesecondr   ^$)appendr   r    )date_sepdatetime_septime_seppiecespattern_listsepr   sub_patterns           r   build_patternr6   ^   s     	7H%	5(#	vx(	8X&	8X&F L"( M MT;C/SSR5{3K3KKLLLL"<000366r   r   )r/   r1    )r0   c                    t           D ]/}t          j        ||           }|r|                                c S 0t	          d|            )Nz4no ISO-8601 or cftime-string-like match for string: )	_PATTERNSrematch	groupdict
ValueError)datetime_stringr   r;   s      r   parse_iso8601_liker?   t   sb     % %/22 	%??$$$$$	%
PPP  r   c                    t           t          d           | ddd          }t          |          }i }dD ].}|                    |d           }|t	          |          ||<   |}/ |j        di ||fS )NNo module named 'cftime'r   )r&   r'   r(   r)   r*   r+   r   )cftimeModuleNotFoundErrorr?   getintreplace)	date_typetimestrdefaultresultrF   attrvalue
resolutions           r   _parse_iso8601_with_resorN   ~   s    ~!"<===i1a  G((FGD  

4&&  JJGDMJ7?%%W%%z11r   c                   |dk    r8 | |j         dd           | |j         dz   dd          t          d          z
  fS |dk    rv|j        dk    r' | |j         dz   dd          t          d          z
  }n+ | |j         |j        dz   d          t          d          z
  } | |j         |j        d          |fS |dk    r2 | |j         |j        |j                  }||t          dd          z   fS |d	k    r8 | |j         |j        |j        |j                  }||t          dd
          z   fS |dk    r> | |j         |j        |j        |j        |j                  }||t          dd          z   fS |dk    rD | |j         |j        |j        |j        |j        |j                  }||t          dd          z   fS t          )zGeneralization of
    pandas.tseries.index.DatetimeIndex._parsed_string_to_bounds
    for use with non-standard calendars and cftime.datetime
    objects.
    r&   r   microsecondsr'      r(   )daysrQ   r)   )hoursrQ   r*   )minutesrQ   r+   )secondsrQ   )r&   r   r'   r(   r)   r*   r+   KeyError)rG   rM   parsedendstarts        r   _parsed_string_to_boundsr\      s#    VIfk1a((IfkAoq!,,ya/H/H/HH
 	
 
w		<2)FK!OQ22YA5N5N5NNCC)FK)91==	A A A C yflA66;;	u			&+v|VZ@@eiQR@@@@@@	v			&+v|VZMMeiabAAAAAA	x			Kvz6;
 
 eiCCCCCC	x			KLJKMM
 
 eiCCCCCCr   c                D    t          j        fd| D                       S )z(Adapted from pandas.tslib.get_date_fieldc                0    g | ]}t          |          S r   )getattr).0datefields     r   
<listcomp>z"get_date_field.<locals>.<listcomp>   s#    @@@dWT5))@@@r   )nparray)	datetimesrb   s    `r   get_date_fieldrg      s(    8@@@@i@@@AAAr   0.0c                L     |f fd	} |_         ||_        t          |          S )z1Adapted from pandas.tseries.index._field_accessorc           	         t           t          d          t          t           j                  t          |          k    rt	          | j                  S t          ddd| dt           j         d          )NrA   zThe z!rz2 accessor requires a minimum version of cftime of z . Found an installed version of .)rB   rC   r   __version__rg   _dataImportError)selfmin_cftime_versionr   s     r   fz_field_accessor.<locals>.f   s    >%&@AAA6%&&'2D*E*EEE!$*d333>t= > >(:> >(.(:> > >  r   )__name____doc__property)r   	docstringrp   rq   s   `   r   _field_accessorrv      sB     $6       AJAIA;;r   c                R    | j         j        rt          | j         d                   S d S )Nr   )rm   sizetype)ro   s    r   get_date_typerz      s'    z DJqM"""tr   c                ~   t           t          d          t          |           dk    r| d         }t          |          t	          |t           j                  s"t          d                                        t          fd| D                       s$t          d                    |                     d S d S )NrA   r   z?CFTimeIndex requires cftime.datetime objects. Got object of {}.c              3  8   K   | ]}t          |          V  d S N)
isinstance)r`   rL   rG   s     r   	<genexpr>z-assert_all_valid_date_type.<locals>.<genexpr>   s-      BBE:eY//BBBBBBr   zJCFTimeIndex requires using datetime objects of all the same type.  Got
{}.)	rB   rC   lenry   r~   datetime	TypeErrorformatall)datasamplerG   s     @r   assert_all_valid_date_typer      s    ~!"<===
4yy1}}aLL	&&/22 	--3VI->->   BBBBTBBBBB 	::@&,,   }	 	r   , ,
c                d    |dz  |                     t          t          |                     z   |z   S )z&Format a single row from format_times.r7   )joinmapstr)timesindent	separatorrow_ends       r   
format_rowr      s*    C<)..S%999GCCr   c                F   t          |t          t          |          z   z  d          }t          j        t          |           |z            }d}	t          |          D ]B}
|
dk    r|n|}|
|dz
  k    r|n|}| |
|z  |
dz   |z           }|	t          ||||          z  }	C|	S )z)Format values of cftimeindex as pd.Index.r   r   r   )r   r   r   )maxCFTIME_REPR_LENGTHr   mathceilranger   )index	max_widthoffsetr   first_row_offsetintermediate_row_endlast_row_end	n_per_rown_rowsrepresentationrowr   r   times_for_rows                 r   format_timesr      s     I"4s9~~"EFJJIYs5zzI-..FNV}} 
 
%(AXX!!6"%!"3"3,,9McIoqI0EEF*&Iw
 
 
 	
 r   c                    d| j          dt          |            d| j         dt          |           dk    rd| j         dndd}d |                                D             }|                     |          }|S )z.Format attributes of CFTimeIndex for __repr__.'   N)dtypelengthcalendarfreqc                "    g | ]\  }}| d | S )=r   )r`   kvs      r   rc   z format_attrs.<locals>.<listcomp>  s&    6661A666r   )r   r   r   r   itemsr   )r   r   attrs	attrs_strs       r   format_attrsr     s     $U[###ZZ/))))%(ZZ1__!EJ!!!!$	 E 76666I##I..Ir   c                      e Zd ZdZ edd          Z edd          Z edd          Z edd	          Z ed
d          Z	 edd          Z
 edd          Z eddd          Z eddd          Z eddd          Z ee          Zd7dZd Zd Zd Zd Zd Z fdZd7d Zd! Zd" Zd# Zd8d(Zd) Zd* Zd+ Z d, Z!d9d.Z"d/ Z#ed0             Z$ed1             Z%ed2             Z&d3 Z'd4 Z(d5 Z)d6 Z* xZ+S ):CFTimeIndexaf  Custom Index for working with CF calendars and dates

    All elements of a CFTimeIndex must be cftime.datetime objects.

    Parameters
    ----------
    data : array or CFTimeIndex
        Sequence of cftime.datetime objects to use in index
    name : str, default: None
        Name of the resulting index

    See Also
    --------
    cftime_range
    r&   zThe year of the datetimer'   zThe month of the datetimer(   zThe days of the datetimer)   zThe hours of the datetimer*   zThe minutes of the datetimer+   zThe seconds of the datetimemicrosecondz The microseconds of the datetimedayofyrz'The ordinal day of year of the datetimez1.0.2.1dayofwkzThe day of week of the datetimedaysinmonthz/The number of days in the month of the datetimez1.1.0.0Nc                    t          |           |t          |d          r|j        }t                              |           }t          j        |d          |_        ||_        i |_        |S )Nr   Or   )	r   hasattrr   object__new__rd   re   rm   _cache)clsr   r   kwargsrJ   s        r   r   zCFTimeIndex.__new__=  sd    "4(((<GD&11<9D$$xC000r   c                   t          |           j        }t          d         }t          |          dz   }t          |           t          k    rt          | j        ||d          }njt          | j        dt                   ||dd          }t          | j        t           d         |||          }d                    |d	|z   d
|g          }t          |           }| d| d| d}t          |          |k    rHt          |          ||z
  k    r|
                    ddd	|dz
  z             }| d| dd	|dz
  z   | d}|S )zA
        Return a string representation for this object.
        display_width   r   )r   r   N,)r   r   r   
r7   z...z([z], r   r   z],
r   )ry   rr   r   r   ITEMS_IN_REPR_MAX_ELSE_ELLIPSISr   values"REPR_ELLIPSIS_SHOW_ITEMS_FRONT_ENDr   r   rF   )	ro   
klass_namer   r   datastr	front_strend_strr   full_repr_strs	            r   __repr__zCFTimeIndex.__repr__H  s    $ZZ(
0Z1$t99777"]6A  GG %???@!"   I #??@@A!'	  G iis6z,>,>,> HIIG &&	%AAAAYAAA}--9~~!777%--c3IfQh3I3IJJ	)VVWVV#vax.V)VVVMr   c                   t          | j        ||          \  }}| j        }| j        rt	          |          r7||d         k     r||d         k     s||d         k    r||d         k    rt
          |                    |d          }|                    |d          }t          ||          S ||k    }||k    }	t          j	        ||	z            S )a5  Adapted from
        pandas.tseries.index.DatetimeIndex._partial_date_slice

        Note that when using a CFTimeIndex, if a partial-date selection
        returns a single element, it will never be converted to a scalar
        coordinate; this is in slight contrast to the behavior when using
        a DatetimeIndex, which sometimes will return a DataArray with a scalar
        coordinate depending on the resolution of the datetimes used in
        defining the index.  For example:

        >>> from cftime import DatetimeNoLeap
        >>> da = xr.DataArray(
        ...     [1, 2],
        ...     coords=[[DatetimeNoLeap(2001, 1, 1), DatetimeNoLeap(2001, 2, 1)]],
        ...     dims=["time"],
        ... )
        >>> da.sel(time="2001-01-01")
        <xarray.DataArray (time: 1)>
        array([1])
        Coordinates:
          * time     (time) object 2001-01-01 00:00:00
        >>> da = xr.DataArray(
        ...     [1, 2],
        ...     coords=[[pd.Timestamp(2001, 1, 1), pd.Timestamp(2001, 2, 1)]],
        ...     dims=["time"],
        ... )
        >>> da.sel(time="2001-01-01")
        <xarray.DataArray ()>
        array(1)
        Coordinates:
            time     datetime64[ns] 2001-01-01
        >>> da = xr.DataArray(
        ...     [1, 2],
        ...     coords=[[pd.Timestamp(2001, 1, 1, 1), pd.Timestamp(2001, 2, 1)]],
        ...     dims=["time"],
        ... )
        >>> da.sel(time="2001-01-01")
        <xarray.DataArray (time: 1)>
        array([1])
        Coordinates:
          * time     (time) datetime64[ns] 2001-01-01T01:00:00
        r   rS   left)sideright)
r\   rG   rm   is_monotonic_increasingr   rX   searchsortedslicerd   flatnonzero)
ro   rM   rY   r[   rZ   r   r   r   lhs_maskrhs_masks
             r   _partial_date_slicezCFTimeIndex._partial_date_sliceo  s    V .dnj&QQ
s
' 	&5zz q!!cE!HnnE"I%%#b	//  %%e&%99D&&s&99Eu%%%E>C<~h1222r   c                    t          | j        |          \  }}	 |                     ||          }n# t          $ r t          |          w xY w|S )zAAdapted from pandas.tseries.index.DatetimeIndex._get_string_slice)rN   rG   r   rX   )ro   keyrY   rM   locs        r   _get_string_slicezCFTimeIndex._get_string_slice  s`    5dncJJ
	 **:v>>CC 	  	  	 3--	 
s	   1 Ac                   |                      |d|          }|                      |d|          }t          | j        |         |j        z
            }t          | j        |         |j        z
            }| j        r||k     |dk    z  }n||k    |dk    z  }t	          j        |||          }	||                     ||	|          }	|	S )z.Adapted from pandas.Index._get_nearest_indexerpad)limitbackfillrS   )get_indexerabsr   r   rd   where_filter_indexer_tolerance)
ro   targetr   	toleranceleft_indexerright_indexerleft_distancesright_distances	conditionindexers
             r   _get_nearest_indexerz CFTimeIndex._get_nearest_indexer  s    ''U'CC((5(IIT[6FGGdk-86=HII' 	T'/9mr>QRII'?:}PR?RSI(9lMBB 44VWiPPGr   c                    t          |t          j                  r#t          | j        |         |j        z
            }nt          | j        |         |z
            }t          j        ||k    |d          }|S )z3Adapted from pandas.Index._filter_indexer_tolerancerS   )r~   pdIndexr   r   rd   r   )ro   r   r   r   distances        r   r   z%CFTimeIndex._filter_indexer_tolerance  si    fbh'' 	:4;w/&-?@@HH4;w/&899H(8y0'2>>r   c                    t          |t                    r|                     |          S t                                          |          S )z7Adapted from pandas.tseries.index.DatetimeIndex.get_loc)r~   r   r   superget_loc)ro   r   	__class__s     r   r   zCFTimeIndex.get_loc  s?    c3 	())#...77??3'''r   c                    t          |t                    s|S t          | j        |          \  }}t	          | j        ||          \  }}| j        rt          |           dk    r
|dk    r|n|S |dk    r|n|S )aJ  Adapted from
        pandas.tseries.index.DatetimeIndex._maybe_cast_slice_bound

        Note that we have never used the kind argument in CFTimeIndex and it is
        deprecated as of pandas version 1.3.0.  It exists only for compatibility
        reasons.  We can remove it when our minimum version of pandas is 1.3.0.
        r   r   )r~   r   rN   rG   r\   is_monotonic_decreasingr   )ro   labelr   kindrY   rM   r[   rZ   s           r   _maybe_cast_slice_boundz#CFTimeIndex._maybe_cast_slice_bound  s     %%% 	L5dneLL
-dnj&QQ
s' 	4CIIMM&..33e3uuC/r   c                P   t          j        |          j        t          j        t                    k    r|j        |         S t          |t                    r1|j        |                     |j        |j	        |j
                           S |j        |                     |                   S )z9Adapted from pandas.tseries.index.DatetimeIndex.get_value)rd   asarrayr   boolilocr~   r   slice_indexerr[   stopstepr   )ro   seriesr   s      r   	get_valuezCFTimeIndex.get_value  s}    :c?? BHTNN22;s##U## 	2;t11#)SXsxPPQQ;t||C0011r   c                    	 |                      |          }t          |          p8t          |          t          k    p t	          |t
          j                  o|j        S # t          t          t          f$ r Y dS w xY w)zKAdapted from
        pandas.tseries.base.DatetimeIndexOpsMixin.__contains__F)r   r   ry   r   r~   rd   ndarrayrx   rX   r   r=   )ro   r   rJ   s      r   __contains__zCFTimeIndex.__contains__  s    	\\#&&F&!! D<<5(Dvrz22Bv{
 )Z0 	 	 	55	s   AA A:9A:c                ,    |                      |          S )z-Needed for .loc based partial-string indexing)r	  )ro   r   s     r   containszCFTimeIndex.contains  s      %%%r   nint | floatr   str | timedeltac                    t          |t                    r| ||z  z   S t          |t                    rddlm} | | ||          z  z   S t          d                    |                    )aE  Shift the CFTimeIndex a multiple of the given frequency.

        See the documentation for :py:func:`~xarray.cftime_range` for a
        complete listing of valid frequency strings.

        Parameters
        ----------
        n : int, float if freq of days or below
            Periods to shift by
        freq : str or datetime.timedelta
            A frequency string or datetime.timedelta object to shift by

        Returns
        -------
        CFTimeIndex

        See Also
        --------
        pandas.DatetimeIndex.shift

        Examples
        --------
        >>> index = xr.cftime_range("2000", periods=1, freq="M")
        >>> index
        CFTimeIndex([2000-01-31 00:00:00],
                    dtype='object', length=1, calendar='standard', freq=None)
        >>> index.shift(1, "M")
        CFTimeIndex([2000-02-29 00:00:00],
                    dtype='object', length=1, calendar='standard', freq=None)
        >>> index.shift(1.5, "D")
        CFTimeIndex([2000-02-01 12:00:00],
                    dtype='object', length=1, calendar='standard', freq=None)
        r   )	to_offsetz9'freq' must be of type str or datetime.timedelta, got {}.)r~   r   r   xarray.coding.cftime_offsetsr  r   r   )ro   r  r   r  s       r   shiftzCFTimeIndex.shift  s    D dI&& 
	!d(?"c"" 	>>>>>>!iioo---55;VD\\  r   c                    t          |t          j                  r|                                }t	          t          j        |           |z             S r}   r~   r   TimedeltaIndexto_pytimedeltar   rd   re   ro   others     r   __add__zCFTimeIndex.__add__4  sC    eR.// 	+((**E28D>>E1222r   c                    t          |t          j                  r|                                }t	          |t          j        |           z             S r}   r  r  s     r   __radd__zCFTimeIndex.__radd__9  sC    eR.// 	+((**E528D>>1222r   c                
   t          |          r$t          t          j        |           |z
            S t	          |t
          j                  r6t          t          j        |           |                                z
            S t          t          j        |                    rY	 t          j        t          j        |           t          j        |          z
            S # t          $ r t          d          w xY wt          S NzcThe time difference exceeds the range of values that can be expressed at the nanosecond resolution.)_contains_datetime_timedeltasr   rd   re   r~   r   r  r  r
   r   r=   NotImplementedr  s     r   __sub__zCFTimeIndex.__sub__>  s    (// 	"rx~~5666r011 	"rx~~0D0D0F0FFGGG'88 		"($"(5//)IJJJ1    J   "!s   &:C! !C;c                    	 t          j        |t          j        |           z
            S # t          $ r t          d          w xY wr  )r   r  rd   re   r   r=   r  s     r   __rsub__zCFTimeIndex.__rsub__N  sX    	$URXd^^%;<<<- 	 	 	F  	s	   (+ AFc                    t          |           }t          |           }|t          vr1|s/t          j        d                    |          t          d           t          j        |          S )a  If possible, convert this index to a pandas.DatetimeIndex.

        Parameters
        ----------
        unsafe : bool
            Flag to turn off warning when converting from a CFTimeIndex with
            a non-standard calendar to a DatetimeIndex (default ``False``).

        Returns
        -------
        pandas.DatetimeIndex

        Raises
        ------
        ValueError
            If the CFTimeIndex contains dates that are not possible in the
            standard calendar or outside the nanosecond-precision range.

        Warns
        -----
        RuntimeWarning
            If converting from a non-standard calendar to a DatetimeIndex.

        Warnings
        --------
        Note that for non-standard calendars, this will change the calendar
        type of the index.  In that case the result of this method should be
        used with caution.

        Examples
        --------
        >>> times = xr.cftime_range("2000", periods=2, calendar="gregorian")
        >>> times
        CFTimeIndex([2000-01-01 00:00:00, 2000-01-02 00:00:00],
                    dtype='object', length=2, calendar='standard', freq=None)
        >>> times.to_datetimeindex()
        DatetimeIndex(['2000-01-01', '2000-01-02'], dtype='datetime64[ns]', freq=None)
        zConverting a CFTimeIndex with dates from a non-standard calendar, {!r}, to a pandas.DatetimeIndex, which uses dates from the standard calendar.  This may lead to subtle errors in operations that depend on the length of time between dates.r   )
stacklevel)	r   r	   r   warningswarnr   RuntimeWarningr   DatetimeIndex)ro   unsafenptimesr   s       r   to_datetimeindexzCFTimeIndex.to_datetimeindexW  sv    N #4((&t,,...v.M  ))    (((r   c                N    t          j        fd| j        D                       S )a  
        Return an Index of formatted strings specified by date_format, which
        supports the same string format as the python standard library. Details
        of the string format can be found in `python string format doc
        <https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior>`__

        Parameters
        ----------
        date_format : str
            Date format string (e.g. "%Y-%m-%d")

        Returns
        -------
        pandas.Index
            Index of formatted strings

        Examples
        --------
        >>> rng = xr.cftime_range(
        ...     start="2000", periods=5, freq="2MS", calendar="noleap"
        ... )
        >>> rng.strftime("%B %d, %Y, %r")
        Index(['January 01, 2000, 12:00:00 AM', 'March 01, 2000, 12:00:00 AM',
               'May 01, 2000, 12:00:00 AM', 'July 01, 2000, 12:00:00 AM',
               'September 01, 2000, 12:00:00 AM'],
              dtype='object')
        c                :    g | ]}|                               S r   )strftime)r`   ra   date_formats     r   rc   z(CFTimeIndex.strftime.<locals>.<listcomp>  s%    KKK{33KKKr   )r   r   rm   )ro   r/  s    `r   r.  zCFTimeIndex.strftime  s,    8 xKKKK
KKKLLLr   c                    ddl m |                     ddd          t          j        fd| j        D             t          j                  S )z@Convert to integers with units of microseconds since 1970-01-01.r   ) exact_cftime_datetime_difference  r   c                B    g | ]}t           |                    S r   )_total_microseconds)r`   ra   epochr1  s     r   rc   z$CFTimeIndex.asi8.<locals>.<listcomp>  s?        $$D$DUD$Q$QRR  r   r   )xarray.core.resample_cftimer1  rG   rd   re   r   int64)ro   r5  r1  s    @@r   asi8zCFTimeIndex.asi8  s{     	QPPPPPtQ**x     K   (
 
 
 	
r   c                $    ddl m}  ||           S )z0The calendar used by the datetimes in the index.r   )r	   )xarray.coding.timesr	   )ro   r	   s     r   r   zCFTimeIndex.calendar  s'     	<;;;;;""4(((r   c                $    ddl m}  ||           S )z-The frequency used by the dates in the index.r   )
infer_freq)xarray.coding.frequenciesr<  )ro   r<  s     r   r   zCFTimeIndex.freq  s&     	988888z$r   c                
   ddl m}m}  ||          }t          ||          st	          | d          t          |                                          }| j        } |||          }t          || j	        | j
                  S )z%Round dates using a specified method.r   )CFTIME_TICKSr  z is a non-fixed frequency)r  r?  r  r~   r=   r4  as_timedeltar8  _cftimeindex_from_i8rG   r   )	ro   r   methodr?  r  r   unitr   roundeds	            r   _round_via_methodzCFTimeIndex._round_via_method  s    HHHHHHHH4&,// 	CAAABBB"6#6#6#8#899&&&#GT^TYGGGr   c                8    |                      |t                    S )a  Round dates down to fixed frequency.

        Parameters
        ----------
        freq : str
            The frequency level to round the index to.  Must be a fixed
            frequency like 'S' (second) not 'ME' (month end).  See `frequency
            aliases <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`_
            for a list of possible values.

        Returns
        -------
        CFTimeIndex
        )rE  
_floor_intro   r   s     r   floorzCFTimeIndex.floor  s     %%dJ777r   c                8    |                      |t                    S )a  Round dates up to fixed frequency.

        Parameters
        ----------
        freq : str
            The frequency level to round the index to.  Must be a fixed
            frequency like 'S' (second) not 'ME' (month end).  See `frequency
            aliases <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`_
            for a list of possible values.

        Returns
        -------
        CFTimeIndex
        )rE  	_ceil_intrH  s     r   r   zCFTimeIndex.ceil  s     %%dI666r   c                8    |                      |t                    S )a  Round dates to a fixed frequency.

        Parameters
        ----------
        freq : str
            The frequency level to round the index to.  Must be a fixed
            frequency like 'S' (second) not 'ME' (month end).  See `frequency
            aliases <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`_
            for a list of possible values.

        Returns
        -------
        CFTimeIndex
        )rE  _round_to_nearest_half_evenrH  s     r   roundzCFTimeIndex.round  s     %%d,GHHHr   r}   )r  r  r   r  )F),rr   
__module____qualname__rs   rv   r&   r'   r(   r)   r*   r+   r   	dayofyear	dayofweekdays_in_monthrt   rz   rG   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r   r"  r+  r.  r8  r   r   rE  rI  r   rN  __classcell__)r   s   @r   r   r     s          ?6#=>>DOG%@AAE
/%!;
<
<C?6#>??D_X'DEEF_X'DEEF!/-1STTK<i I  	+LiXXI#OH) M ''I	 	 	 	% % %N>3 >3 >3@    "  ( ( ( ( (0 0 0 0&2 2 2  & & &, , , ,\3 3 3
3 3 3
" " "   3) 3) 3) 3)jM M M< 
 
 X
 ) ) X)     X H H H8 8 8"7 7 7"I I I I I I Ir   r   c                ,    t          | |          \  }}|S r}   )rN   )rG   datetime_strra   _s       r   _parse_iso8601_without_resorX    s    &y,??GD!Kr   c                    t          j        fd|                                 D                                           | j                  S )a  Create a numpy array from an array of strings.

    For use in generating dates from strings for use with interp.  Assumes the
    array is either 0-dimensional or 1-dimensional.

    Parameters
    ----------
    strings : array of strings
        Strings to convert to dates
    date_type : cftime.datetime type
        Calendar type to use for dates

    Returns
    -------
    np.array
    c                0    g | ]}t          |          S r   )rX  )r`   srG   s     r   rc   z2_parse_array_of_cftime_strings.<locals>.<listcomp>  s$    LLLq	$Y	2	2LLLr   )rd   re   ravelreshapeshape)stringsrG   s    `r   _parse_array_of_cftime_stringsr`    sG    " 8LLLLGMMOOLLL ggmr   c                `    t          j        |           } t          | d         t                    S )z<Check if an input array contains datetime.timedelta objects.r   )rd   
atleast_1dr~   r   )re   s    r   r  r  "  s%    M%  EeAh	***r   c                     |ddd          t          j        fd| D                       }t          ||          S )a@  Construct a CFTimeIndex from an array of integers.

    Parameters
    ----------
    values : np.array
        Integers representing microseconds since 1970-01-01.
    date_type : cftime.datetime
        Type of date for the index.
    name : str
        Name of the index.

    Returns
    -------
    CFTimeIndex
    r2  r   c                P    g | ]"}t          t          |                     z   #S )rP   )r   rE   )r`   rL   r5  s     r   rc   z(_cftimeindex_from_i8.<locals>.<listcomp>9  s/    UUUUeiSZZ@@@@UUUr   )r   )rd   re   r   )r   rG   r   datesr5  s       @r   rA  rA  (  sO      IdAq!!EHUUUUfUUUVVEu4((((r   c                (    | t          d          z  S )zCompute the total number of microseconds of a datetime.timedelta.

    Parameters
    ----------
    delta : datetime.timedelta
        Input timedelta.

    Returns
    -------
    int
    r   rP   r   )deltas    r   r4  r4  =  s     9!,,,,,r   c                2    | t          j        | |          z
  S Copied from pandas.rd   	remainderr   rC  s     r   rG  rG  L  s    BL....r   c                4    | t          j        |  |          z   S ri  rk  rm  s     r   rK  rK  Q  s    BL&$////r   c                   |dz  rt          | |dz  z
  |          S t          j        | |          \  }}t          j        ||dz  k    t          j        ||dz  k    |dz                      }||xx         dz  cc<   ||z  S )rj  r   r   )rK  rd   divmod
logical_orlogical_and)r   rC  quotientrl  masks        r   rM  rM  V  s    ax 3$!)+T222)FD11Hi=TQY	dai0H(UV,!W!W D TNNNaNNNd?r   )r"   r#   r$   )Nrh   )r   r   r   )r   r   r   r   )r   )?rs   
__future__r   r   r:   r%  r   r   numpyrd   pandasr   packaging.versionr   r:  r   r   r	   xarray.core.commonr
   xarray.core.optionsr   xarray.core.utilsr   rB   rn   r   r   r   __annotations__errorsOutOfBoundsTimedeltaOverflowErrorr   AttributeErrorr   r   r    r6   _BASIC_PATTERN_EXTENDED_PATTERN_CFTIME_PATTERNr9   r?   rN   r\   rg   rv   rz   r   r   r   r   r   r   rX  r`  r  rA  r4  rG  rK  rM  r   r   r   <module>r     s}   6 6 6P # " " " " "  				                % % % % % %         
 : 9 9 9 9 9 ' ' ' ' ' ' ' ' ' ' ' 'MMMM   FFF
  "% %' " < ; ; ;6&(i&Dm%T"" 6 6 6&3%5"""6/ / /  7 7 77 7 7 7  R888!MOO -S111.@	  2 2 2$) ) )XB B B
   *    &D D D D    2   hI hI hI hI hI"( hI hI hIV  
  ,+ + +) ) )*- - -/ / /
0 0 0
	 	 	 	 	s$   A AA%A4 4A?>A?