o
    $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   Z	describerresult r(   ]/var/www/html/Deteccion_Ine/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 )NDFrameDescriberAbstractzAbstract 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 )zDo 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)r   r,   r   r-   )r   r1   r   r,   )__name__
__module____qualname____doc__r0   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   r1   r   c                 C  s   t | j}|| j|S r.   )select_describe_funcr   )r/   r   describe_funcr(   r(   r)   r&      s   zSeriesDescriber.describeN)r   r1   r   r   )r2   r3   r4   r5   __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superr0   )r/   r   r   r   	__class__r(   r)   r0      s
   zDataFrameDescriber.__init__r   r1   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>   s    z/DataFrameDescriber.describe.<locals>.<listcomp>r    F)Zaxissort)_select_dataitemsr6   appendreorder_columnsr   r:   r@   )r/   r   dataldesc_seriesr7   dr(   rD   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   Zselect_dtypeslenr:   r<   )r/   Zdefault_includerK   msgr(   r(   r)   rG      s"   


zDataFrameDescriber._select_data)r   r   r   r   r   r   r   r-   )r   r1   r   r   )r   r   )	r2   r3   r4   r5   r8   r0   r&   rG   __classcell__r(   r(   r>   r)   r%      s   
 
r%   rL   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.   )indexrA   r(   r(   r)   	<genexpr>   s    z"reorder_columns.<locals>.<genexpr>)key)setsortedrT   addrI   )rL   namesZ
seen_namesZldesc_indexesZidxnamesnamer(   r(   r)   rJ      s   

rJ   rN   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 )
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mNZiufbfloatrY   r`   dtype)pandasr   r   rc   rd   re   rf   quantiletolistrg   
isinstancerk   r   r   kindZpyarrowZfloat64r   rR   r`   )rN   r   r   formatted_percentiles
stat_indexrO   rk   par(   r(   r)   describe_numeric_1d   s(   
rt   rK   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.
    )rc   uniquetopfreqr   Nobjectrb   rj   )
value_countsrT   rY   ilocrR   nanrc   rl   r   r`   )
rK   ru   r_   	objcountscount_uniquerw   rx   rk   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.
    rc   rv   r   Ni8)rw   rx   firstlast)tzrw   rx   ry   rb   rj   )rz   rT   rc   rY   r{   dtr   Zdropnavaluesviewr   tzinfoZ
tz_convertZtz_localizerf   rg   rR   r|   rl   r   r`   )rK   ru   r_   r}   r~   r'   rk   rw   rx   r   Z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   rb   )rc   rd   rf   rg   )rY   r`   )
rl   r   r   rc   rd   rf   rm   rn   rg   r`   )rK   r   r   rq   rr   rO   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 )zSelect proper function for describing series based on data type.

    Parameters
    ----------
    data : Series
        Series to be described.
    Mrh   )	r   rk   r   r   rt   rp   ro   r   r   )rK   r(   r(   r)   r6   j  s   

r6   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)	rR   arraylistr   rI   Zasarrayrv   rT   r<   )r   Zunique_pctsr(   r(   r)   r"     s   


r"   )
r   r
   r   r   r   r   r   r   r   r
   )rL   rW   r   rX   )rN   r   r   ra   r   r   )rK   r   ru   ra   r   r   )rK   r   r   ra   r   r   )rK   r   r   r   )r   r   r   r   )2r5   
__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   rl   r   r   r*   r+   r$   r%   rJ   rt   r   r   r   r6   r"   r(   r(   r(   r)   <module>   s6    
.
D

)
 
0
