
    Owg.                       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Z' G d de      Z( G d de(      Z) G d de(      Z*ddZ+d dZ,	 	 	 	 	 	 d!dZ-	 	 	 	 	 	 d!dZ.d"dZ/	 	 	 	 d#dZ0	 	 	 	 d$dZ1y)%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Seriesc                    t        |      }| j                  dk(  rt        t        d|             }nt	        t        d|       ||      }|j                  |      }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   objr   )r   includeexclude)percentiles)_refine_percentilesndimSeriesDescriberr   DataFrameDescriberdescriber   )r   r   r   r    	describerresults         S/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/core/methods/describe.pydescribe_ndframer)   7   sm    8 &k2K xx1}#Xs#
	 '[#&
	 K8F&!!    c                  *    e Zd ZdZddZedd       Zy)NDFrameDescriberAbstractzAbstract class for describing dataframe or series.

    Parameters
    ----------
    obj : Series or DataFrame
        Object to be described.
    c                    || _         y Nr   )selfr   s     r(   __init__z!NDFrameDescriberAbstract.__init__n   s	    r*   c                     y)zDo describe either series or dataframe.

        Parameters
        ----------
        percentiles : list-like of numbers
            The percentiles to include in the output.
        N )r/   r    s     r(   r%   z!NDFrameDescriberAbstract.describeq   s    r*   N)r   DataFrame | SeriesreturnNone)r    Sequence[float] | np.ndarrayr4   r3   )__name__
__module____qualname____doc__r0   r   r%   r2   r*   r(   r,   r,   e   s       r*   r,   c                  $    e Zd ZU dZded<   ddZy)r#   z2Class responsible for creating series description.r   r   c                R    t        | j                        } || j                  |      S r.   )select_describe_funcr   )r/   r    describe_funcs      r(   r%   zSeriesDescriber.describe   s&    ,HH
 TXX{33r*   N)r    r6   r4   r   )r7   r8   r9   r:   __annotations__r%   r2   r*   r(   r#   r#   |   s    <	K4r*   r#   c                  P     e Zd ZU dZded<   	 	 	 	 	 	 	 	 d fdZddZd	dZ x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   c                   || _         || _        |j                  dk(  r$|j                  j                  dk(  rt        d      t        |   |       y )N   r   z+Cannot describe a DataFrame without columns)r   r   r"   columnssize
ValueErrorsuperr0   )r/   r   r   r   	__class__s       r(   r0   zDataFrameDescriber.__init__   sH     88q=S[[--2JKKr*   c           	     X   | j                         }g }|j                         D ](  \  }}t        |      }|j                   |||             * t	        |      }t        |D cg c]  }|j                  |d       c}dd      }	|j                  j                         |	_        |	S c c}w )NF)copyr   )axissort)	_select_dataitemsr=   appendreorder_columnsr   reindexrC   rI   )
r/   r    dataldesc_seriesr>   	col_namesxds
             r(   r%   zDataFrameDescriber.describe   s      "  	=IAv08MLLv{;<	= $E*	7<=!QYYyuY-=

 LL%%'	 >s   "B'c                   | j                   `| j                  Tt        j                  dg}| j                  j                  |      }t        |j                        dk(  r| j                  }|S | j                   dk(  r'| j                  d}t        |      | j                  }|S | j                  j                  | j                   | j                        }|S )zSelect columns to be described.datetime)r   r   allz*exclude must be None when include is 'all')r   r   )	r   r   npnumberr   select_dtypeslenrC   rE   )r/   default_includerQ   msgs       r(   rL   zDataFrameDescriber._select_data   s    LL t||';46IIz3JO88))/)BD4<< A%xx  \\U"||'B o%88D 	 88)) * D r*   )r   r   r   str | Sequence[str] | Noner   ra   r4   r5   )r    r6   r4   r   )r4   r   )	r7   r8   r9   r:   r?   r0   r%   rL   __classcell__)rG   s   @r(   r$   r$      sD    
 
N ,	
 , 
"r*   r$   c                    g }t               }t        d | D        t              }|D ]0  }|D ])  }||vs|j                  |       |j	                  |       + 2 |S )z,Set a convenient order for rows for display.c              3  4   K   | ]  }|j                     y wr.   )index).0rV   s     r(   	<genexpr>z"reorder_columns.<locals>.<genexpr>   s     3AGG3s   )key)setsortedr^   addrN   )rR   names
seen_namesldesc_indexesidxnamesnames         r(   rO   rO      se    E #J3U3=M! # 	#D:%t$T"	##
 Lr*   c                   ddl m} t        |      }g d|z   dgz   }| j                         | j	                         | j                         | j                         g| j                  |      j                         z   | j                         gz   }t        | j                  t              r_t        | j                  t              r:| j                  j                  dk(  rd}nYddl}t        |j!                               }n;t#               }n0| j                  j                  dv rt%        j                  d      }nd} |||| j&                  |	      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mNiufbfloatre   rp   dtype)pandasr   r   rs   rt   ru   rv   quantiletolistrw   
isinstancer|   r   r   kindpyarrowfloat64r   r[   rp   )rT   r    r   formatted_percentiles
stat_indexrW   r|   pas           r(   describe_numeric_1dr      s     .{;03HHE7RJ	

fjjlC
//+
&
-
-
/	0::<.	  &,,/fllJ/||  C'$"2::<0 NE			f	$!!:FKKuEEr*   c                <   g d}| j                         }t        ||dk7           }|dkD  r!|j                  d   |j                  d   }}d}n"t        j
                  t        j
                  }}d}| j                         |||g}ddlm}	  |	||| j                  |      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.
    )rs   uniquetopfreqr   Nobjectrr   r{   )
value_countsr^   re   ilocr[   nanrs   r}   r   rp   )
rQ   percentiles_ignoredrl   	objcountscount_uniquer   r   r|   r'   r   s
             r(   describe_categorical_1dr     s     /E!!#Iya01LaOOA&	q(9T FFBFFTjjlL#t4F&DIIUCCr*   c                   ddg}| j                         }t        ||dk7           }| j                         |g}d}|dkD  r|j                  d   |j                  d   }}| j
                  j                  }	| j                         j                  j                  d      }
t        |      }|j                  |	|j                  |	      }n|j                  |	      }|g dz  }|||t        |
j                         |	      t        |
j                         |	      gz  }n,|dd	gz  }|t         j"                  t         j"                  gz  }d
}ddlm}  |||| j(                  |      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.
    rs   r   r   Ni8)r   r   firstlast)tzr   r   r   rr   r{   )r   r^   rs   re   r   dtr   dropnavaluesviewr	   tzinfo
tz_converttz_localizerv   rw   r[   r   r}   r   rp   )rQ   r   rl   r   r   r'   r|   r   r   r   asintr   s               r(   $describe_timestamp_as_categorical_1dr   "  sG    hE!!#Iya01L'+zz|\&BFEaOOA&	q(9TWWZZ$$))$/n::!bn..$C//"%C11eiikb)eiikb)	
 	
 	% 266266""&DIIUCCr*   c                &   ddl m} t        |      }g d|z   dgz   }| j                         | j	                         | j                         g| j                  |      j                         z   | j                         gz   } |||| j                        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   rr   )rs   rt   rv   rw   )re   rp   )
r}   r   r   rs   rt   rv   r~   r   rw   rp   )rQ   r    r   r   r   rW   s         r(   describe_timestamp_1dr   R  s     .{;),AAUGKJ	tyy{DHHJ/
--
$
+
+
-	.88:,	 
 !:DII66r*   c                   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.
    Mrx   )	r   r|   r   r   r   r   r   r   r   )rQ   s    r(   r=   r=   j  sc     TZZ &&	$	""	C	:djj/#J$$	C	""&&r*   c                .   | t        j                  g d      S t        |       } t        |        d| vr| j	                  d       t        j
                  |       } t        j                  |       }| J t        |      t        |       k  rt        d      |S )z
    Ensure that percentiles are unique and sorted.

    Parameters
    ----------
    percentiles : list-like of numbers, optional
        The percentiles to include in the output.
    )g      ?      ?g      ?r   z%percentiles cannot contain duplicates)	r[   arraylistr   rN   asarrayr   r^   rE   )r    unique_pctss     r(   r!   r!     s     xx)** {#K $ +3**[)K ))K(K"""
;#k**@AAr*   )
r   r   r   ra   r   ra   r    #Sequence[float] | np.ndarray | Noner4   r   )rR   zSequence[Series]r4   zlist[Hashable])rT   r   r    Sequence[float]r4   r   )rQ   r   r   r   r4   r   )rQ   r   r    r   r4   r   )rQ   r   r4   r   )r    r   r4   znpt.NDArray[np.float64])2r:   
__future__r   abcr   r   typingr   r   r   numpyr[   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   r}   r   r   r)   r,   r#   r$   rO   r   r   r   r   r=   r!   r2   r*   r(   <module>r      s>  
 #   ) 
 8  5 - 7
+"	+" (+" (	+"
 5+" +"\s .	4. 	4A1 AH
&FRD
D(D D@-D
-D(-D -D`70'
'', 4  r*   