o
    i*2                     @  s`  d Z ddlmZ ddlmZm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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m Z  ddl!Z"ddl#m$Z$ ddl%m&Z& ernd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/Z0d<d0d1Z1d=d3d4Z2d>d6d7Z3d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AnyCallableHashableSequencecastN)	Timestamp)DtypeObjNDFrameTnpt)find_stack_level)validate_percentile)is_bool_dtypeis_complex_dtypeis_datetime64_any_dtypeis_extension_array_dtypeis_numeric_dtypeis_timedelta64_dtype)concat)format_percentiles)	DataFrameSeriesobjr   includestr | Sequence[str] | Noneexcludedatetime_is_numericboolpercentiles#Sequence[float] | np.ndarray | None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!   	describerresult r-   O/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/pandas/core/describe.pydescribe_ndframe6   s   

r/   c                   @  s(   e Zd ZdZddd	ZedddZdS )NDFrameDescriberAbstractzAbstract 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.
    r   DataFrame | Seriesr   r    r#   Nonec                 C  s   || _ || _d S Nr%   )selfr   r   r-   r-   r.   __init__t   s   
z!NDFrameDescriberAbstract.__init__r!   Sequence[float] | np.ndarrayc                 C  s   dS )zDo describe either series or dataframe.

        Parameters
        ----------
        percentiles : list-like of numbers
            The percentiles to include in the output.
        Nr-   )r4   r!   r-   r-   r.   r*   x   s    z!NDFrameDescriberAbstract.describeN)r   r1   r   r    r#   r2   )r!   r6   r#   r1   )__name__
__module____qualname____doc__r5   r   r*   r-   r-   r-   r.   r0   i   s
    

r0   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!   r6   r#   c                 C  s   t | j| j}|| j|S r3   )select_describe_funcr   r   )r4   r!   describe_funcr-   r-   r.   r*      s
   zSeriesDescriber.describeN)r!   r6   r#   r   )r7   r8   r9   r:   __annotations__r*   r-   r-   r-   r.   r(      s   
 r(   c                      s4   e Zd ZdZd fddZ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#   r2   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superr5   )r4   r   r   r   r   	__class__r-   r.   r5      s
   zDataFrameDescriber.__init__r!   r6   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)reindex.0x	col_namesr-   r.   
<listcomp>   s    z/DataFrameDescriber.describe.<locals>.<listcomp>r$   F)axissort)	_select_dataitemsr;   r   appendreorder_columnsr   r?   rE   )r4   r!   dataldesc_seriesr<   dr-   rJ   r.   r*      s   zDataFrameDescriber.describec                 C  s   | j du r)| jdu r)tjg}| jr|d | jj|d}t|j	dkr'| j}|S | j dkr>| jdur9d}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   rQ   r   select_dtypeslenr?   rA   )r4   default_includerS   msgr-   r-   r.   rO      s&   


zDataFrameDescriber._select_data)
r   r   r   r   r   r   r   r    r#   r2   )r!   r6   r#   r   )r7   r8   r9   r:   r5   r*   rO   __classcell__r-   r-   rC   r.   r)      s
    
r)   rT   Sequence[Series]list[Hashable]c                 C  sD   g }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 r3   )indexrG   r-   r-   r.   	<genexpr>   s    z"reorder_columns.<locals>.<genexpr>)key)sortedr]   rQ   )rT   namesldesc_indexesidxnamesnamer-   r-   r.   rR      s   
rR   rV   r   Sequence[float]c                 C  s   ddl m} t|}g d| dg }|  |  |  |  g| |  | 	 g }t
| r6t }nt| rDt| sDtd}nd}|||| j|dS )zDescribe 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floatNrc   rj   dtype)pandasr   r   rm   rn   ro   rp   quantiletolistrq   r   pdFloat64Dtyper   r   rZ   rt   rj   )rV   r!   r   formatted_percentiles
stat_indexrW   rt   r-   r-   r.   describe_numeric_1d   s   

r|   rS   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 )zDescribe series containing categorical data.

    Parameters
    ----------
    data : Series
        Series to be described.
    percentiles_ignored : list-like of numbers
        Ignored, but in place to unify interface.
    )rm   uniquetopfreqr   Nobjectrl   rs   )
value_countsr]   rc   ilocrZ   nanrm   ru   r   rj   )
rS   r}   rg   	objcountscount_uniquer   r   rt   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 )zDescribe 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.
    rm   r~   r   Ni8)r   r   firstlast)tzr   r   r   rl   rs   )r   r]   rm   rc   r   dtr   dropnavaluesviewr   tzinfo
tz_converttz_localizerp   rq   rZ   r   ru   r   rj   )rS   r}   rg   r   r   r,   rt   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 )zDescribe series containing datetime64 dtype.

    Parameters
    ----------
    data : Series
        Series to be described.
    percentiles : list-like of numbers
        The percentiles to include in the output.
    r   rl   )rm   rn   rp   rq   )rc   rj   )
ru   r   r   rm   rn   rp   rv   rw   rq   rj   )rS   r!   r   rz   r{   rW   r-   r-   r.   describe_timestamp_1dQ  s   r   r   c                 C  sT   t | jrtS t| rtS t| jr!|rtS tjdt	t
 d tS t| jr(tS tS )zSelect 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.
    zTreating 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.)
stacklevel)r   rt   r   r   r|   r   r   warningswarnFutureWarningr   r   r   )rS   r   r-   r-   r.   r;   i  s    


r;   %np.ndarray[Any, np.dtype[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)	rZ   arraylistr   rQ   asarrayr~   r]   rA   )r!   unique_pctsr-   r-   r.   r&     s   


r&   )r   r   r   r   r   r   r   r    r!   r"   r#   r   )rT   ra   r#   rb   )rV   r   r!   rk   r#   r   )rS   r   r}   rk   r#   r   )rS   r   r!   rk   r#   r   )rS   r   r   r    r#   r   )r!   r"   r#   r   )4r:   
__future__r   abcr   r   typingr   r   r   r   r	   r
   r   numpyrZ   pandas._libs.tslibsr   pandas._typingr   r   r   pandas.util._exceptionsr   pandas.util._validatorsr   pandas.core.dtypes.commonr   r   r   r   r   r   ru   rx   pandas.core.reshape.concatr   pandas.io.formats.formatr   r   r   r/   r0   r(   r)   rR   r|   r   r   r   r;   r&   r-   r-   r-   r.   <module>   s6      	
3
G


 
0
$