
    Eg.                    n   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& d0dZ' G d de          Z( G d de(          Z) G d de(          Z*d1d"Z+d2d&Z,d3d)Z-d3d*Z.d4d+Z/d5d-Z0d6d/Z1dS )7z
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                
   t          |          }| j        dk    rt          t          d|                     }n t	          t          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results         Q/var/www/sysmax/venv/lib/python3.11/site-packages/pandas/core/methods/describe.pydescribe_ndframer,   7   s    8 &k22K x1}}#Xs##
 
 
		 '[#&&
 
 
	 K88F&!!!    c                  2    e Zd ZdZddZe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                    || _         d S Nr#   )selfr   s     r+   __init__z!NDFrameDescriberAbstract.__init__n   s    r-   r   Sequence[float] | np.ndarrayc                    dS )zDo describe either series or dataframe.

        Parameters
        ----------
        percentiles : list-like of numbers
            The percentiles to include in the output.
        N )r4   r   s     r+   r(   z!NDFrameDescriberAbstract.describeq   s      r-   N)r   r0   r    r1   )r   r6   r    r0   )__name__
__module____qualname____doc__r5   r   r(   r8   r-   r+   r/   r/   e   sR                ^  r-   r/   c                  &    e Zd ZU dZded<   d	dZdS )
r&   z2Class responsible for creating series description.r   r   r   r6   r    c                L    t          | j                  } || j        |          S r3   )select_describe_funcr   )r4   r   describe_funcs      r+   r(   zSeriesDescriber.describe   s,    ,H
 
 }TX{333r-   N)r   r6   r    r   )r9   r:   r;   r<   __annotations__r(   r8   r-   r+   r&   r&   |   s9         <<KKK4 4 4 4 4 4r-   r&   c                  @     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   r   r   r   r    r1   c                   || _         || _        |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superr5   )r4   r   r   r   	__class__s       r+   r5   zDataFrameDescriber.__init__   sZ     8q==S[-22JKKKr-   r   r6   c                Z   |                                  }g }|                                D ]3\  }}t          |          }|                     |||                     4t	          |          t          fd|D             dd          }|j                                        |_        |S )Nc                >    g | ]}|                     d           S )F)copy)reindex).0x	col_namess     r+   
<listcomp>z/DataFrameDescriber.describe.<locals>.<listcomp>   s)    ===!QYYyuY--===r-   r"   F)axissort)_select_dataitemsr?   appendreorder_columnsr   rE   rL   )	r4   r   dataldesc_seriesr@   drP   s	           @r+   r(   zDataFrameDescriber.describe   s      ""  	= 	=IAv088MLLv{;;<<<<#E**	====u===
 
 

 L%%''	r-   c                V   | j         P| j        It          j        dg}| j                            |          }t          |j                  dk    r| j        }nQ| j         dk    r | j        d}t          |          | j        }n&| j                            | j         | j                  }|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lenrE   rG   )r4   default_includerX   msgs       r+   rT   zDataFrameDescriber._select_data   s    L t|';46Iz3JO8))/)BBD4<  A%%x\U""|'B oo%8DD8)) *  D r-   )r   r   r   r   r   r   r    r1   )r   r6   r    r   )r    r   )	r9   r:   r;   r<   rA   r5   r(   rT   __classcell__)rI   s   @r+   r'   r'      s|         
 
 NNN        "       r-   r'   rY   Sequence[Series]list[Hashable]c                    g }t                      }t          d | D             t                    }|D ]5}|D ]0}||vr*|                    |           |                    |           16|S )z,Set a convenient order for rows for display.c              3  $   K   | ]}|j         V  d S r3   )index)rN   rO   s     r+   	<genexpr>z"reorder_columns.<locals>.<genexpr>   s$      33AG333333r-   )key)setsortedrc   addrV   )rY   names
seen_namesldesc_indexesidxnamesnames         r+   rW   rW      s    E #J33U333===M! # # 	# 	#D:%%t$$$T"""	# Lr-   r[   r   Sequence[float]c                   ddl m} t          |          }g d|z   dgz   }|                                 |                                 |                                 |                                 g|                     |                                          z   | 	                                gz   }t          | j        t                    rbt          | j        t                    r9| j        j        dk    rd}nZddl}t          |                                          }n4t#                      }n%| 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rk   ru   dtype)pandasr   r   ry   rz   r{   r|   quantiletolistr}   
isinstancer   r   r   kindpyarrowfloat64r   r`   ru   )r[   r   r   formatted_percentiles
stat_indexr\   r   pas           r+   describe_numeric_1dr      sO    .{;;0003HHE7RJ	

fjjllC
//+
&
&
-
-
/
/	0::<<.	  &,// flJ// 		#| C''$$$$"2::<<00 NNEE		f	$	$!!6!:FKuEEEEr-   rX   percentiles_ignoredc                B   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	        |          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.
    )ry   uniquetopfreqr   Nobjectrx   r   )
value_countsrc   rk   ilocr`   nanry   r   r   ru   )
rX   r   rq   	objcountscount_uniquer   r   r   r*   r   s
             r+   describe_categorical_1dr     s     /..E!!##Iya011LaOA&	q(9T FBFTjjllL#t4F6&DIUCCCCr-   c                   ddg}|                                  }t          ||dk                       }|                                 |g}d}|dk    r|j        d         |j        d         }}| j        j        }	|                                 j        	                    d          }
t          |          }|j        |	|                    |	          }n|                    |	          }|g dz  }|||t          |
                                |	          t          |
                                |	          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.
    ry   r   r   Ni8)r   r   firstlast)tzr   r   r   rx   r   )r   rc   ry   rk   r   dtr   dropnavaluesviewr	   tzinfo
tz_converttz_localizer|   r}   r`   r   r   r   ru   )rX   r   rq   r   r   r*   r   r   r   r   asintr   s               r+   $describe_timestamp_as_categorical_1dr   "  s}    hE!!##Iya011L'+zz||\&BFEaOA&	q(9TWZ$))$//nn:!bn..$$CC//"%%C1111eiikkb)))eiikkb)))	
 	
 	% 2626""6&DIUCCCCr-   c                Z   ddl m} t          |          }g d|z   dgz   }|                                 |                                 |                                 g|                     |                                          z   |                                 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   rx   )ry   rz   r|   r}   )rk   ru   )
r   r   r   ry   rz   r|   r   r   r}   ru   )rX   r   r   r   r   r\   s         r+   describe_timestamp_1dr   R  s     .{;;))),AAUGKJ	tyy{{DHHJJ/
--
$
$
+
+
-
-	.88::,	 
 6!:DI6666r-   r   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.
    Mr~   )	r   r   r   r   r   r   r   r   r   )rX   s    r+   r?   r?   j  ss     TZ   	'&&	$		 '""	C		:dj/#J#J	$$	C		""&&r-   npt.NDArray[np.float64]c                Z   | t          j        g d          S t          |           } t          |            d| vr|                     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.
    N)g      ?      ?g      ?r   z%percentiles cannot contain duplicates)	r`   arraylistr   rV   asarrayr   rc   rG   )r   unique_pctss     r+   r$   r$     s     x)))*** {##K $$$ +3*[))K )K((K"""
;#k****@AAAr-   )
r   r   r   r   r   r   r   r   r    r   )rY   rg   r    rh   )r[   r   r   rv   r    r   )rX   r   r   rv   r    r   )rX   r   r   rv   r    r   )rX   r   r    r   )r   r   r    r   )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'   rW   r   r   r   r   r?   r$   r8   r-   r+   <module>r      s   
 # " " " " "                     ) ) ) ) ) )         
 8 7 7 7 7 7                 5 4 4 4 4 4 - - - - - - 7 7 7 7 7 7 	       
       +" +" +" +"\    s   .	4 	4 	4 	4 	4. 	4 	4 	4A A A A A1 A A AH
 
 
 
&F &F &F &FRD D D D@-D -D -D -D`7 7 7 70' ' ' ',           r-   