a
    İa                     @   s   d Z ddlZddlZddlZddlmZ ddl	m
Z ddlmZ ddlmZ ddlmZ eeeefZejefe Ze Zd	d
 ZG dd dZdd Zdd Zdd Zdd ZdZ e D ]Z!ee!e" e!< qdS )ar  xarray specific universal functions

Handles unary and binary operations for the following types, in ascending
priority order:
- scalars
- numpy.ndarray
- dask.array.Array
- xarray.Variable
- xarray.DataArray
- xarray.Dataset
- xarray.core.groupby.GroupBy

Once NumPy 1.10 comes out with support for overriding ufuncs, this module will
hopefully no longer be necessary.
    N   )	DataArray)Dataset)GroupBy)dask_array_type)Variablec                 C   s(   t tD ]\}}t| |r|  S qdS )N)	enumerate_dispatch_order
isinstance)objprioritycls r   ,lib/python3.9/site-packages/xarray/ufuncs.py_dispatch_priority    s    

r   c                   @   s    e Zd ZdZdd Zdd ZdS )_UFuncDispatcherzWrapper for dispatching ufuncs.c                 C   s
   || _ d S N)_name)selfnamer   r   r   __init__*   s    z_UFuncDispatcher.__init__c                 O   sF  | j dvrtjdtdd |}t}t|dks:t|dkrRtdt|| j nt|dkr|t|d t	r|d 
| }nltt|\}}||krt|d t	r|d |d | }n2t|d t	r|d j|d | dd	}tt|}|tu rtt| j }||i |}|tu rBt| j d
t|d dt|d d|S )N)angle	iscomplexz@xarray.ufuncs is deprecated. Instead, use numpy ufuncs directly.   )
stacklevelr   z#cannot handle {} arguments for {!r}r   T)Z	reflexivez not implemented for types (z, ))r   	_warningswarnFutureWarning
_UNDEFINEDlen	TypeErrorformatr   _xarray_typesZ	_unary_opmapr   Z
_binary_optuplereversedgetattr_npNotImplementedtype)r   argskwargsnew_argsresZp1Zp2fr   r   r   __call__-   s<    


&z_UFuncDispatcher.__call__N)__name__
__module____qualname____doc__r   r1   r   r   r   r   r   '   s   r   c                 C   s6   t | ts| S | |r2| d}| |d d  } | S )Nz

r   )r   str
startswithfind)docr   Zsignature_endr   r   r   _skip_signatureR   s    


r:   c                 C   sd   t | ts| S d}t|D ]D}d| d}d| d}| d}|| vs|| v rRq| ||} q| S )N   z.. [][z]_z.    )r   r6   rangereplace)r9   Zmax_referencesZnumZlabelZ	referenceindexr   r   r   _remove_unused_reference_labels]   s    

rA   c                 C   s   t | ts| S t| S r   )r   r6   textwrapdedent)r9   r   r   r   _dedento   s    
rD   c                 C   sB   t | }| |_tt| j}ttt|| }d|  d| |_|S )Nz!xarray specific variant of numpy.z. Handles xarray.Dataset, xarray.DataArray, xarray.Variable, numpy.ndarray and dask.array.Array objects with automatic dispatching.

Documentation from numpy:

)r   r2   r(   r)   r5   rA   r:   rD   )r   funcr9   r   r   r   
_create_opv   s    rF   );r   ZarccosZarccoshZarcsinZarcsinhZarctanZarctan2ZarctanhZceilZconjZcopysignZcosZcoshZdeg2radZdegreesZexpZexpm1ZfabsZfixZfloorZfmaxZfminfmodrG   ZfrexpZhypotimagr   ZisfiniteZisinfZisnanZisrealZldexplogZlog10Zlog1pZlog2Z	logaddexpZ
logaddexp2Zlogical_andZlogical_notZ
logical_orZlogical_xorZmaximumZminimumZ	nextafterZrad2degZradiansrealZrintsignZsignbitZsinZsinhZsqrtZsquareZtanZtanhZtrunc)#r5   rB   warningsr   Znumpyr)   Zcore.dataarrayr   Z
_DataArrayZcore.datasetr   Z_DatasetZcore.groupbyr   Z_GroupByZcore.pycompatr   Z_dask_array_typeZcore.variabler   Z	_Variabler$   Zndarrayr
   objectr    r   r   r:   rA   rD   rF   __all__r   globalsr   r   r   r   <module>   s(   +?