U
    `»{j}1  ã                   @  sš  d Z ddlmZ ddlmZmZ ddlZddlmZm	Z	m
Z
mZmZmZ ddlZddlZddlmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZmZmZmZmZ ddl m!Z! ddl"m#Z# erÔddl$m%Z%m&Z& d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-d.œd/d0„Z0dd1d2œd3d4„Z1dS )5z–
Module responsible for execution of NDFrame.describe() method.

Method NDFrame.describe() delegates actual execution to function describe_ndframe().
é    )Úannotations)ÚABCÚabstractmethodN)ÚTYPE_CHECKINGÚAnyÚCallableÚHashableÚSequenceÚcast)Ú	Timestamp)ÚNDFrameTÚnpt)Úfind_stack_level)Úvalidate_percentile)Úis_bool_dtypeÚis_complex_dtypeÚis_datetime64_any_dtypeÚis_numeric_dtypeÚis_timedelta64_dtype)Úconcat)Úformat_percentiles)Ú	DataFrameÚSeriesr   ústr | Sequence[str] | NoneÚboolz#Sequence[float] | np.ndarray | None)ÚobjÚincludeÚexcludeÚdatetime_is_numericÚpercentilesÚreturnc                 C  sR   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``.
    datetime_is_numeric : bool, default False
        Whether to treat datetime dtypes as numeric.
    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   r   )r   )Úrefine_percentilesÚndimÚSeriesDescriberr
   ÚDataFrameDescriberÚdescriber   )r   r   r   r   r   Z	describerÚresult© r)   úS/var/www/html/bwave/python/venv/lib/python3.8/site-packages/pandas/core/describe.pyÚdescribe_ndframe4   s    
þür+   c                   @  s6   e Zd ZdZd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.
    datetime_is_numeric : bool
        Whether to treat datetime dtypes as numeric.
    zDataFrame | Seriesr   ÚNone)r   r   r    c                 C  s   || _ || _d S ©Nr"   )Úselfr   r   r)   r)   r*   Ú__init__r   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'   v   s    z!NDFrameDescriberAbstract.describeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r0   r   r'   r)   r)   r)   r*   r,   g   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   r1   r2   c                 C  s   t | j| jƒ}|| j|ƒS r.   )Úselect_describe_funcr   r   )r/   r   Údescribe_funcr)   r)   r*   r'   †   s
    þzSeriesDescriber.describeN)r3   r4   r5   r6   Ú__annotations__r'   r)   r)   r)   r*   r%   �   s   
r%   c                      sF   e Zd ZdZddddddœ‡ fdd„Zd	dd
œdd„Zdd„ Z‡  ZS )r&   a¶  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.
    datetime_is_numeric : bool
        Whether to treat datetime dtypes as numeric.
    r   r   r   r-   )r   r   r   r   r    c                  s>   || _ || _|jdkr*|jjdkr*tdƒ‚tƒ j||d� d S )Né   r   z+Cannot describe a DataFrame without columns)r   )r   r   r$   ÚcolumnsÚsizeÚ
ValueErrorÚsuperr0   )r/   r   r   r   r   ©Ú	__class__r)   r*   r0   �   s
    zDataFrameDescriber.__init__r1   r2   c                   sn   |   ¡ }g }| ¡ D ]$\}}t|| jƒ}| |||ƒ¡ 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>·   s     z/DataFrameDescriber.describe.<locals>.<listcomp>r!   F)ZaxisÚsort)	Ú_select_dataÚitemsr7   r   ÚappendÚreorder_columnsr   r;   rA   )r/   r   ÚdataÚldescÚ_Úseriesr8   Údr)   rE   r*   r'   ­   s    ýzDataFrameDescriber.describec                 C  s�   | j dkrP| jdkrPtjg}| jr,| d¡ | jj|d�}t|j	ƒdkrŒ| j}n<| j dkrx| jdk	rpd}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   rJ   r   Zselect_dtypesÚlenr;   r=   )r/   Zdefault_includerL   Úmsgr)   r)   r*   rH   ¾   s"    


þzDataFrameDescriber._select_data)r3   r4   r5   r6   r0   r'   rH   Ú__classcell__r)   r)   r?   r*   r&   Ž   s   r&   zSequence[Series]zlist[Hashable])rM   r    c                 C  sD   g }t dd„ | D ƒtd�}|D ] }|D ]}||kr&| |¡ q&q|S )z,Set a convenient order for rows for display.c                 s  s   | ]}|j V  qd S r.   )ÚindexrB   r)   r)   r*   Ú	<genexpr>Ø   s     z"reorder_columns.<locals>.<genexpr>)Úkey)ÚsortedrU   rJ   )rM   ÚnamesZldesc_indexesZidxnamesÚnamer)   r)   r*   rK   Õ   s    rK   r   zSequence[float])rO   r   r    c                 C  sˆ   ddl m} t|ƒ}ddddg| dg }|  ¡ |  ¡ |  ¡ |  ¡ g|  |¡ ¡  |  	¡ g }t
| ƒrrt| ƒsrt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ÚmaxN©rX   r]   Údtype)Úpandasr   r   r_   r`   ra   rb   ÚquantileÚtolistrc   r   r   Úfloatr]   )rO   r   r   Úformatted_percentilesÚ
stat_indexrP   re   r)   r)   r*   Údescribe_numeric_1dà   s    
ÿþÿrl   )rL   Úpercentiles_ignoredr    c           
      C  sˆ   ddddg}|   ¡ }t||dk ƒ}|dkrH|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^   rd   )
Úvalue_countsrU   rX   ÚilocrS   Únanr_   rf   r   r]   )
rL   rm   r\   Ú	objcountsÚcount_uniquero   rp   re   r(   r   r)   r)   r*   Údescribe_categorical_1dù   s    rw   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k	rŒ|	dk	rŒ| |	¡}n
| |	¡}|dddd	g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_   rn   r   NÚi8ro   rp   ÚfirstÚlast)Útzrq   r^   rd   )rr   rU   r_   rX   rs   Údtr{   ZdropnaÚvaluesÚviewr   ÚtzinfoZ
tz_convertZtz_localizerb   rc   rS   rt   rf   r   r]   )rL   rm   r\   ru   rv   r(   re   ro   rp   r{   Zasintr   r)   r)   r*   Ú$describe_timestamp_as_categorical_1d  s2    
ü
r€   )rL   r   r    c                 C  sf   ddl m} t|ƒ}dddg| 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_   r`   rb   rc   )rX   r]   )
rf   r   r   r_   r`   rb   rg   rh   rc   r]   )rL   r   r   rj   rk   rP   r)   r)   r*   Údescribe_timestamp_1dI  s    ÿþÿr�   r   )rL   r   r    c                 C  s`   t | jƒrtS t| ƒrtS t| jƒrJ|r,tS tjdt	t
t ¡ ƒd� tS nt| jƒrXtS tS dS )zêSelect proper function for describing series based on data type.

    Parameters
    ----------
    data : Series
        Series to be described.
    datetime_is_numeric : bool
        Whether to treat datetime dtypes as numeric.
    zçTreating datetime data as categorical rather than numeric in `.describe` is deprecated and will be removed in a future version of pandas. Specify `datetime_is_numeric=True` to silence this warning and adopt the future behavior now.)Ú
stacklevelN)r   re   rw   r   rl   r   r�   ÚwarningsÚwarnÚFutureWarningr   ÚinspectÚcurrentframer€   r   )rL   r   r)   r)   r*   r7   a  s     


ú
r7   z%np.ndarray[Any, np.dtype[np.float64]]r2   c                 C  sv   | dkrt  dddg¡S t| ƒ} t| ƒ d| kr:|  d¡ t  | ¡} t  | ¡}| dk	sZt‚t|ƒt| ƒk rrt	dƒ‚|S )zº
    Ensure that percentiles are unique and sorted.

    Parameters
    ----------
    percentiles : list-like of numbers, optional
        The percentiles to include in the output.
    Ng      Ð?g      à?g      è?z%percentiles cannot contain duplicates)
rS   ÚarrayÚlistr   rJ   Zasarrayrn   ÚAssertionErrorrU   r=   )r   Zunique_pctsr)   r)   r*   r#   …  s    


r#   )2r6   Ú
__future__r   Úabcr   r   r†   Útypingr   r   r   r   r	   r
   rƒ   ÚnumpyrS   Zpandas._libs.tslibsr   Zpandas._typingr   r   Zpandas.util._exceptionsr   Zpandas.util._validatorsr   Zpandas.core.dtypes.commonr   r   r   r   r   Zpandas.core.reshape.concatr   Zpandas.io.formats.formatr   rf   r   r   r+   r,   r%   r&   rK   rl   rw   r€   r�   r7   r#   r)   r)   r)   r*   Ú<module>   s4    3G 0$