a
    DBìj¹.  ã                   @  s–  d Z ddlmZ ddlmZmZ ddlmZmZm	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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  erÔddl!m"Z"m#Z# ddl$m%Z%m&Z& ddddddœdd„Z'G dd„ deƒZ(G dd„ de(ƒZ)G dd„ de(ƒZ*dddœdd „Z+d!d"d!d#œd$d%„Z,d!d"d!d&œd'd(„Z-d!d"d!d&œd)d*„Z.d!d"d!d+œd,d-„Z/d!d.d/œd0d1„Z0dd2d3œd4d5„Z1dS )6z–
Module responsible for execution of NDFrame.describe() method.

Method NDFrame.describe() delegates actual execution to function describe_ndframe().
é    )Úannotations)ÚABCÚabstractmethod)ÚTYPE_CHECKINGÚCallableÚcastN)Ú	Timestamp)ÚDtypeObjÚNDFrameTÚnpt)Úvalidate_percentile)Úis_bool_dtypeÚis_numeric_dtype)Ú
ArrowDtypeÚDatetimeTZDtypeÚExtensionDtype)ÚFloat64Dtype)Úconcat)Úformat_percentiles)ÚHashableÚSequence)Ú	DataFrameÚSeriesr
   ústr | Sequence[str] | Nonez#Sequence[float] | np.ndarray | None)ÚobjÚincludeÚexcludeÚpercentilesÚreturnc                 C  sN   t |ƒ}| jdkr$ttd| ƒd�}nttd| ƒ||d�}|j|d�}tt|ƒS )a   Describe series or dataframe.

    Called from pandas.core.generic.NDFrame.describe()

    Parameters
    ----------
    obj: DataFrame or Series
        Either dataframe or series to be described.
    include : 'all', list-like of dtypes or None (default), optional
        A white list of data types to include in the result. Ignored for ``Series``.
    exclude : list-like of dtypes or None (default), optional,
        A black list of data types to omit from the result. Ignored for ``Series``.
    percentiles : list-like of numbers, optional
        The percentiles to include in the output. All should fall between 0 and 1.
        The default is ``[.25, .5, .75]``, which returns the 25th, 50th, and
        75th percentiles.

    Returns
    -------
    Dataframe or series description.
    é   r   ©r   r   )r   r   r   )r   )Ú_refine_percentilesÚndimÚSeriesDescriberr   ÚDataFrameDescriberÚdescriber
   )r   r   r   r   Z	describerÚresult© r'   ú[/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pandas/core/methods/describe.pyÚdescribe_ndframe7   s    
ÿýr)   c                   @  s4   e Zd ZdZdddœdd„Zedddœd	d
„ƒZdS )ÚNDFrameDescriberAbstractz”Abstract class for describing dataframe or series.

    Parameters
    ----------
    obj : Series or DataFrame
        Object to be described.
    zDataFrame | SeriesÚNone)r   r   c                 C  s
   || _ d S ©Nr    )Úselfr   r'   r'   r(   Ú__init__n   s    z!NDFrameDescriberAbstract.__init__úSequence[float] | np.ndarray©r   r   c                 C  s   dS )z¸Do describe either series or dataframe.

        Parameters
        ----------
        percentiles : list-like of numbers
            The percentiles to include in the output.
        Nr'   )r-   r   r'   r'   r(   r%   q   s    z!NDFrameDescriberAbstract.describeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r.   r   r%   r'   r'   r'   r(   r*   e   s   r*   c                   @  s*   e Zd ZU dZded< dddœdd„ZdS )	r#   z2Class responsible for creating series description.r   r   r/   r0   c                 C  s   t | jƒ}|| j|ƒS r,   )Úselect_describe_funcr   )r-   r   Údescribe_funcr'   r'   r(   r%   �   s    ÿzSeriesDescriber.describeN)r1   r2   r3   r4   Ú__annotations__r%   r'   r'   r'   r(   r#   |   s   
r#   c                      sT   e Zd ZU dZded< dddddœ‡ fdd„Zd	dd
œdd„Zddœdd„Z‡  ZS )r$   ab  Class responsible for creating dataobj description.

    Parameters
    ----------
    obj : DataFrame
        DataFrame to be described.
    include : 'all', list-like of dtypes or None
        A white list of data types to include in the result.
    exclude : list-like of dtypes or None
        A black list of data types to omit from the result.
    r   r   r   r+   )r   r   r   r   c                  s:   || _ || _|jdkr*|jjdkr*tdƒ‚tƒ  |¡ d S )Né   r   z+Cannot describe a DataFrame without columns)r   r   r"   ÚcolumnsÚsizeÚ
ValueErrorÚsuperr.   )r-   r   r   r   ©Ú	__class__r'   r(   r.   —   s
    zDataFrameDescriber.__init__r/   r0   c                   sj   |   ¡ }g }| ¡ D ] \}}t|ƒ}| |||ƒ¡ qt|ƒ‰ t‡ fdd„|D ƒddd�}|j ¡ |_|S )Nc                   s   g | ]}|j ˆ d d�‘qS )F)Úcopy)Zreindex©Ú.0Úx©Z	col_namesr'   r(   Ú
<listcomp>°   ó    z/DataFrameDescriber.describe.<locals>.<listcomp>r   F)ZaxisÚsort)Ú_select_dataÚitemsr5   ÚappendÚreorder_columnsr   r9   r?   )r-   r   ÚdataÚldescÚ_Úseriesr6   Údr'   rC   r(   r%   ¦   s    ýzDataFrameDescriber.describe)r   c                 C  s‚   | j du rB| jdu rBtjdg}| jj|d�}t|jƒdkr~| j}n<| j dkrj| jdurbd}t|ƒ‚| j}n| jj| j | jd�}|S )zSelect columns to be described.NÚdatetime)r   r   Úallz*exclude must be None when include is 'all')r   r   )	r   r   ÚnpÚnumberr   Zselect_dtypesÚlenr9   r;   )r-   Zdefault_includerK   Úmsgr'   r'   r(   rG   ·   s    


þzDataFrameDescriber._select_data)	r1   r2   r3   r4   r7   r.   r%   rG   Ú__classcell__r'   r'   r=   r(   r$   ˆ   s
   
r$   zSequence[Series]zlist[Hashable])rL   r   c                 C  sT   g }t ƒ }tdd„ | D ƒtd�}|D ]*}|D ] }||vr,| |¡ | |¡ q,q$|S )z,Set a convenient order for rows for display.c                 s  s   | ]}|j V  qd S r,   )Úindexr@   r'   r'   r(   Ú	<genexpr>Ð   rE   z"reorder_columns.<locals>.<genexpr>)Úkey)ÚsetÚsortedrT   ÚaddrI   )rL   ÚnamesZ
seen_namesZldesc_indexesZidxnamesÚnamer'   r'   r(   rJ   Ì   s    
rJ   r   zSequence[float])rN   r   r   c                 C  sÐ   ddl m} t|ƒ}g d¢| dg }|  ¡ |  ¡ |  ¡ |  ¡ g|  |¡ ¡  |  	¡ g }t
| jtƒr¢t
| jtƒrš| jjdkr„d}q ddl}t| ¡ ƒ}q¾tƒ }n| jjdv rºt d¡}nd}|||| j|d	�S )
zÛDescribe series containing numerical data.

    Parameters
    ----------
    series : Series
        Series to be described.
    percentiles : list-like of numbers
        The percentiles to include in the output.
    r   ©r   )ÚcountÚmeanÚstdÚminÚmaxÚmNZiufbÚfloat©rW   r^   Údtype)Úpandasr   r   r`   ra   rb   rc   ÚquantileÚtolistrd   Ú
isinstancerh   r   r   ÚkindZpyarrowZfloat64r   rR   r^   )rN   r   r   Úformatted_percentilesÚ
stat_indexrO   rh   Úpar'   r'   r(   Údescribe_numeric_1dÙ   s(    
ÿþÿrq   )rK   Úpercentiles_ignoredr   c           
      C  s„   g d¢}|   ¡ }t||dk ƒ}|dkrD|jd |jd  }}d}ntjtj }}d}|  ¡ |||g}ddlm}	 |	||| j	|d�S )zãDescribe series containing categorical data.

    Parameters
    ----------
    data : Series
        Series to be described.
    percentiles_ignored : list-like of numbers
        Ignored, but in place to unify interface.
    )r`   ÚuniqueÚtopÚfreqr   NÚobjectr_   rg   )
Úvalue_countsrT   rW   ÚilocrR   Únanr`   ri   r   r^   )
rK   rr   r]   Ú	objcountsÚcount_uniquert   ru   rh   r&   r   r'   r'   r(   Údescribe_categorical_1d  s    r|   c                 C  s
  ddg}|   ¡ }t||dk ƒ}|  ¡ |g}d}|dkrÌ|jd |jd  }}| jj}	|  ¡ j 	d¡}
t
|ƒ}|jdurŒ|	durŒ| |	¡}n
| |	¡}|g d¢7 }|||t
|
 ¡ |	d�t
|
 ¡ |	d�g7 }n |dd	g7 }|tjtjg7 }d
}ddlm} |||| j|d�S )zøDescribe series containing timestamp data treated as categorical.

    Parameters
    ----------
    data : Series
        Series to be described.
    percentiles_ignored : list-like of numbers
        Ignored, but in place to unify interface.
    r`   rs   r   NÚi8)rt   ru   ÚfirstÚlast)Útzrt   ru   rv   r_   rg   )rw   rT   r`   rW   rx   Údtr€   ZdropnaÚvaluesÚviewr   ÚtzinfoZ
tz_convertZtz_localizerc   rd   rR   ry   ri   r   r^   )rK   rr   r]   rz   r{   r&   rh   rt   ru   r€   Zasintr   r'   r'   r(   Ú$describe_timestamp_as_categorical_1d"  s2    
ü
r…   )rK   r   r   c                 C  sd   ddl m} t|ƒ}g d¢| dg }|  ¡ |  ¡ |  ¡ g|  |¡ ¡  |  ¡ g }|||| j	d�S )zÛDescribe series containing datetime64 dtype.

    Parameters
    ----------
    data : Series
        Series to be described.
    percentiles : list-like of numbers
        The percentiles to include in the output.
    r   r_   )r`   ra   rc   rd   )rW   r^   )
ri   r   r   r`   ra   rc   rj   rk   rd   r^   )rK   r   r   rn   ro   rO   r'   r'   r(   Údescribe_timestamp_1dR  s    ÿþÿr†   r   )rK   r   c                 C  sN   t | jƒrtS t| ƒrtS | jjdks2t| jtƒr6tS | jjdkrFtS tS dS )z–Select proper function for describing series based on data type.

    Parameters
    ----------
    data : Series
        Series to be described.
    ÚMre   N)	r   rh   r|   r   rq   rm   rl   r   r†   )rK   r'   r'   r(   r5   j  s    

r5   znpt.NDArray[np.float64]r0   c                 C  st   | du rt  g d¢¡S t| ƒ} t| ƒ d| vr8|  d¡ t  | ¡} t  | ¡}| dusXJ ‚t|ƒt| ƒk rptdƒ‚|S )zº
    Ensure that percentiles are unique and sorted.

    Parameters
    ----------
    percentiles : list-like of numbers, optional
        The percentiles to include in the output.
    N)g      Ð?ç      à?g      è?rˆ   z%percentiles cannot contain duplicates)	rR   ÚarrayÚlistr   rI   Zasarrayrs   rT   r;   )r   Zunique_pctsr'   r'   r(   r!   €  s    


r!   )2r4   Ú
__future__r   Úabcr   r   Útypingr   r   r   ÚnumpyrR   Zpandas._libs.tslibsr   Zpandas._typingr	   r
   r   Zpandas.util._validatorsr   Zpandas.core.dtypes.commonr   r   Zpandas.core.dtypes.dtypesr   r   r   Zpandas.core.arrays.floatingr   Zpandas.core.reshape.concatr   Zpandas.io.formats.formatr   Úcollections.abcr   r   ri   r   r   r)   r*   r#   r$   rJ   rq   r|   r…   r†   r5   r!   r'   r'   r'   r(   Ú<module>   s4   .D) 0