o
    gRP                     @  sT  d dl mZ d dlmZmZ d dlZd dlmZmZm	Z	m
Z
mZmZ d dlmZ d dl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 d4ddZd5ddZ	d6d7ddZG dd deZG dd  d eZG d!d" d"Z G d#d$ d$e Z!G d%d& d&eZ"G d'd( d(e"Z#G d)d* d*e#Z$G d+d, d,e"Z%G d-d. d.e#e%Z&d8d2d3Z'dS )9    )annotations)ABCabstractmethodN)IOTYPE_CHECKINGIterableIteratorMappingSequence
get_option)DtypeFrameOrSeriesUnion)Index)format)pprint_thing)	DataFramesstr | Dtypespaceintreturnstrc                 C  s   t | d| |S )a  
    Make string of specified length, padding to the right if necessary.

    Parameters
    ----------
    s : Union[str, Dtype]
        String to be formatted.
    space : int
        Length to force string to be of.

    Returns
    -------
    str
        String coerced to given length.

    Examples
    --------
    >>> pd.io.formats.info._put_str("panda", 6)
    'panda '
    >>> pd.io.formats.info._put_str("panda", 4)
    'pand'
    N)r   ljust)r   r    r   T/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pandas/io/formats/info.py_put_str!   s   r   numint | floatsize_qualifierc                 C  sB   dD ]}| dk r| d| d|   S | d } q| d| dS )a{  
    Return size in human readable format.

    Parameters
    ----------
    num : int
        Size in bytes.
    size_qualifier : str
        Either empty, or '+' (if lower bound).

    Returns
    -------
    str
        Size in human readable format.

    Examples
    --------
    >>> _sizeof_fmt(23028, '')
    '22.5 KB'

    >>> _sizeof_fmt(23028, '+')
    '22.5+ KB'
    )bytesKBMBGBTBg      @z3.1f z PBr   )r   r   xr   r   r   _sizeof_fmt;   s
   
r'   memory_usagebool | str | None
bool | strc                 C  s   | du rt d} | S )z5Get memory usage based on inputs and display options.Nzdisplay.memory_usager   )r(   r   r   r   _initialize_memory_usageZ   s   r+   c                   @  s   e Zd ZU dZded< ded< eed#dd	Zeed$ddZeed%ddZ	eed&ddZ
ed'ddZed'ddZed(d d!Zd"S ))BaseInfoaj  
    Base class for DataFrameInfo and SeriesInfo.

    Parameters
    ----------
    data : DataFrame or Series
        Either dataframe or series.
    memory_usage : bool or str, optional
        If "deep", introspect the data deeply by interrogating object dtypes
        for system-level memory consumption, and include it in the returned
        values.
    r   datar*   r(   r   Iterable[Dtype]c                 C     dS )z
        Dtypes.

        Returns
        -------
        dtypes : sequence
            Dtype of each of the DataFrame's columns (or one series column).
        Nr   selfr   r   r   dtypest       zBaseInfo.dtypesMapping[str, int]c                 C  r/   )!Mapping dtype - number of counts.Nr   r0   r   r   r   dtype_counts   r3   zBaseInfo.dtype_countsSequence[int]c                 C  r/   )BSequence of non-null counts for all columns or column (if series).Nr   r0   r   r   r   non_null_counts   r3   zBaseInfo.non_null_countsr   c                 C  r/   )z
        Memory usage in bytes.

        Returns
        -------
        memory_usage_bytes : int
            Object's total memory usage in bytes.
        Nr   r0   r   r   r   memory_usage_bytes   r3   zBaseInfo.memory_usage_bytesr   c                 C  s   t | j| j dS )z0Memory usage in a form of human readable string.
)r'   r:   r   r0   r   r   r   memory_usage_string      zBaseInfo.memory_usage_stringc                 C  s2   d}| j r| j dkrd| jv s| jj rd}|S )N deepobject+)r(   r6   r-   index_is_memory_usage_qualified)r1   r   r   r   r   r      s   


zBaseInfo.size_qualifierbufIO[str] | Nonemax_cols
int | Noneverbosebool | Noneshow_countsNonec                C  r/   )a^  
        Print a concise summary of a %(klass)s.

        This method prints information about a %(klass)s including
        the index dtype%(type_sub)s, non-null values and memory usage.
        %(version_added_sub)s
        Parameters
        ----------
        data : %(klass)s
            %(klass)s to print information about.
        verbose : bool, optional
            Whether to print the full summary. By default, the setting in
            ``pandas.options.display.max_info_columns`` is followed.
        buf : writable buffer, defaults to sys.stdout
            Where to send the output. By default, the output is printed to
            sys.stdout. Pass a writable buffer if you need to further process
            the output.
        %(max_cols_sub)s
        memory_usage : bool, str, optional
            Specifies whether total memory usage of the %(klass)s
            elements (including the index) should be displayed. By default,
            this follows the ``pandas.options.display.memory_usage`` setting.

            True always show memory usage. False never shows memory usage.
            A value of 'deep' is equivalent to "True with deep introspection".
            Memory usage is shown in human-readable units (base-2
            representation). Without deep introspection a memory estimation is
            made based in column dtype and number of rows assuming values
            consume the same memory amount for corresponding dtypes. With deep
            memory introspection, a real memory usage calculation is performed
            at the cost of computational resources.
        %(show_counts_sub)s

        Returns
        -------
        None
            This method prints a summary of a %(klass)s and returns None.

        See Also
        --------
        %(see_also_sub)s

        Examples
        --------
        %(examples_sub)s
        Nr   )r1   rD   rF   rH   rJ   r   r   r   render   r3   zBaseInfo.renderNr   r.   r   r4   r   r7   r   r   r   r   
rD   rE   rF   rG   rH   rI   rJ   rI   r   rK   )__name__
__module____qualname____doc____annotations__propertyr   r2   r6   r9   r:   r<   r   rL   r   r   r   r   r,   c   s,   
 

r,   c                   @  s|   e Zd ZdZ	d%d&ddZed'ddZed(ddZed)ddZed*ddZ	ed+ddZ
ed*ddZd,d#d$ZdS )-DataFrameInfoz0
    Class storing dataframe-specific info.
    Nr-   r   r(   r)   c                 C  s   || _ t|| _d S N)r-   r+   r(   )r1   r-   r(   r   r   r   __init__   s   zDataFrameInfo.__init__r   r4   c                 C  
   t | jS rZ   )_get_dataframe_dtype_countsr-   r0   r   r   r   r6      s   
zDataFrameInfo.dtype_countsr.   c                 C     | j jS )z
        Dtypes.

        Returns
        -------
        dtypes
            Dtype of each of the DataFrame's columns.
        )r-   r2   r0   r   r   r   r2         
zDataFrameInfo.dtypesr   c                 C  r^   )zz
        Column names.

        Returns
        -------
        ids : Index
            DataFrame's column names.
        )r-   columnsr0   r   r   r   ids  r_   zDataFrameInfo.idsr   c                 C  r\   z#Number of columns to be summarized.)lenra   r0   r   r   r   	col_count     
zDataFrameInfo.col_countr7   c                 C  s
   | j  S )r8   )r-   countr0   r   r   r   r9     re   zDataFrameInfo.non_null_countsc                 C  s(   | j dkrd}nd}| jj d|d S )Nr?   TF)rB   r?   )r(   r-   sum)r1   r?   r   r   r   r:     s   
z DataFrameInfo.memory_usage_bytesrD   rE   rF   rG   rH   rI   rJ   rK   c                C  s   t | |||d}|| d S )N)inforF   rH   rJ   )DataFrameInfoPrinter	to_buffer)r1   rD   rF   rH   rJ   printerr   r   r   rL     s   zDataFrameInfo.renderrZ   )r-   r   r(   r)   rN   rM   r   r   rP   rO   rR   )rS   rT   rU   rV   r[   rX   r6   r2   ra   rd   r9   r:   rL   r   r   r   r   rY      s"    rY   c                   @  s*   e Zd ZdZddddZedd
dZdS )InfoPrinterAbstractz6
    Class for printing dataframe or series info.
    NrD   rE   r   rK   c                 C  s.   |   }| }|du rtj}t|| dS )z Save dataframe info into buffer.N)_create_table_builder	get_linessysstdoutfmtbuffer_put_lines)r1   rD   table_builderlinesr   r   r   rj   5  s
   zInfoPrinterAbstract.to_bufferTableBuilderAbstractc                 C  r/   )z!Create instance of table builder.Nr   r0   r   r   r   rn   =  r3   z)InfoPrinterAbstract._create_table_builderrZ   )rD   rE   r   rK   )r   rv   )rS   rT   rU   rV   rj   r   rn   r   r   r   r   rm   0  s
    rm   c                   @  sx   e Zd ZdZ			ddd
dZed ddZed!ddZed!ddZed ddZ	d"ddZ
d#ddZd$ddZdS )%ri   a{  
    Class for printing dataframe info.

    Parameters
    ----------
    info : DataFrameInfo
        Instance of DataFrameInfo.
    max_cols : int, optional
        When to switch from the verbose to the truncated output.
    verbose : bool, optional
        Whether to print the full summary.
    show_counts : bool, optional
        Whether to show the non-null counts.
    Nrh   rY   rF   rG   rH   rI   rJ   c                 C  s0   || _ |j| _|| _| || _| || _d S rZ   )rh   r-   rH   _initialize_max_colsrF   _initialize_show_countsrJ   )r1   rh   rF   rH   rJ   r   r   r   r[   R  s
   zDataFrameInfoPrinter.__init__r   r   c                 C  s   t dt| jd S )z"Maximum info rows to be displayed.zdisplay.max_info_rows   )r   rc   r-   r0   r   r   r   max_rows_  r=   zDataFrameInfoPrinter.max_rowsboolc                 C  s   t | j| jkS )zDCheck if number of columns to be summarized does not exceed maximum.)r{   rd   rF   r0   r   r   r   exceeds_info_colsd     z&DataFrameInfoPrinter.exceeds_info_colsc                 C  s   t t| j| jkS )zACheck if number of rows to be summarized does not exceed maximum.)r{   rc   r-   rz   r0   r   r   r   exceeds_info_rowsi  r=   z&DataFrameInfoPrinter.exceeds_info_rowsc                 C  r^   rb   rh   rd   r0   r   r   r   rd   n     zDataFrameInfoPrinter.col_countc                 C  s   |d u rt d| jd S |S )Nzdisplay.max_info_columnsry   )r   rd   )r1   rF   r   r   r   rw   s  s   z)DataFrameInfoPrinter._initialize_max_colsc                 C  s    |d u rt | j o| j S |S rZ   )r{   r|   r~   )r1   rJ   r   r   r   rx   x  s   z,DataFrameInfoPrinter._initialize_show_countsDataFrameTableBuilderc                 C  sN   | j rt| j| jdS | j du rt| jdS | jrt| jdS t| j| jdS )z[
        Create instance of table builder based on verbosity and display settings.
        )rh   with_countsFrh   )rH   DataFrameTableBuilderVerboserh   rJ   DataFrameTableBuilderNonVerboser|   r0   r   r   r   rn   ~  s   
z*DataFrameInfoPrinter._create_table_builder)NNN)rh   rY   rF   rG   rH   rI   rJ   rI   rP   r   r{   )rF   rG   r   r   )rJ   rI   r   r{   )r   r   )rS   rT   rU   rV   r[   rX   rz   r|   r~   rd   rw   rx   rn   r   r   r   r   ri   B  s"    

ri   c                   @  s   e Zd ZU dZded< ded< ed#ddZed$d
dZed%ddZ	ed&ddZ
ed'ddZed(ddZed)ddZd*ddZd*ddZd*d d!Zd"S )+rv   z*
    Abstract builder for info table.
    	list[str]_linesr,   rh   r   c                 C  r/   )z-Product in a form of list of lines (strings).Nr   r0   r   r   r   ro     r3   zTableBuilderAbstract.get_linesr   c                 C  r^   rZ   rh   r-   r0   r   r   r   r-        zTableBuilderAbstract.datar.   c                 C  r^   )z*Dtypes of each of the DataFrame's columns.)rh   r2   r0   r   r   r   r2     r   zTableBuilderAbstract.dtypesr4   c                 C  r^   )r5   )rh   r6   r0   r   r   r   r6     r   z!TableBuilderAbstract.dtype_countsr{   c                 C  s   t | jjS )z Whether to display memory usage.)r{   rh   r(   r0   r   r   r   display_memory_usage  s   z)TableBuilderAbstract.display_memory_usager   c                 C  r^   )z/Memory usage string with proper size qualifier.)rh   r<   r0   r   r   r   r<     r   z(TableBuilderAbstract.memory_usage_stringr7   c                 C  r^   rZ   )rh   r9   r0   r   r   r   r9     r   z$TableBuilderAbstract.non_null_countsrK   c                 C  s   | j tt| j dS )z>Add line with string representation of dataframe to the table.N)r   appendr   typer-   r0   r   r   r   add_object_type_line  s   z)TableBuilderAbstract.add_object_type_linec                 C  s   | j | jj  dS )z,Add line with range of indices to the table.N)r   r   r-   rB   _summaryr0   r   r   r   add_index_range_line     z)TableBuilderAbstract.add_index_range_linec                 C  s4   dd t | j D }| jdd|  dS )z2Add summary line with dtypes present in dataframe.c                 S  s"   g | ]\}}| d |ddqS )(d)r   ).0keyvalr   r   r   
<listcomp>  s    z8TableBuilderAbstract.add_dtypes_line.<locals>.<listcomp>zdtypes: z, N)sortedr6   itemsr   r   join)r1   collected_dtypesr   r   r   add_dtypes_line  s   z$TableBuilderAbstract.add_dtypes_lineNr   r   )r   r   rM   rN   r   rQ   rO   r   rK   )rS   rT   rU   rV   rW   r   ro   rX   r-   r2   r6   r   r<   r9   r   r   r   r   r   r   r   rv     s*   
 

rv   c                   @  sp   e Zd ZdZdddZddd	ZdddZedddZe	dddZ
e	dddZe	d ddZdddZdS )!r   z
    Abstract builder for dataframe info table.

    Parameters
    ----------
    info : DataFrameInfo.
        Instance of DataFrameInfo.
    rh   rY   c                C  s
   || _ d S rZ   r   )r1   rh   r   r   r   r[     s   
zDataFrameTableBuilder.__init__r   r   c                 C  s,   g | _ | jdkr|   | j S |   | j S )Nr   )r   rd   _fill_empty_info_fill_non_empty_infor0   r   r   r   ro     s   
zDataFrameTableBuilder.get_linesrK   c                 C  s.   |    |   | jdt| jj  dS )z;Add lines to the info table, pertaining to empty dataframe.zEmpty N)r   r   r   r   r   r-   rS   r0   r   r   r   r     s   z&DataFrameTableBuilder._fill_empty_infoc                 C  r/   z?Add lines to the info table, pertaining to non-empty dataframe.Nr   r0   r   r   r   r     r3   z*DataFrameTableBuilder._fill_non_empty_infor   c                 C  r^   )z
DataFrame.r   r0   r   r   r   r-     r   zDataFrameTableBuilder.datar   c                 C  r^   )zDataframe columns.)rh   ra   r0   r   r   r   ra     r   zDataFrameTableBuilder.idsr   c                 C  r^   )z-Number of dataframe columns to be summarized.r   r0   r   r   r   rd     r   zDataFrameTableBuilder.col_countc                 C  s   | j d| j  dS )z!Add line containing memory usage.zmemory usage: N)r   r   r<   r0   r   r   r   add_memory_usage_line  r   z+DataFrameTableBuilder.add_memory_usage_lineN)rh   rY   r   r   )r   r   rl   rP   )rS   rT   rU   rV   r[   ro   r   r   r   rX   r-   ra   rd   r   r   r   r   r   r     s    
	

r   c                   @  s$   e Zd ZdZd	ddZd	ddZdS )
r   z>
    Dataframe info table builder for non-verbose output.
    r   rK   c                 C  s6   |    |   |   |   | jr|   dS dS r   )r   r   add_columns_summary_liner   r   r   r0   r   r   r   r     s   z4DataFrameTableBuilderNonVerbose._fill_non_empty_infoc                 C  s   | j | jjdd d S )NColumnsname)r   r   ra   r   r0   r   r   r   r        z8DataFrameTableBuilderNonVerbose.add_columns_summary_lineNr   )rS   rT   rU   rV   r   r   r   r   r   r   r     s    
	r   c                   @  s   e Zd ZU dZdZded< ded< ded< d	ed
< eed)ddZed*ddZ	d*ddZ
d*ddZd+ddZed+ddZed+ddZd,ddZd,dd Zd,d!d"Zd-d$d%Zd-d&d'Zd(S ).TableBuilderVerboseMixinz(
    Mixin for verbose info output.
    z  r   SPACINGzSequence[Sequence[str]]strrowsr7   gross_column_widthsr{   r   r   Sequence[str]c                 C  r/   ).Headers names of the columns in verbose table.Nr   r0   r   r   r   headers  r3   z TableBuilderVerboseMixin.headersc                 C  s   dd | j D S )z'Widths of header columns (only titles).c                 S  s   g | ]}t |qS r   rc   r   colr   r   r   r   "  s    zATableBuilderVerboseMixin.header_column_widths.<locals>.<listcomp>)r   r0   r   r   r   header_column_widths  r}   z-TableBuilderVerboseMixin.header_column_widthsc                 C  s   |   }dd t| j|D S )zAGet widths of columns containing both headers and actual content.c                 S  s   g | ]}t | qS r   max)r   widthsr   r   r   r   '  s    zETableBuilderVerboseMixin._get_gross_column_widths.<locals>.<listcomp>)_get_body_column_widthszipr   )r1   body_column_widthsr   r   r   _get_gross_column_widths$  s   
z1TableBuilderVerboseMixin._get_gross_column_widthsc                 C  s   t t| j }dd |D S )z$Get widths of table content columns.c                 S  s   g | ]}t d d |D qS )c                 s  s    | ]}t |V  qd S rZ   r   )r   r&   r   r   r   	<genexpr>/  s    zNTableBuilderVerboseMixin._get_body_column_widths.<locals>.<listcomp>.<genexpr>r   r   r   r   r   r   /  s    zDTableBuilderVerboseMixin._get_body_column_widths.<locals>.<listcomp>)listr   r   )r1   strcolsr   r   r   r   ,  s   z0TableBuilderVerboseMixin._get_body_column_widthsIterator[Sequence[str]]c                 C  s   | j r|  S |  S )z
        Generator function yielding rows content.

        Each element represents a row comprising a sequence of strings.
        )r   _gen_rows_with_counts_gen_rows_without_countsr0   r   r   r   	_gen_rows1  s   z"TableBuilderVerboseMixin._gen_rowsc                 C  r/   z=Iterator with string representation of body data with counts.Nr   r0   r   r   r   r   <  r3   z.TableBuilderVerboseMixin._gen_rows_with_countsc                 C  r/   z@Iterator with string representation of body data without counts.Nr   r0   r   r   r   r   @  r3   z1TableBuilderVerboseMixin._gen_rows_without_countsrK   c                 C  0   | j dd t| j| jD }| j| d S )Nc                 S     g | ]	\}}t ||qS r   r   )r   header	col_widthr   r   r   r   F      z<TableBuilderVerboseMixin.add_header_line.<locals>.<listcomp>)r   r   r   r   r   r   r   )r1   header_liner   r   r   add_header_lineD  s   z(TableBuilderVerboseMixin.add_header_linec                 C  r   )Nc                 S  s   g | ]\}}t d | |qS )-r   )r   header_colwidthgross_colwidthr   r   r   r   O  s    z?TableBuilderVerboseMixin.add_separator_line.<locals>.<listcomp>)r   r   r   r   r   r   r   )r1   separator_liner   r   r   add_separator_lineM  s   z+TableBuilderVerboseMixin.add_separator_linec                 C  s:   | j D ]}| jdd t|| jD }| j| qd S )Nc                 S  r   r   r   )r   r   r   r   r   r   r   [  r   z;TableBuilderVerboseMixin.add_body_lines.<locals>.<listcomp>)r   r   r   r   r   r   r   )r1   row	body_liner   r   r   add_body_linesX  s   

z'TableBuilderVerboseMixin.add_body_linesIterator[str]c                 c  s    | j D ]}| dV  qdS )z7Iterator with string representation of non-null counts.z	 non-nullN)r9   )r1   rf   r   r   r   _gen_non_null_countsb  s   
z-TableBuilderVerboseMixin._gen_non_null_countsc                 c      | j D ]}t|V  qdS )z5Iterator with string representation of column dtypes.N)r2   r   )r1   dtyper   r   r   _gen_dtypesg     
z$TableBuilderVerboseMixin._gen_dtypesNr   r   rO   r   r   r   r   r   )rS   rT   rU   rV   r   rW   rX   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s.   
 




	


r   c                   @  sd   e Zd ZdZdddZdd
dZedddZdddZdddZ	dddZ
d ddZd ddZdS )!r   z:
    Dataframe info table builder for verbose output.
    rh   rY   r   r{   c                C  s(   || _ || _t|  | _|  | _d S rZ   )rh   r   r   r   r   r   r   )r1   rh   r   r   r   r   r[   r  s   z%DataFrameTableBuilderVerbose.__init__r   rK   c                 C  sN   |    |   |   |   |   |   |   | jr%|   dS dS r   )	r   r   r   r   r   r   r   r   r   r0   r   r   r   r   }  s   z1DataFrameTableBuilderVerbose._fill_non_empty_infor   c                 C  s   | j rg dS g dS )r   ) # ColumnzNon-Null Countr   )r   r   r   )r   r0   r   r   r   r     s   z$DataFrameTableBuilderVerbose.headersc                 C  s   | j d| j d d S )NzData columns (total z
 columns):)r   r   rd   r0   r   r   r   r     r   z5DataFrameTableBuilderVerbose.add_columns_summary_liner   c                 c  s$    t |  |  |  E dH  dS r   )r   _gen_line_numbers_gen_columnsr   r0   r   r   r   r     s   z5DataFrameTableBuilderVerbose._gen_rows_without_countsc                 c  s*    t |  |  |  |  E dH  dS r   )r   r   r   r   r   r0   r   r   r   r     s   z2DataFrameTableBuilderVerbose._gen_rows_with_countsr   c                 c  s&    t | jD ]
\}}d| V  qdS )z6Iterator with string representation of column numbers.r%   N)	enumeratera   )r1   i_r   r   r   r     s   z.DataFrameTableBuilderVerbose._gen_line_numbersc                 c  r   )z4Iterator with string representation of column names.N)ra   r   )r1   r   r   r   r   r     r   z)DataFrameTableBuilderVerbose._gen_columnsN)rh   rY   r   r{   r   r   r   r   )rS   rT   rU   rV   r[   r   rX   r   r   r   r   r   r   r   r   r   r   r   m  s    





	r   dfr   r4   c                 C  s   | j  dd  S )zK
    Create mapping between datatypes and their number of occurrences.
    c                 S  s   | j S rZ   r   )r&   r   r   r   <lambda>  s    z-_get_dataframe_dtype_counts.<locals>.<lambda>)r2   value_countsgroupbyrg   )r   r   r   r   r]     s   r]   )r   r   r   r   r   r   )r   r   r   r   r   r   rZ   )r(   r)   r   r*   )r   r   r   r4   )(
__future__r   abcr   r   rp   typingr   r   r   r   r	   r
   pandas._configr   pandas._typingr   r   pandas.core.indexes.apir   pandas.io.formatsr   rr   pandas.io.formats.printingr   pandas.core.framer   r   r'   r+   r,   rY   rm   ri   rv   r   r   r   r   r]   r   r   r   r   <module>   s4     	

 	 LQ83]B