a
    İa                  D   @   sV  d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	Z
ddlmZ dd	lmZmZ dd
lmZ zddlZW n ey   dZY n0 dd ZG dd dZdd Zdd Zdd Zdd ZdgddZdhddZdd ZG dd  d eZG d!d" d"eZd#d$d%d&d'd(d)d*d+d,d-d.d/ZG d0d1 d1eZ G d2d3 d3e Z!G d4d5 d5e Z"G d6d7 d7eZ#G d8d9 d9e#Z$G d:d; d;e#Z%G d<d= d=eZ&G d>d? d?eZ'G d@dA dAeZ(G dBdC dCeZ)G dDdE dEeZ*G dFdG dGeZ+e%e$e%e$ee"dHdIee!ddIeee&e'e(e(e)e*e*e+e+ee$ddIee$ddIee$ddIee$dJdIee$dKdIee$dLdIee$dMdIee$dNdIee$dOdIee$dPdIee$dQdIee$dHdIee%ddIee%ddIee%ddIee%dJdIee%dKdIee%dLdIee%dMdIee%dNdIee%dOdIee%dPdIee%dQdIee%dHdIee!ddIee!ddIee!ddIee!dJdIee!dKdIee!dLdIee!dMdIee!dNdIee!dOdIee!dPdIee!dQdIee!dHdIee"ddIee"ddIee"ddIee"dJdIee"dKdIee"dLdIee"dMdIee"dNdIee"dOdIee"dPdIee"dQdIee"dHdIdRAZ,dS-e,. Z/dTe/ dUZ0e&e'e(e)fZ1dVdW Z2didXdYZ3dZd[ Z4d\d] Z5d^d_ Z6d`da Z7djdedfZ8dS )kz8Time offset classes for use with cftime.datetime objects    N)	timedelta)partial)ClassVarOptional   )count_not_none   )CFTimeIndex_parse_iso8601_with_reso)format_cftime_datetimec              
   C   sH   t du rtdn2t jt jt jt jt jt jt jt jt jd	}||  S dS )z6Return the cftime date type for a given calendar name.Nz8cftime is required for dates with non-standard calendars)	ZnoleapZ360_dayZ365_dayZ366_dayZ	gregorianZproleptic_gregorianZjulianZall_leapstandard)cftimeImportErrorZDatetimeNoLeapZDatetime360DayZDatetimeAllLeapZDatetimeGregorianZDatetimeProlepticGregorianZDatetimeJulian)calendarZ	calendars r   ;lib/python3.9/site-packages/xarray/coding/cftime_offsets.pyget_date_type<   s    
r   c                   @   s   e Zd ZU dZeee  ed< dZeee  ed< d)ddZ	dd Z
d	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( ZdS )*BaseCFTimeOffsetN_freq_day_optionr   c                 C   s&   t |tstdt||| _d S )NzXThe provided multiple 'n' must be an integer. Instead a value of type {!r} was provided.)
isinstanceint	TypeErrorformattypen)selfr   r   r   r   __init__S   s    
zBaseCFTimeOffset.__init__c                 C   s   | j S N)r   r   r   r   r   	rule_code[   s    zBaseCFTimeOffset.rule_codec                 C   s   | j |j ko|  | kS r   )r   r    r   otherr   r   r   __eq__^   s    zBaseCFTimeOffset.__eq__c                 C   s
   | |k S r   r   r!   r   r   r   __ne__a   s    zBaseCFTimeOffset.__ne__c                 C   s
   |  |S r   )	__apply__r!   r   r   r   __add__d   s    zBaseCFTimeOffset.__add__c                 C   sR   t d u rtdt|t jr&tdn(t|t| krJt| | j|j S tS d S )NNo module named 'cftime'z5Cannot subtract a cftime.datetime from a time offset.)r   ModuleNotFoundErrorr   datetimer   r   r   NotImplementedr!   r   r   r   __sub__g   s    
zBaseCFTimeOffset.__sub__c                 C   s   t | || j dS )Nr   )r   r   r!   r   r   r   __mul__r   s    zBaseCFTimeOffset.__mul__c                 C   s   | d S )Nr   r   r   r   r   __neg__u   s    zBaseCFTimeOffset.__neg__c                 C   s
   |  |S r   )r-   r!   r   r   r   __rmul__x   s    zBaseCFTimeOffset.__rmul__c                 C   s
   |  |S r   )r&   r!   r   r   r   __radd__{   s    zBaseCFTimeOffset.__radd__c                 C   s,   t |tr"t| t|kr"td|  | S )Nz1Cannot subtract cftime offsets of differing types)r   r   r   r   r!   r   r   r   __rsub__~   s    zBaseCFTimeOffset.__rsub__c                 C   s   t S r   )r*   r   r   r   r   r%      s    zBaseCFTimeOffset.__apply__c                 C   s   | | |  }||kS xCheck if the given date is in the set of possible dates created
        using a length-one version of this offset class.r   )r   dateZ	test_dater   r   r   onOffset   s    zBaseCFTimeOffset.onOffsetc                 C   s    |  |r|S |t|   S d S r   r6   r   r   r5   r   r   r   rollforward   s    
zBaseCFTimeOffset.rollforwardc                 C   s    |  |r|S |t|   S d S r   r7   r8   r   r   r   rollback   s    
zBaseCFTimeOffset.rollbackc                 C   s   d t| j| jS )Nz
<{}: n={}>)r   r   __name__r   r   r   r   r   __str__   s    zBaseCFTimeOffset.__str__c                 C   s   t | S r   )strr   r   r   r   __repr__   s    zBaseCFTimeOffset.__repr__c                 C   s   t || jS r   )_get_day_of_monthr   r!   r   r   r   _get_offset_day   s    z BaseCFTimeOffset._get_offset_day)r   )r;   
__module____qualname__r   r   r   r=   __annotations__r   r   r    r#   r$   r&   r+   r-   r/   r0   r1   r2   r%   r6   r9   r:   r<   r>   r@   r   r   r   r   r   O   s(   

r   c                 C   s8   |dkrdS |dkrt | S |du r,t nt|dS )a\  Find the day in `other`'s month that satisfies a BaseCFTimeOffset's
    onOffset policy, as described by the `day_option` argument.

    Parameters
    ----------
    other : cftime.datetime
    day_option : 'start', 'end'
        'start': returns 1
        'end': returns last day of the month

    Returns
    -------
    day_of_month : int

    startr   endN)_days_in_monthNotImplementedError
ValueError)r"   
day_optionr   r   r   r?      s    r?   c                 C   sJ   | j dkr"t| | jd dd}nt| | j| j d d}|tdd jS )z1The number of days in the month of the given date   r   Zdays)monthr   yearr   day)r5   	referencer   r   r   rF      s    
rF   c                 C   s6   |dkr| |k r|d }n|dkr2| |kr2|d }|S )zAdjust the number of times a monthly offset is applied based
    on the day of a given date, and the reference day provided.
    r   r   r   )Z	other_dayr   reference_dayr   r   r   _adjust_n_months   s
    
rQ   c                 C   sZ   |dkr0| j |k s&| j |krV| j|k rV|d8 }n&| j |ksN| j |krV| j|krV|d7 }|S )zpAdjust the number of times an annual offset is applied based on
    another date, and the reference day providedr   r   )rL   rN   )r"   r   rL   rP   r   r   r   _adjust_n_years   s    
rR   rD   c                 C   s   t du rtd| j| d }| j| d }|dkr@d}|d }| j| }|dkrXd}n*|dkrzt| ||d}t|}nt|| j|||dS )	zEShift the date to a month start or end a given number of months away.Nr'   rJ   r   r   rD   rE   )rM   rL   rN   )r   r(   rL   rM   r   rF   rH   replace)r5   monthsrI   Z
delta_yearrL   rM   rN   rO   r   r   r   _shift_month   s    

rU      c                 C   sp   | j | ||  }|dkrD|dk s:|dkrl| jt| |k rl|d8 }n(|dksd|dkrl| jt| |krl|d7 }|S )a  Possibly increment or decrement the number of periods to shift
    based on rollforward/rollbackward conventions.

    Parameters
    ----------
    other : cftime.datetime
    n : number of periods to increment, before adjusting for rolling
    month : int reference month giving the first month of the year
    day_option : 'start', 'end'
        The convention to use in finding the day in a given month against
        which to compare for rollforward/rollbackward decisions.
    modby : int 3 for quarters, 12 for years

    Returns
    -------
    n : int number of periods to increment

    See Also
    --------
    _get_day_of_month : Find the day in a month provided an offset.
    r   r   )rL   rN   r?   )r"   r   rL   rI   modbymonths_sincer   r   r   roll_qtrday   s    
rY   c                 C   sR   | d u r|n| }t |ts*td|n$d|  kr>dksNn td||S )Nz_'self.month' must be an integer value between 1 and 12.  Instead, it was set to a value of {!r}r   rJ   )r   r   r   r   rH   )rL   Zdefault_monthZresult_monthr   r   r   _validate_month!  s    
rZ   c                   @   s    e Zd ZdZdd Zdd ZdS )
MonthBeginMSc                 C   s   t |j| jd}t||dS )Nr   rD   )rQ   rN   r   rU   r   r"   r   r   r   r   r%   5  s    zMonthBegin.__apply__c                 C   s
   |j dkS r4   r   )rN   r8   r   r   r   r6   9  s    zMonthBegin.onOffsetNr;   rA   rB   r   r%   r6   r   r   r   r   r[   2  s   r[   c                   @   s    e Zd ZdZdd Zdd ZdS )MonthEndMc                 C   s    t |j| jt|}t||dS )NrE   )rQ   rN   r   rF   rU   r]   r   r   r   r%   B  s    zMonthEnd.__apply__c                 C   s   |j t|kS r3   )rN   rF   r8   r   r   r   r6   F  s    zMonthEnd.onOffsetNr_   r   r   r   r   r`   ?  s   r`   ZJANZFEBZMARZAPRZMAYZJUNZJULZAUGZSEPZOCTZNOVZDEC)r   r   rV                  	   
      rJ   c                   @   sd   e Zd ZU dZee ed< ee ed< dddZdd	 Z	d
d Z
dd Zdd Zdd Zdd ZdS )QuarterOffsetz>Quarter representation copied off of pandas/tseries/offsets.pyr   _default_monthr   Nc                 C   s   t | | t|| j| _d S r   r   r   rZ   rk   rL   r   r   rL   r   r   r   r   b  s    zQuarterOffset.__init__c                 C   sF   |j d | j d  }t|| j| j | jdd}|d | }t||| jS )NrV   )rI   rW   )rL   rY   r   r   rU   )r   r"   rX   ZqtrsrT   r   r   r   r%   f  s    zQuarterOffset.__apply__c                 C   s(   |j | j  d }|dko&|j| |kS )r4   rV   r   )rL   rN   r@   )r   r5   Z	mod_monthr   r   r   r6   s  s    zQuarterOffset.onOffsetc                 C   sd   t d u rtdt|t jr&tdn:t|t| kr\|j| jkr\t| | j|j | jdS tS d S Nr'   z,Cannot subtract cftime.datetime from offset.rL   	r   r(   r   r)   r   r   rL   r   r*   r!   r   r   r   r+   y  s    
zQuarterOffset.__sub__c                 C   s   t | || j | jdS N)r   rL   r   r   rL   r!   r   r   r   r-     s    zQuarterOffset.__mul__c                 C   s   d | jt| j S Nz{}-{}r   r   _MONTH_ABBREVIATIONSrL   r   r   r   r   r      s    zQuarterOffset.rule_codec                 C   s   d t| j| j| jS Nz<{}: n={}, month={}>r   r   r;   r   rL   r   r   r   r   r<     s    zQuarterOffset.__str__)r   N)r;   rA   rB   __doc__r   r=   rC   r   r   r%   r6   r+   r-   r    r<   r   r   r   r   rj   \  s   

rj   c                   @   s(   e Zd ZdZdZdZdd Zdd ZdS )	QuarterBeginrV   QSrD   c                 C   s"   |  |r|S |t| jd S dS )z-Roll date forward to nearest start of quarterro   Nr6   ry   rL   r8   r   r   r   r9     s    
zQuarterBegin.rollforwardc                 C   s"   |  |r|S |t| jd S dS )z.Roll date backward to nearest start of quarterro   Nr{   r8   r   r   r   r:     s    
zQuarterBegin.rollbackNr;   rA   rB   rk   r   r   r9   r:   r   r   r   r   ry     s
   ry   c                   @   s(   e Zd ZdZdZdZdd Zdd ZdS )	
QuarterEndrV   QrE   c                 C   s"   |  |r|S |t| jd S dS )z+Roll date forward to nearest end of quarterro   Nr6   r}   rL   r8   r   r   r   r9     s    
zQuarterEnd.rollforwardc                 C   s"   |  |r|S |t| jd S dS )z,Roll date backward to nearest end of quarterro   Nr   r8   r   r   r   r:     s    
zQuarterEnd.rollbackNr|   r   r   r   r   r}     s
   r}   c                   @   sd   e Zd ZU ee ed< ee ed< ee ed< dddZdd	 Zd
d Z	dd Z
dd Zdd ZdS )
YearOffsetr   r   rk   r   Nc                 C   s   t | | t|| j| _d S r   rl   rm   r   r   r   r     s    zYearOffset.__init__c                 C   s@   t || j}t|| j| j|}|d | j|j  }t||| jS )NrJ   )r?   r   rR   r   rL   rU   )r   r"   rP   ZyearsrT   r   r   r   r%     s    zYearOffset.__apply__c                 C   sd   t d u rtdt|t jr&tdn:t|t| kr\|j| jkr\t| | j|j | jdS tS d S rn   rp   r!   r   r   r   r+     s    
zYearOffset.__sub__c                 C   s   t | || j | jdS rq   rr   r!   r   r   r   r-     s    zYearOffset.__mul__c                 C   s   d | jt| j S rs   rt   r   r   r   r   r      s    zYearOffset.rule_codec                 C   s   d t| j| j| jS rv   rw   r   r   r   r   r<     s    zYearOffset.__str__)r   N)r;   rA   rB   r   r=   rC   r   r   r%   r+   r-   r    r<   r   r   r   r   r     s   

r   c                   @   s0   e Zd ZdZdZdZdd Zdd Zdd	 Zd
S )	YearBeginASrD   r   c                 C   s   |j dko|j| jkS r^   )rN   rL   r8   r   r   r   r6     s    zYearBegin.onOffsetc                 C   s"   |  |r|S |t| jd S dS )z*Roll date forward to nearest start of yearro   Nr6   r   rL   r8   r   r   r   r9     s    
zYearBegin.rollforwardc                 C   s"   |  |r|S |t| jd S dS )z+Roll date backward to nearest start of yearro   Nr   r8   r   r   r   r:     s    
zYearBegin.rollbackN	r;   rA   rB   r   r   rk   r6   r9   r:   r   r   r   r   r     s   r   c                   @   s0   e Zd ZdZdZdZdd Zdd Zdd	 Zd
S )YearEndArE   rJ   c                 C   s   |j t|ko|j| jkS r3   )rN   rF   rL   r8   r   r   r   r6     s    zYearEnd.onOffsetc                 C   s"   |  |r|S |t| jd S dS )z(Roll date forward to nearest end of yearro   Nr6   r   rL   r8   r   r   r   r9     s    
zYearEnd.rollforwardc                 C   s"   |  |r|S |t| jd S dS )z)Roll date backward to nearest end of yearro   Nr   r8   r   r   r   r:     s    
zYearEnd.rollbackNr   r   r   r   r   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )DayDc                 C   s   t | jdS )NrK   r   r   r   r   r   r   as_timedelta  s    zDay.as_timedeltac                 C   s   ||    S r   r   r!   r   r   r   r%     s    zDay.__apply__Nr;   rA   rB   r   r   r%   r   r   r   r   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )HourHc                 C   s   t | jdS )N)Zhoursr   r   r   r   r   r   #  s    zHour.as_timedeltac                 C   s   ||    S r   r   r!   r   r   r   r%   &  s    zHour.__apply__Nr   r   r   r   r   r      s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )MinuteTc                 C   s   t | jdS )N)Zminutesr   r   r   r   r   r   -  s    zMinute.as_timedeltac                 C   s   ||    S r   r   r!   r   r   r   r%   0  s    zMinute.__apply__Nr   r   r   r   r   r   *  s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )SecondSc                 C   s   t | jdS )N)Zsecondsr   r   r   r   r   r   7  s    zSecond.as_timedeltac                 C   s   ||    S r   r   r!   r   r   r   r%   :  s    zSecond.__apply__Nr   r   r   r   r   r   4  s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )MillisecondLc                 C   s   t | jdS )N)Zmillisecondsr   r   r   r   r   r   A  s    zMillisecond.as_timedeltac                 C   s   ||    S r   r   r!   r   r   r   r%   D  s    zMillisecond.__apply__Nr   r   r   r   r   r   >  s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )MicrosecondUc                 C   s   t | jdS )N)Zmicrosecondsr   r   r   r   r   r   K  s    zMicrosecond.as_timedeltac                 C   s   ||    S r   r   r!   r   r   r   r%   N  s    zMicrosecond.__apply__Nr   r   r   r   r   r   H  s   r   rJ   ro   rb   rc   rd   re   rf   rg   rh   ri   )Ar   r   YZYSr~   rz   ra   r\   r   r   r   minr   r   msr   uszAS-JANzAS-FEBzAS-MARzAS-APRzAS-MAYzAS-JUNzAS-JULzAS-AUGzAS-SEPzAS-OCTzAS-NOVzAS-DECzA-JANzA-FEBzA-MARzA-APRzA-MAYzA-JUNzA-JULzA-AUGzA-SEPzA-OCTzA-NOVzA-DECzQS-JANzQS-FEBzQS-MARzQS-APRzQS-MAYzQS-JUNzQS-JULzQS-AUGzQS-SEPzQS-OCTzQS-NOVzQS-DECzQ-JANzQ-FEBzQ-MARzQ-APRzQ-MAYzQ-JUNzQ-JULzQ-AUGzQ-SEPzQ-OCTzQ-NOVzQ-DEC|z!^((?P<multiple>\d+)|())(?P<freq>(z))$c                 C   sp   t | tr| S ztt|  }W n ty<   tdY n0 |d } |d }|du rZdnt|}t	|  |dS )zOConvert a frequency string to the appropriate subclass of
    BaseCFTimeOffset.z!Invalid frequency string providedfreqZmultipleNr   r,   )
r   r   rematch_PATTERN	groupdictAttributeErrorrH   r   _FREQUENCIES)r   Z	freq_dataZ	multiplesr   r   r   	to_offset  s    
r   c                 C   sb   t d u rtdt| tr@|d u r*tdtt|| \}}|S t| t jrP| S td	| d S )Nr'   zTIf converting a string to a cftime.datetime object, a calendar type must be providedzUdate_str_or_date must be a string or a subclass of cftime.datetime. Instead got {!r}.)
r   r(   r   r=   rH   r
   r   r)   r   r   )Zdate_str_or_dater   r5   _r   r   r   to_cftime_datetime  s     
r   c                 C   s   | j dddddS )z Round datetime down to midnight.r   )ZhourZminutesecondZmicrosecond)rS   )r5   r   r   r   normalize_date  s    r   c                 C   s   |rt | S | S dS )z5Round datetime down to midnight if normalize is True.N)r   )r5   	normalizer   r   r   _maybe_normalize_date  s    r   c                 C   sT   t du rtd||   }tjd||dd}dt| }| j}t j|||ddS )zGenerate an equally-spaced sequence of cftime.datetime objects between
    and including two dates (whose length equals the number of periods).Nr'   g        T)Zendpointzseconds since {})unitsr   Zonly_use_cftime_datetimes)	r   r(   total_secondsnpZlinspacer   r   r   Znum2date)rD   rE   periodsr   valuesr   r   r   r   r   _generate_linear_range  s    r   c                 c   s   | r| | } |r||}|du r4|| k r4d}d}|du rL| |d |  }| du rd||d |  } | }|jdkr||kr|V  || }||krtd| d|}qrn4||kr|V  || }||krtd| d|}qdS )a   Generate a regular range of cftime.datetime objects with a
    given time offset.

    Adapted from pandas.tseries.offsets.generate_range.

    Parameters
    ----------
    start : cftime.datetime, or None
        Start of range
    end : cftime.datetime, or None
        End of range
    periods : int, or None
        Number of elements in the sequence
    offset : BaseCFTimeOffset
        An offset class designed for working with cftime.datetime objects

    Returns
    -------
    A generator object
    Nr   r   zOffset z did not increment datez did not decrement date)r9   r:   r   rH   )rD   rE   r   offsetcurrentZ	next_dater   r   r   _generate_range  s2    


r   r   Fr   c                 C   s2  t | |||dkrtd| dur6t| |} t| |} |durRt||}t||}|du rht| ||}n t|}	ttt	| |||	}d}
d}|du rd}
d}n$|dkrd}
n|dkrd}ntd|
st
|r| dur|d	 | kr|d
d }|s&t
|r&|dur&|d |kr&|dd }t||dS )a%  Return a fixed frequency CFTimeIndex.

    Parameters
    ----------
    start : str or cftime.datetime, optional
        Left bound for generating dates.
    end : str or cftime.datetime, optional
        Right bound for generating dates.
    periods : int, optional
        Number of periods to generate.
    freq : str or None, default: "D"
        Frequency strings can have multiples, e.g. "5H".
    normalize : bool, default: False
        Normalize start/end dates to midnight before generating date range.
    name : str, default: None
        Name of the resulting index
    closed : {"left", "right"} or None, default: None
        Make the interval closed with respect to the given frequency to the
        "left", "right", or both sides (None).
    calendar : str, default: "standard"
        Calendar type for the datetimes.

    Returns
    -------
    CFTimeIndex

    Notes
    -----
    This function is an analog of ``pandas.date_range`` for use in generating
    sequences of ``cftime.datetime`` objects.  It supports most of the
    features of ``pandas.date_range`` (e.g. specifying how the index is
    ``closed`` on either side, or whether or not to ``normalize`` the start and
    end bounds); however, there are some notable exceptions:

    - You cannot specify a ``tz`` (time zone) argument.
    - Start or end dates specified as partial-datetime strings must use the
      `ISO-8601 format <https://en.wikipedia.org/wiki/ISO_8601>`_.
    - It supports many, but not all, frequencies supported by
      ``pandas.date_range``.  For example it does not currently support any of
      the business-related or semi-monthly frequencies.
    - Compound sub-monthly frequencies are not supported, e.g. '1H1min', as
      these can easily be written in terms of the finest common resolution,
      e.g. '61min'.

    Valid simple frequency strings for use with ``cftime``-calendars include
    any multiples of the following.

    +--------+--------------------------+
    | Alias  | Description              |
    +========+==========================+
    | A, Y   | Year-end frequency       |
    +--------+--------------------------+
    | AS, YS | Year-start frequency     |
    +--------+--------------------------+
    | Q      | Quarter-end frequency    |
    +--------+--------------------------+
    | QS     | Quarter-start frequency  |
    +--------+--------------------------+
    | M      | Month-end frequency      |
    +--------+--------------------------+
    | MS     | Month-start frequency    |
    +--------+--------------------------+
    | D      | Day frequency            |
    +--------+--------------------------+
    | H      | Hour frequency           |
    +--------+--------------------------+
    | T, min | Minute frequency         |
    +--------+--------------------------+
    | S      | Second frequency         |
    +--------+--------------------------+
    | L, ms  | Millisecond frequency    |
    +--------+--------------------------+
    | U, us  | Microsecond frequency    |
    +--------+--------------------------+

    Any multiples of the following anchored offsets are also supported.

    +----------+--------------------------------------------------------------------+
    | Alias    | Description                                                        |
    +==========+====================================================================+
    | A(S)-JAN | Annual frequency, anchored at the end (or beginning) of January    |
    +----------+--------------------------------------------------------------------+
    | A(S)-FEB | Annual frequency, anchored at the end (or beginning) of February   |
    +----------+--------------------------------------------------------------------+
    | A(S)-MAR | Annual frequency, anchored at the end (or beginning) of March      |
    +----------+--------------------------------------------------------------------+
    | A(S)-APR | Annual frequency, anchored at the end (or beginning) of April      |
    +----------+--------------------------------------------------------------------+
    | A(S)-MAY | Annual frequency, anchored at the end (or beginning) of May        |
    +----------+--------------------------------------------------------------------+
    | A(S)-JUN | Annual frequency, anchored at the end (or beginning) of June       |
    +----------+--------------------------------------------------------------------+
    | A(S)-JUL | Annual frequency, anchored at the end (or beginning) of July       |
    +----------+--------------------------------------------------------------------+
    | A(S)-AUG | Annual frequency, anchored at the end (or beginning) of August     |
    +----------+--------------------------------------------------------------------+
    | A(S)-SEP | Annual frequency, anchored at the end (or beginning) of September  |
    +----------+--------------------------------------------------------------------+
    | A(S)-OCT | Annual frequency, anchored at the end (or beginning) of October    |
    +----------+--------------------------------------------------------------------+
    | A(S)-NOV | Annual frequency, anchored at the end (or beginning) of November   |
    +----------+--------------------------------------------------------------------+
    | A(S)-DEC | Annual frequency, anchored at the end (or beginning) of December   |
    +----------+--------------------------------------------------------------------+
    | Q(S)-JAN | Quarter frequency, anchored at the end (or beginning) of January   |
    +----------+--------------------------------------------------------------------+
    | Q(S)-FEB | Quarter frequency, anchored at the end (or beginning) of February  |
    +----------+--------------------------------------------------------------------+
    | Q(S)-MAR | Quarter frequency, anchored at the end (or beginning) of March     |
    +----------+--------------------------------------------------------------------+
    | Q(S)-APR | Quarter frequency, anchored at the end (or beginning) of April     |
    +----------+--------------------------------------------------------------------+
    | Q(S)-MAY | Quarter frequency, anchored at the end (or beginning) of May       |
    +----------+--------------------------------------------------------------------+
    | Q(S)-JUN | Quarter frequency, anchored at the end (or beginning) of June      |
    +----------+--------------------------------------------------------------------+
    | Q(S)-JUL | Quarter frequency, anchored at the end (or beginning) of July      |
    +----------+--------------------------------------------------------------------+
    | Q(S)-AUG | Quarter frequency, anchored at the end (or beginning) of August    |
    +----------+--------------------------------------------------------------------+
    | Q(S)-SEP | Quarter frequency, anchored at the end (or beginning) of September |
    +----------+--------------------------------------------------------------------+
    | Q(S)-OCT | Quarter frequency, anchored at the end (or beginning) of October   |
    +----------+--------------------------------------------------------------------+
    | Q(S)-NOV | Quarter frequency, anchored at the end (or beginning) of November  |
    +----------+--------------------------------------------------------------------+
    | Q(S)-DEC | Quarter frequency, anchored at the end (or beginning) of December  |
    +----------+--------------------------------------------------------------------+

    Finally, the following calendar aliases are supported.

    +--------------------------------+---------------------------------------+
    | Alias                          | Date type                             |
    +================================+=======================================+
    | standard, gregorian            | ``cftime.DatetimeGregorian``          |
    +--------------------------------+---------------------------------------+
    | proleptic_gregorian            | ``cftime.DatetimeProlepticGregorian`` |
    +--------------------------------+---------------------------------------+
    | noleap, 365_day                | ``cftime.DatetimeNoLeap``             |
    +--------------------------------+---------------------------------------+
    | all_leap, 366_day              | ``cftime.DatetimeAllLeap``            |
    +--------------------------------+---------------------------------------+
    | 360_day                        | ``cftime.Datetime360Day``             |
    +--------------------------------+---------------------------------------+
    | julian                         | ``cftime.DatetimeJulian``             |
    +--------------------------------+---------------------------------------+

    Examples
    --------
    This function returns a ``CFTimeIndex``, populated with ``cftime.datetime``
    objects associated with the specified calendar type, e.g.

    >>> xr.cftime_range(start="2000", periods=6, freq="2MS", calendar="noleap")
    CFTimeIndex([2000-01-01 00:00:00, 2000-03-01 00:00:00, 2000-05-01 00:00:00,
                 2000-07-01 00:00:00, 2000-09-01 00:00:00, 2000-11-01 00:00:00],
                dtype='object', length=6, calendar='noleap', freq='2MS')

    As in the standard pandas function, three of the ``start``, ``end``,
    ``periods``, or ``freq`` arguments must be specified at a given time, with
    the other set to ``None``.  See the `pandas documentation
    <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.date_range.html>`_
    for more examples of the behavior of ``date_range`` with each of the
    parameters.

    See Also
    --------
    pandas.date_range
    rV   zZOf the arguments 'start', 'end', 'periods', and 'freq', three must be specified at a time.NFTleftrightz-Closed must be either 'left', 'right' or Noner   r   r.   )name)r   rH   r   r   r   r   r   Zarraylistr   lenr	   )rD   rE   r   r   r   r   closedr   Zdatesr   Zleft_closedZright_closedr   r   r   cftime_range  s<     4



 (r   )rD   )rV   )N)NNNr   FNNr   )9rx   r   r)   r   	functoolsr   typingr   r   Znumpyr   Zcore.pdcompatr   Zcftimeindexr	   r
   timesr   r   r   r   r   r?   rF   rQ   rR   rU   rY   rZ   r[   r`   ru   rj   ry   r}   r   r   r   r   r   r   r   r   r   r   joinkeysZ_FREQUENCY_CONDITIONr   ZCFTIME_TICKSr   r   r   r   r   r   r   r   r   r   r   <module>   s  *
U	

)2$






















































E
9        