o
    ôT·j¹.  ã                   @  sX  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rjddl!m"Z"m#Z# ddl$m%Z%m&Z& d8dd„Z'G dd„ deƒZ(G dd„ de(ƒZ)G dd„ de(ƒZ*d9d#d$„Z+d:d(d)„Z,d;d,d-„Z-d;d.d/„Z.d<d0d1„Z/d=d3d4„Z0d>d6d7„Z1dS )?z–
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ÚSeriesÚobjr
   Úincludeústr | Sequence[str] | NoneÚexcludeÚpercentilesú#Sequence[float] | np.ndarray | NoneÚ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   Ú	describerÚresult© r)   ú_/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/pandas/core/methods/describe.pyÚdescribe_ndframe7   s   
ÿý
r+   c                   @  s(   e Zd ZdZddd„Zedd
d„ƒZdS )ÚNDFrameDescriberAbstractz”Abstract class for describing dataframe or series.

    Parameters
    ----------
    obj : Series or DataFrame
        Object to be described.
    r   úDataFrame | Seriesr   ÚNonec                 C  s
   || _ d S ©Nr!   )Úselfr   r)   r)   r*   Ú__init__n   s   
z!NDFrameDescriberAbstract.__init__r   úSequence[float] | np.ndarrayc                 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)   )r0   r   r)   r)   r*   r&   q   s    z!NDFrameDescriberAbstract.describeN)r   r-   r   r.   )r   r2   r   r-   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r1   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„Zd	S )r$   z2Class responsible for creating series description.r   r   r   r2   r   c                 C  s   t | jƒ}|| j|ƒS r/   )Úselect_describe_funcr   )r0   r   Údescribe_funcr)   r)   r*   r&   �   s   ÿzSeriesDescriber.describeN)r   r2   r   r   )r3   r4   r5   r6   Ú__annotations__r&   r)   r)   r)   r*   r$   |   s   
 r$   c                      s@   e Zd ZU dZded< d‡ fd	d
„Zddd„Z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.   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Úsuperr1   )r0   r   r   r   ©Ú	__class__r)   r*   r1   —   s
   zDataFrameDescriber.__init__r   r2   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)Úreindex©Ú.0Úx©Ú	col_namesr)   r*   Ú
<listcomp>°   s    z/DataFrameDescriber.describe.<locals>.<listcomp>r    F)ÚaxisÚsort)Ú_select_dataÚitemsr7   ÚappendÚreorder_columnsr   r;   rA   )r0   r   ÚdataÚldescÚ_Úseriesr8   Údr)   rF   r*   r&   ¦   s   ýzDataFrameDescriber.describec                 C  s†   | j du r"| jdu r"tjdg}| jj|d�}t|jƒdkr | j}|S | j dkr7| jdur2d}t|ƒ‚| j}|S | 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   Úselect_dtypesÚlenr;   r=   )r0   Údefault_includerO   Úmsgr)   r)   r*   rK   ·   s"   

ö
üþzDataFrameDescriber._select_data)r   r   r   r   r   r   r   r.   )r   r2   r   r   )r   r   )	r3   r4   r5   r6   r9   r1   r&   rK   Ú__classcell__r)   r)   r?   r*   r%   ˆ   s   
 
r%   rP   úSequence[Series]úlist[Hashable]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/   )ÚindexrC   r)   r)   r*   Ú	<genexpr>Ð   s   € z"reorder_columns.<locals>.<genexpr>)Úkey)ÚsetÚsortedrY   ÚaddrM   )rP   ÚnamesÚ
seen_namesÚldesc_indexesÚidxnamesÚnamer)   r)   r*   rN   Ì   s   

€ýrN   rR   r   úSequence[float]c                 C  sÐ   ddl m} t|ƒ}g d¢| dg }|  ¡ |  ¡ |  ¡ |  ¡ g|  |¡ ¡  |  	¡ g }t
| jtƒrQt
| jtƒrM| jjdkrBd}nddl}t| ¡ ƒ}n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ÚmNÚiufbÚfloat©r_   ri   Údtype)Úpandasr   r   rl   rm   rn   ro   ÚquantileÚtolistrp   Ú
isinstanceru   r   r   ÚkindÚpyarrowÚfloat64r   rV   ri   )rR   r   r   Úformatted_percentilesÚ
stat_indexrS   ru   Úpar)   r)   r*   Údescribe_numeric_1dÙ   s(   
ÿþÿr€   rO   Úpercentiles_ignoredc           
      C  s„   g d¢}|   ¡ }t||dk ƒ}|dkr"|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.
    )rl   ÚuniqueÚtopÚfreqr   NÚobjectrk   rt   )
Úvalue_countsrY   r_   ÚilocrV   Únanrl   rv   r   ri   )
rO   r�   re   Ú	objcountsÚcount_uniquerƒ   r„   ru   r(   r   r)   r)   r*   Údescribe_categorical_1d  s   r‹   c                 C  s
  ddg}|   ¡ }t||dk ƒ}|  ¡ |g}d}|dkrf|jd |jd }}| jj}	|  ¡ j 	d¡}
t
|ƒ}|jdurF|	durF| |	¡}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.
    rl   r‚   r   NÚi8)rƒ   r„   ÚfirstÚlast)Útzrƒ   r„   r…   rk   rt   )r†   rY   rl   r_   r‡   Údtr�   ÚdropnaÚvaluesÚviewr   ÚtzinfoÚ
tz_convertÚtz_localizero   rp   rV   rˆ   rv   r   ri   )rO   r�   re   r‰   rŠ   r(   ru   rƒ   r„   r�   Úasintr   r)   r)   r*   Ú$describe_timestamp_as_categorical_1d"  s2   
ü
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   rk   )rl   rm   ro   rp   )r_   ri   )
rv   r   r   rl   rm   ro   rw   rx   rp   ri   )rO   r   r   r}   r~   rS   r)   r)   r*   Údescribe_timestamp_1dR  s   ÿþÿr™   r   c                 C  sJ   t | jƒrtS t| ƒrtS | jjdkst| jtƒrtS | jjdkr#tS tS )z–Select proper function for describing series based on data type.

    Parameters
    ----------
    data : Series
        Series to be described.
    ÚMrq   )	r   ru   r‹   r   r€   rz   ry   r   r™   )rO   r)   r)   r*   r7   j  s   

r7   únpt.NDArray[np.float64]c                 C  st   | du rt  g d¢¡S t| ƒ} t| ƒ d| vr|  d¡ t  | ¡} t  | ¡}| dus,J ‚t|ƒt| ƒk r8t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)	rV   ÚarrayÚlistr   rM   Úasarrayr‚   rY   r=   )r   Úunique_pctsr)   r)   r*   r"   €  s   


r"   )
r   r
   r   r   r   r   r   r   r   r
   )rP   r]   r   r^   )rR   r   r   rj   r   r   )rO   r   r�   rj   r   r   )rO   r   r   rj   r   r   )rO   r   r   r   )r   r   r   r›   )2r6   Ú
__future__r   Úabcr   r   Útypingr   r   r   ÚnumpyrV   Úpandas._libs.tslibsr   Úpandas._typingr	   r
   r   Úpandas.util._validatorsr   Úpandas.core.dtypes.commonr   r   Úpandas.core.dtypes.dtypesr   r   r   Úpandas.core.arrays.floatingr   Úpandas.core.reshape.concatr   Úpandas.io.formats.formatr   Úcollections.abcr   r   rv   r   r   r+   r,   r$   r%   rN   r€   r‹   r˜   r™   r7   r"   r)   r)   r)   r*   Ú<module>   s6    
.
D

)
 
0
