o
    tBh:                     @   s   d dl Zd dlZd dlZd dlmZ d dlmZm	Z	 d dl
Z
dddZdddZdd	 Zd
d Zdd ZdZdZddZe	eeeZe
j	ee
j	jd dZdZdZddZe	eeeZe
j	ee
j	jddZ	 		 dddZdS )    N)wraps)FunctionDoc	Parameterc                 C   s   dd | D }t ||S )a  
    Broadcast shapes of arrays, dropping specified axes

    Given a sequence of arrays `arrays` and an integer or tuple `axis`, find
    the shape of the broadcast result after consuming/dropping `axis`.
    In other words, return output shape of a typical hypothesis test on
    `arrays` vectorized along `axis`.

    Examples
    --------
    >>> a = np.zeros((5, 2, 1))
    >>> b = np.zeros((9, 3))
    >>> _broadcast_array_shapes((a, b), 1)
    (5, 3)
    c                 S      g | ]}|j qS  shape).0arrr   r   s/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/scipy/stats/_axis_nan_policy.py
<listcomp>!       z7_broadcast_array_shapes_remove_axis.<locals>.<listcomp>)_broadcast_shapes_remove_axis)arraysaxisshapesr   r   r   #_broadcast_array_shapes_remove_axis   s   
r   c                 C   s   t dd | D }tjt| |ftd}t|| D ]\}}||t|t| d< q|dur6tj||dd}tj |dd}||jdd9 }t|dk||kB  rUt	dt
|S )	z
    Broadcast shapes, dropping specified axes

    Same as _broadcast_array_shapes, but given a sequence
    of array shapes `shapes` instead of the arrays themselves.
    c                 S   s   g | ]}t |qS r   len)r	   r   r   r   r   r   ,       z1_broadcast_shapes_remove_axis.<locals>.<listcomp>)dtypeN   r   r   z/Array shapes are incompatible for broadcasting.)maxnponesr   intzipdeleteallany
ValueErrortuple)r   r   n_dims
new_shapesrowr   	new_shaper   r   r   r   %   s   r   c                    st   t dd | D fdd| D }  fdd| D } t| ddfdd| D } tj| dd}t| d}|S )z3Concatenate arrays along an axis with broadcasting.c                 S   r   r   ndimr	   xr   r   r   r   <   r   z*_broadcast_concatenate.<locals>.<listcomp>c                    s,   g | ]}| d g |j  t|j qS )r   )reshaper(   listr   r)   r'   r   r   r   =   s   , c                    s   g | ]	}t | d qS )r   swapaxesr)   r   r   r   r   ?   s    r.   r   c                    s$   g | ]}t | |jd  f qS r-   )r   broadcast_tor   r)   r   r   r   r   C   s   $ )r   r   r   concatenater/   )xsr   resr   )r   r(   r   r   _broadcast_concatenate9   s   r4   c                    sX   |s	dd | D S t | d }| dd D ]	}|t |B }q|   fdd| D S )z+Remove nans from paired or unpaired samplesc                 S   s   g | ]
}|t |  qS r   r   isnanr	   sampler   r   r   r   P   s    z _remove_nans.<locals>.<listcomp>r   r   Nc                    s   g | ]}|  qS r   r   r7   not_nansr   r   r   X   r   r5   )samplespairednansr8   r   r9   r   _remove_nansL   s   r>   c                 C   s4   t dd | D sdS t| |}t|tj }|S )zU
    Check for empty sample; return appropriate output for a vectorized hypotest
    c                 s   s    | ]}|j d kV  qdS )r   N)sizer7   r   r   r   	<genexpr>`   s    z&_check_empty_inputs.<locals>.<genexpr>N)r    r   r   r   nan)r;   r   output_shapeoutputr   r   r   _check_empty_inputs[   s
   
rD   r   zint or None, default: 0zIf an int, the axis of the input along which to compute the statistic.
The statistic of each axis-slice (e.g. row) of the input will appear in a
corresponding element of the output.
If ``None``, the input will be raveled before computing the statistic.
)default
nan_policyz{'propagate', 'omit', 'raise'}a  Defines how to handle input NaNs.

- ``propagate``: if a NaN is present in the axis slice (e.g. row) along
  which the  statistic is computed, the corresponding entry of the output
  will be NaN.
- ``omit``: NaNs will be omitted when performing the calculation.
  If insufficient data remains in the axis slice along which the
  statistic is computed, the corresponding entry of the output will be
  NaN.
- ``raise``: if a NaN is present, a ``ValueError`` will be raised.	propagater   Fc                    s6   du rdd fdd fdd}|S )aB  Factory for a wrapper that adds axis/nan_policy params to a function.

    Parameters
    ----------
    result_object : callable
        Callable that returns an object of the type returned by the function
        being wrapped (e.g. the namedtuple or dataclass returned by a
        statistical test) provided the separate components (e.g. statistic,
        pvalue).
    default_axis : int, default: 0
        The default value of the axis argument. Standard is 0 except when
        backwards compatibility demands otherwise (e.g. `None`).
    n_samples : int or callable, default: 1
        The number of data samples accepted by the function
        (e.g. `mannwhitneyu`), a callable that accepts a dictionary of
        parameters passed into the function and returns the number of data
        samples (e.g. `wilcoxon`), or `None` to indicate an arbitrary number
        of samples (e.g. `kruskal`).
    paired : {False, True}
        Whether the function being wrapped treats the samples as paired (i.e.
        corresponding elements of each sample should be considered as different
        components of the same sample.)
    result_unpacker : callable, optional
        Function that unpacks the results of the function being wrapped into
        a tuple. This is essentially the inverse of `result_object`. Default
        is `None`, which is appropriate for statistical tests that return a
        statistic, pvalue tuple (rather than, e.g., a non-iterable datalass).
    too_small : int, default: 0
        The largest unnacceptably small sample for the function being wrapped.
        For example, some functions require samples of size two or more or they
        raise an error. This argument prevents the error from being raised when
        input is not 1D and instead places a NaN in the corresponding element
        of the result.
    Nc                 S   s   | d | d fS )N).r   ).r   r   )r3   r   r   r   result_unpacker   s   z1_axis_nan_policy_factory.<locals>.result_unpackerc                    s    | D ]}t | kr dS qdS )NTFr   )r;   r8   )	too_smallr   r   is_too_small   s
   z._axis_nan_policy_factory.<locals>.is_too_smallc              	      s  t  dd fdd
}t|}dd |d D }d|v r.t|d |d< n|d t d	|v rCt|d |d	< n|d t t|d
dd }t||_t	
|}|j}t| }d|vrp|t d	|vry|t |j|d}||_|S )NF)_no_decoc                    s  | r	|i S t tj}d u r&dd tt|D |dd   }tt||}t|t@ }|rHj	 dt |d  d}t
|| trVnp[t|fdd|d  D }d|v rod	nd
}d dd}	~ d u rdd |D }d n
 t krtdt  tdd |D }
t|
dkrg }|D ]}tjj||	\}}|| qt|r|	dkrЈ	tjtjS t|r|	dkrt|}|i S t| }|d ur|}| }	||S t fdd|D }t|t| }tjj||	\}}|r'|s'|d iS |r<|	dkr<	fdd}n|rO|	dkrO	fdd}n	fdd}t| d}tj |d|d}	
| S )Nc                 S   s   g | ]}d | qS )argr   )r	   ir   r   r   r          zp_axis_nan_policy_factory.<locals>.axis_nan_policy_decorator.<locals>.axis_nan_policy_wrapper.<locals>.<listcomp>r   z%() got multiple values for argument 'r   'c                    s   g | ]
}t  |qS r   )r   
atleast_1dpopr	   param)kwdsr   r   r      s    r   TFrG   rH   c                 S   s   g | ]}|  qS r   )ravelr7   r   r   r   r      r   z`axis` must be an integerc                 S   r   r   r'   r7   r   r   r   r      r   omitc                    s   g | ]}|j   qS r   r   r7   r   r   r   r     rO   c                    sB   t | d  }t|}|rt jt jS  |i S N)r   splitr>   rA   r*   r;   )hypotest_fun_inrK   rU   n_sampr<   result_objectsplit_indicesr   r   hypotest_fun)  s
   
zr_axis_nan_policy_factory.<locals>.axis_nan_policy_decorator.<locals>.axis_nan_policy_wrapper.<locals>.hypotest_func                    s>   t |  rt jt jS t | d  } |i S rX   )r   r6   r    rA   rY   rZ   )r[   rU   r\   r]   r^   r   r   r_   2  s   c                    s"   t | d  } |i S rX   )r   rY   rZ   )r[   rU   r\   r^   r   r   r_   9  s   r.   )r   r
   )!r,   inspect	signature
parametersranger   dictr   set__name__	TypeErrorupdatecallablerR   r   r!   r   arrayr   scipystats	_stats_py_contains_nanappendr    rA   r>   rD   copycumsumr4   moveaxisapply_along_axis)rL   argsrU   paramsd_argsintersectionmessager;   
vectorizedrG   ndimscontains_nansr8   contains_nan_empty_output	statisticpvaluelengthsr*   r_   r3   )default_axisr[   rK   	n_samplesr<   r]   rI   )r   rU   r\   r^   r   axis_nan_policy_wrapper   sz   "









z\_axis_nan_policy_factory.<locals>.axis_nan_policy_decorator.<locals>.axis_nan_policy_wrapperc                 S   r   r   )namerS   r   r   r   r   B  r   zO_axis_nan_policy_factory.<locals>.axis_nan_policy_decorator.<locals>.<listcomp>
Parametersr   rG   rE   r   )rb   )r   r   _axis_parameter_docindexro   _nan_policy_parameter_docstrrY   __doc__r`   ra   rb   r,   values_axis_parameter_nan_policy_parameterreplace__signature__)r[   r   docparameter_namessigrb   parameter_list)r   rK   r   r<   r]   rI   )r[   r   axis_nan_policy_decorator   s2     



z;_axis_nan_policy_factory.<locals>.axis_nan_policy_decoratorr   )r]   r   r   r<   rI   rJ   r   r   )r   rK   r   r<   r]   rI   rJ   r   _axis_nan_policy_factory   s   & !r   rX   )r   r   FNr   )numpyr   scipy.statsrk   scipy.stats._stats_py	functoolsr   scipy._lib._docscraper   r   r`   r   r   r4   r>   rD   _name_typerY   _descr   KEYWORD_ONLYr   r   r   r   r   r   r   r   <module>   sF   


