a
    .;b                     @   s   d Z ddlZdddddddd	d
ddddddZedejZdd Zdd Z	ddddddddddd d!Z
d"d# Zd$d% Zd&d' Zd(d) Zd*d+ ZdS ),z
Helper functions for np.timedelta64 and np.datetime64.
For now, multiples-of-units (for example timedeltas expressed in tens
of seconds) are not supported.
    N                     	   
               )YMWDhmsZmsusnsZpsZfsas Znatc                 C   s   t |  dk t | dk kS )zB
    Whether the *src* and *dest* units are of the same kind.
    r   DATETIME_UNITSsrcdest r   :lib/python3.9/site-packages/numba/np/npdatetime_helpers.py	same_kind(   s    r!   c                 C   sX   t |  } t | }| |krdS | dkr(dS | |kr4dS |dkr@dS | dkrT|dkrTdS dS )NTr   Fr   r   r   r   r   r    can_cast_timedelta_units/   s    r"   )r   r   )r   r   )r      )r   <   )r   r$   )r     )r	   r%   )r
   r%   )r   r%   )r   r%   )r   r%   )r   r   r   r   r   r   r   r	   r
   r   r   c                 C   s`   | dkrdS | }d}||k rLzt | \}}W n ty@   Y dS 0 ||9 }q||krX|S dS dS )z
    Return an integer multiplier allowing to convert from *big_unit_code*
    to *small_unit_code*.
    None is returned if the conversion is not possible through a
    simple integer multiplication.
    r   r   N)_factorsKeyError)Zbig_unit_codeZsmall_unit_codecfactorZmultr   r   r    _get_conversion_multiplierU   s    	
r*   c                 C   s   t t|  t| S )zl
    Return an integer multiplier allowing to convert from timedeltas
    of *src_unit* to *dest_unit*.
    )r*   r   )Zsrc_unitZ	dest_unitr   r   r    get_timedelta_conversion_factoro   s    r+   c                 C   s  t |  }t | }|dks |dkr*| ddfS |dk rJ|dkrJtd| |f d\}}|dkr|dkrpd}d	}d}q|dkrd}d
}d}n2|dkr|dkrd}d}d}n|dkrd}d}d}||krt||}|dusJ ||f||| |fS t||}|dusJ ||f| ||| fS dS )a  
    Compute a possible conversion for combining *datetime_unit* and
    *timedelta_unit* (presumably for adding or subtracting).
    Return (result unit, integer datetime multiplier, integer timedelta
    multiplier). RuntimeError is raised if the combination is impossible.
    r   r   r   z1cannot combine datetime64(%r) and timedelta64(%r))r   r   r   r   i: i  i
  i  i@  N)r   RuntimeErrorr*   )datetime_unittimedelta_unitdt_unit_codetd_unit_codeZ	dt_factorZ	td_factorr)   r   r   r    !get_datetime_timedelta_conversionx   sD    


r1   c                 C   sP   t |  }t | }|dkr|S |dkr(| S |dk r<|dkr<dS ||krH| S |S dS )z
    Return the unit result of combining *datetime_unit* with *timedelta_unit*
    (e.g. by adding or subtracting).  None is returned if combining
    those units is forbidden.
    r   r   Nr   )r-   r.   r/   r0   r   r   r     combine_datetime_timedelta_units   s    r2   c                 C   s8   t |  }t | }|dkr|S |dkr(| S ||kr4|S | S )z9
    Get the best (i.e. finer-grained) of two units.
    r   r   )Zunit_aZunit_babr   r   r    get_best_unit   s    r5   )__doc__ZnumpyZnpr   Ztimedelta64ZastypeZint64ZNATr!   r"   r&   r*   r+   r1   r2   r5   r   r   r   r    <module>   sH   	4