o
    5c                  	   @  s  d dl mZ d dlmZmZ d dlZd dlmZ d dl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 e	rLd d
lmZmZmZ edZedZedZedZedZ ddeeeee ddZ!edZ"edZ#dddede"e#ddZ$edZ%dKdd Z&dLd$d%Z'	dMdNd)d*Z(G d+d, d,eZ)G d-d. d.e)Z*G d/d0 d0e)Z+G d1d2 d2Z,G d3d4 d4e,Z-G d5d6 d6e,Z.G d7d8 d8eZ/G d9d: d:e/Z0G d;d< d<e0Z1G d=d> d>e/Z2G d?d@ d@e0e2Z3G dAdB dBe/Z4G dCdD dDe4Z5G dEdF dFe4e2Z6dOdIdJZ7dS )P    )annotations)ABCabstractmethodN)dedent)TYPE_CHECKINGIterableIteratorMappingSequence
get_option)DtypeWriteBuffer)format)pprint_thing)	DataFrameIndexSeriesa      max_cols : int, optional
        When to switch from the verbose to the truncated output. If the
        DataFrame has more than `max_cols` columns, the truncated output
        is used. By default, the setting in
        ``pandas.options.display.max_info_columns`` is used.aR      show_counts : bool, optional
        Whether to show the non-null counts. By default, this is shown
        only if the DataFrame is smaller than
        ``pandas.options.display.max_info_rows`` and
        ``pandas.options.display.max_info_columns``. A value of True always
        shows the counts, and False never shows the counts.zd
    null_counts : bool, optional
        .. deprecated:: 1.2.0
            Use show_counts instead.a      >>> int_values = [1, 2, 3, 4, 5]
    >>> text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon']
    >>> float_values = [0.0, 0.25, 0.5, 0.75, 1.0]
    >>> df = pd.DataFrame({"int_col": int_values, "text_col": text_values,
    ...                   "float_col": float_values})
    >>> df
        int_col text_col  float_col
    0        1    alpha       0.00
    1        2     beta       0.25
    2        3    gamma       0.50
    3        4    delta       0.75
    4        5  epsilon       1.00

    Prints information of all columns:

    >>> df.info(verbose=True)
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 5 entries, 0 to 4
    Data columns (total 3 columns):
     #   Column     Non-Null Count  Dtype
    ---  ------     --------------  -----
     0   int_col    5 non-null      int64
     1   text_col   5 non-null      object
     2   float_col  5 non-null      float64
    dtypes: float64(1), int64(1), object(1)
    memory usage: 248.0+ bytes

    Prints a summary of columns count and its dtypes but not per column
    information:

    >>> df.info(verbose=False)
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 5 entries, 0 to 4
    Columns: 3 entries, int_col to float_col
    dtypes: float64(1), int64(1), object(1)
    memory usage: 248.0+ bytes

    Pipe output of DataFrame.info to buffer instead of sys.stdout, get
    buffer content and writes to a text file:

    >>> import io
    >>> buffer = io.StringIO()
    >>> df.info(buf=buffer)
    >>> s = buffer.getvalue()
    >>> with open("df_info.txt", "w",
    ...           encoding="utf-8") as f:  # doctest: +SKIP
    ...     f.write(s)
    260

    The `memory_usage` parameter allows deep introspection mode, specially
    useful for big DataFrames and fine-tune memory optimization:

    >>> random_strings_array = np.random.choice(['a', 'b', 'c'], 10 ** 6)
    >>> df = pd.DataFrame({
    ...     'column_1': np.random.choice(['a', 'b', 'c'], 10 ** 6),
    ...     'column_2': np.random.choice(['a', 'b', 'c'], 10 ** 6),
    ...     'column_3': np.random.choice(['a', 'b', 'c'], 10 ** 6)
    ... })
    >>> df.info()
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 1000000 entries, 0 to 999999
    Data columns (total 3 columns):
     #   Column    Non-Null Count    Dtype
    ---  ------    --------------    -----
     0   column_1  1000000 non-null  object
     1   column_2  1000000 non-null  object
     2   column_3  1000000 non-null  object
    dtypes: object(3)
    memory usage: 22.9+ MB

    >>> df.info(memory_usage='deep')
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 1000000 entries, 0 to 999999
    Data columns (total 3 columns):
     #   Column    Non-Null Count    Dtype
    ---  ------    --------------    -----
     0   column_1  1000000 non-null  object
     1   column_2  1000000 non-null  object
     2   column_3  1000000 non-null  object
    dtypes: object(3)
    memory usage: 165.9 MBz    DataFrame.describe: Generate descriptive statistics of DataFrame
        columns.
    DataFrame.memory_usage: Memory usage of DataFrame columns.r   z and columns )klasstype_submax_cols_subshow_counts_subnull_counts_subexamples_subsee_also_subversion_added_suba      >>> int_values = [1, 2, 3, 4, 5]
    >>> text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon']
    >>> s = pd.Series(text_values, index=int_values)
    >>> s.info()
    <class 'pandas.core.series.Series'>
    Int64Index: 5 entries, 1 to 5
    Series name: None
    Non-Null Count  Dtype
    --------------  -----
    5 non-null      object
    dtypes: object(1)
    memory usage: 80.0+ bytes

    Prints a summary excluding information about its values:

    >>> s.info(verbose=False)
    <class 'pandas.core.series.Series'>
    Int64Index: 5 entries, 1 to 5
    dtypes: object(1)
    memory usage: 80.0+ bytes

    Pipe output of Series.info to buffer instead of sys.stdout, get
    buffer content and writes to a text file:

    >>> import io
    >>> buffer = io.StringIO()
    >>> s.info(buf=buffer)
    >>> s = buffer.getvalue()
    >>> with open("df_info.txt", "w",
    ...           encoding="utf-8") as f:  # doctest: +SKIP
    ...     f.write(s)
    260

    The `memory_usage` parameter allows deep introspection mode, specially
    useful for big Series and fine-tune memory optimization:

    >>> random_strings_array = np.random.choice(['a', 'b', 'c'], 10 ** 6)
    >>> s = pd.Series(np.random.choice(['a', 'b', 'c'], 10 ** 6))
    >>> s.info()
    <class 'pandas.core.series.Series'>
    RangeIndex: 1000000 entries, 0 to 999999
    Series name: None
    Non-Null Count    Dtype
    --------------    -----
    1000000 non-null  object
    dtypes: object(1)
    memory usage: 7.6+ MB

    >>> s.info(memory_usage='deep')
    <class 'pandas.core.series.Series'>
    RangeIndex: 1000000 entries, 0 to 999999
    Series name: None
    Non-Null Count    Dtype
    --------------    -----
    1000000 non-null  object
    dtypes: object(1)
    memory usage: 55.3 MBzp    Series.describe: Generate descriptive statistics of Series.
    Series.memory_usage: Memory usage of Series.r   z
.. versionadded:: 1.4.0
a  
    Print a concise summary of a {klass}.

    This method prints information about a {klass} including
    the index dtype{type_sub}, non-null values and memory usage.
    {version_added_sub}
    Parameters
    ----------
    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}
    memory_usage : bool, str, optional
        Specifies whether total memory usage of the {klass}
        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. See the
        :ref:`Frequently Asked Questions <df-memory-usage>` for more
        details.
    {show_counts_sub}{null_counts_sub}

    Returns
    -------
    None
        This method prints a summary of a {klass} and returns None.

    See Also
    --------
    {see_also_sub}

    Examples
    --------
    {examples_sub}
    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$   L/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/io/formats/info.py_put_str-  s   r&   num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_fmtG  s
   
r1   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   )r2   r$   r$   r%   _initialize_memory_usagef  s   r5   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.
    DataFrame | Seriesdatar4   r2   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%   dtypes      zBaseInfo.dtypesMapping[str, int]c                 C  r:   )!Mapping dtype - number of counts.Nr$   r;   r$   r$   r%   dtype_counts  r>   zBaseInfo.dtype_countsSequence[int]c                 C  r:   )BSequence of non-null counts for all columns or column (if series).Nr$   r;   r$   r$   r%   non_null_counts  r>   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$   r;   r$   r$   r%   memory_usage_bytes  r>   zBaseInfo.memory_usage_bytesr"   c                 C  s   t | j| j dS )z0Memory usage in a form of human readable string.
)r1   rE   r)   r;   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 )Nr   deepobject+)r2   rA   r8   index_is_memory_usage_qualified)r<   r)   r$   r$   r%   r)     s   

zBaseInfo.size_qualifierbufWriteBuffer[str] | Nonemax_cols
int | Noneverbosebool | Noneshow_countsNonec                C  s   d S Nr$   )r<   rN   rP   rR   rT   r$   r$   r%   render  s   	zBaseInfo.renderNr!   r9   r!   r?   r!   rB   r!   r    r!   r"   
rN   rO   rP   rQ   rR   rS   rT   rS   r!   rU   )__name__
__module____qualname____doc____annotations__propertyr   r=   rA   rD   rE   rG   r)   rW   r$   r$   r$   r%   r6   o  s,   
 

r6   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.
    Nr8   r   r2   r3   r!   rU   c                 C     || _ t|| _d S rV   r8   r5   r2   r<   r8   r2   r$   r$   r%   __init__     zDataFrameInfo.__init__r?   c                 C  
   t | jS rV   )_get_dataframe_dtype_countsr8   r;   r$   r$   r%   rA        
zDataFrameInfo.dtype_countsr9   c                 C     | j jS )z
        Dtypes.

        Returns
        -------
        dtypes
            Dtype of each of the DataFrame's columns.
        r8   r=   r;   r$   r$   r%   r=        
zDataFrameInfo.dtypesr   c                 C  rm   )zz
        Column names.

        Returns
        -------
        ids : Index
            DataFrame's column names.
        )r8   columnsr;   r$   r$   r%   ids  ro   zDataFrameInfo.idsr    c                 C  rj   z#Number of columns to be summarized.)lenrq   r;   r$   r$   r%   	col_count     
zDataFrameInfo.col_countrB   c                 C  s
   | j  S )rC   r8   countr;   r$   r$   r%   rD     ru   zDataFrameInfo.non_null_countsc                 C  s(   | j dkrd}nd}| jj d|d S )NrI   TFrL   rI   )r2   r8   sumr<   rI   r$   r$   r%   rE     s   
z DataFrameInfo.memory_usage_bytesrN   rO   rP   rQ   rR   rS   rT   c                C  s   t | |||d}|| d S )N)inforP   rR   rT   )DataFrameInfoPrinter	to_bufferr<   rN   rP   rR   rT   printerr$   r$   r%   rW     s   zDataFrameInfo.renderrV   )r8   r   r2   r3   r!   rU   rY   rX   r!   r   r[   rZ   r]   )r^   r_   r`   ra   rh   rc   rA   r=   rq   rt   rD   rE   rW   r$   r$   r$   r%   rd     s"    rd   c                   @  sl   e Zd ZdZ	d!d"d	d
Zdddd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S )(
SeriesInfoz-
    Class storing series-specific info.
    Nr8   r   r2   r3   r!   rU   c                 C  re   rV   rf   rg   r$   r$   r%   rh     ri   zSeriesInfo.__init__)rN   rP   rR   rT   rN   rO   rP   rQ   rR   rS   rT   c                C  s,   |d urt dt| ||d}|| d S )NzIArgument `max_cols` can only be passed in DataFrame.info, not Series.info)r{   rR   rT   )
ValueErrorSeriesInfoPrinterr}   r~   r$   r$   r%   rW     s   zSeriesInfo.renderrB   c                 C  s   | j  gS rV   rv   r;   r$   r$   r%   rD   /  s   zSeriesInfo.non_null_countsr9   c                 C  s
   | j jgS rV   rn   r;   r$   r$   r%   r=   3  rl   zSeriesInfo.dtypesr?   c                 C  s   ddl m} t|| jS )Nr   )r   )pandas.core.framer   rk   r8   )r<   r   r$   r$   r%   rA   7  s   zSeriesInfo.dtype_countsr    c                 C  s$   | j dkrd}nd}| jj d|dS )zMemory usage in bytes.

        Returns
        -------
        memory_usage_bytes : int
            Object's total memory usage in bytes.
        rI   TFrx   )r2   r8   rz   r$   r$   r%   rE   =  s   
	zSeriesInfo.memory_usage_bytesrV   )r8   r   r2   r3   r!   rU   r]   rZ   rX   rY   r[   )r^   r_   r`   ra   rh   rW   rc   rD   r=   rA   rE   r$   r$   r$   r%   r     s"    r   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.
    NrN   rO   r!   rU   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)r<   rN   table_builderlinesr$   r$   r%   r}   R  s
   zInfoPrinterAbstract.to_bufferTableBuilderAbstractc                 C  r:   )z!Create instance of table builder.Nr$   r;   r$   r$   r%   r   Z  r>   z)InfoPrinterAbstract._create_table_builderrV   )rN   rO   r!   rU   )r!   r   )r^   r_   r`   ra   r}   r   r   r$   r$   r$   r%   r   M  s
    r   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 )&r|   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.
    Nr{   rd   rP   rQ   rR   rS   rT   r!   rU   c                 C  s0   || _ |j| _|| _| || _| || _d S rV   )r{   r8   rR   _initialize_max_colsrP   _initialize_show_countsrT   )r<   r{   rP   rR   rT   r$   r$   r%   rh   o  s
   zDataFrameInfoPrinter.__init__r    c                 C  s   t dt| jd S )z"Maximum info rows to be displayed.zdisplay.max_info_rows   )r   rs   r8   r;   r$   r$   r%   max_rows|  rH   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   rt   rP   r;   r$   r$   r%   exceeds_info_cols     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   rs   r8   r   r;   r$   r$   r%   exceeds_info_rows  rH   z&DataFrameInfoPrinter.exceeds_info_rowsc                 C  rm   rr   r{   rt   r;   r$   r$   r%   rt        zDataFrameInfoPrinter.col_countc                 C  s   |d u rt d| jd S |S )Nzdisplay.max_info_columnsr   )r   rt   )r<   rP   r$   r$   r%   r     s   z)DataFrameInfoPrinter._initialize_max_colsc                 C  s    |d u rt | j o| j S |S rV   )r   r   r   r<   rT   r$   r$   r%   r     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.
        r{   with_countsFr{   )rR   DataFrameTableBuilderVerboser{   rT   DataFrameTableBuilderNonVerboser   r;   r$   r$   r%   r     s   
z*DataFrameInfoPrinter._create_table_builder)NNN)
r{   rd   rP   rQ   rR   rS   rT   rS   r!   rU   r[   r!   r   )rP   rQ   r!   r    rT   rS   r!   r   )r!   r   )r^   r_   r`   ra   rh   rc   r   r   r   rt   r   r   r   r$   r$   r$   r%   r|   _  s"    

r|   c                   @  s4   e Zd ZdZ		ddd
dZdddZdddZdS )r   a  Class for printing series info.

    Parameters
    ----------
    info : SeriesInfo
        Instance of SeriesInfo.
    verbose : bool, optional
        Whether to print the full summary.
    show_counts : bool, optional
        Whether to show the non-null counts.
    Nr{   r   rR   rS   rT   r!   rU   c                 C  s$   || _ |j| _|| _| || _d S rV   )r{   r8   rR   r   rT   )r<   r{   rR   rT   r$   r$   r%   rh     s   zSeriesInfoPrinter.__init__SeriesTableBuilderc                 C  s,   | j s| j du rt| j| jdS t| jdS )zF
        Create instance of table builder based on verbosity.
        Nr   r   )rR   SeriesTableBuilderVerboser{   rT   SeriesTableBuilderNonVerboser;   r$   r$   r%   r     s   z'SeriesInfoPrinter._create_table_builderr   c                 C  s   |d u rdS |S )NTr$   r   r$   r$   r%   r     s   z)SeriesInfoPrinter._initialize_show_counts)NN)r{   r   rR   rS   rT   rS   r!   rU   )r!   r   r   )r^   r_   r`   ra   rh   r   r   r$   r$   r$   r%   r     s    
r   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 )+r   z*
    Abstract builder for info table.
    	list[str]_linesr6   r{   r!   c                 C  r:   )z-Product in a form of list of lines (strings).Nr$   r;   r$   r$   r%   r     r>   zTableBuilderAbstract.get_linesr7   c                 C  rm   rV   r{   r8   r;   r$   r$   r%   r8        zTableBuilderAbstract.datar9   c                 C  rm   )z*Dtypes of each of the DataFrame's columns.)r{   r=   r;   r$   r$   r%   r=     r   zTableBuilderAbstract.dtypesr?   c                 C  rm   )r@   )r{   rA   r;   r$   r$   r%   rA     r   z!TableBuilderAbstract.dtype_countsr   c                 C  s   t | jjS )z Whether to display memory usage.)r   r{   r2   r;   r$   r$   r%   display_memory_usage  s   z)TableBuilderAbstract.display_memory_usager"   c                 C  rm   )z/Memory usage string with proper size qualifier.)r{   rG   r;   r$   r$   r%   rG     r   z(TableBuilderAbstract.memory_usage_stringrB   c                 C  rm   rV   )r{   rD   r;   r$   r$   r%   rD     r   z$TableBuilderAbstract.non_null_countsrU   c                 C  s   | j tt| j dS )z>Add line with string representation of dataframe to the table.N)r   appendr"   typer8   r;   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   r8   rL   _summaryr;   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)sortedrA   itemsr   r   join)r<   collected_dtypesr$   r$   r%   add_dtypes_line  s   z$TableBuilderAbstract.add_dtypes_lineNr!   r   )r!   r7   rX   rY   r   r\   rZ   r!   rU   )r^   r_   r`   ra   rb   r   r   rc   r8   r=   rA   r   rG   rD   r   r   r   r$   r$   r$   r%   r     s*   
 

r   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.
    r{   rd   r!   rU   c                C  
   || _ d S rV   r   r<   r{   r$   r$   r%   rh        
zDataFrameTableBuilder.__init__r   c                 C  s,   g | _ | jdkr|   | j S |   | j S )Nr   )r   rt   _fill_empty_info_fill_non_empty_infor;   r$   r$   r%   r      s   
zDataFrameTableBuilder.get_linesc                 C  s0   |    |   | jdt| jj d dS )z;Add lines to the info table, pertaining to empty dataframe.zEmpty rF   N)r   r   r   r   r   r8   r^   r;   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$   r;   r$   r$   r%   r   .  r>   z*DataFrameTableBuilder._fill_non_empty_infor   c                 C  rm   )z
DataFrame.r   r;   r$   r$   r%   r8   2  r   zDataFrameTableBuilder.datar   c                 C  rm   )zDataframe columns.)r{   rq   r;   r$   r$   r%   rq   7  r   zDataFrameTableBuilder.idsr    c                 C  rm   )z-Number of dataframe columns to be summarized.r   r;   r$   r$   r%   rt   <  r   zDataFrameTableBuilder.col_countc                 C     | j d| j  dS z!Add line containing memory usage.zmemory usage: Nr   r   rG   r;   r$   r$   r%   add_memory_usage_lineA  r   z+DataFrameTableBuilder.add_memory_usage_lineN)r{   rd   r!   rU   r   r   )r!   r   r   r[   )r^   r_   r`   ra   rh   r   r   r   r   rc   r8   rq   rt   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!   rU   c                 C  s6   |    |   |   |   | jr|   dS dS r   )r   r   add_columns_summary_liner   r   r   r;   r$   r$   r%   r   K  s   z4DataFrameTableBuilderNonVerbose._fill_non_empty_infoc                 C  s   | j | jjdd d S )NColumnsname)r   r   rq   r   r;   r$   r$   r%   r   T     z8DataFrameTableBuilderNonVerbose.add_columns_summary_lineNr   )r^   r_   r`   ra   r   r   r$   r$   r$   r%   r   F  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]]strrowsrB   gross_column_widthsr   r   r!   Sequence[str]c                 C  r:   ).Headers names of the columns in verbose table.Nr$   r;   r$   r$   r%   headersb  r>   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$   rs   r   colr$   r$   r%   r   j  s    zATableBuilderVerboseMixin.header_column_widths.<locals>.<listcomp>)r   r;   r$   r$   r%   header_column_widthsg  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   o  s    zETableBuilderVerboseMixin._get_gross_column_widths.<locals>.<listcomp>)_get_body_column_widthszipr   )r<   body_column_widthsr$   r$   r%   _get_gross_column_widthsl  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 rV   r   )r   r0   r$   r$   r%   	<genexpr>w  s    zNTableBuilderVerboseMixin._get_body_column_widths.<locals>.<listcomp>.<genexpr>r   r   r$   r$   r%   r   w  s    zDTableBuilderVerboseMixin._get_body_column_widths.<locals>.<listcomp>)listr   r   )r<   strcolsr$   r$   r%   r   t  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_countsr;   r$   r$   r%   	_gen_rowsy  s   z"TableBuilderVerboseMixin._gen_rowsc                 C  r:   z=Iterator with string representation of body data with counts.Nr$   r;   r$   r$   r%   r     r>   z.TableBuilderVerboseMixin._gen_rows_with_countsc                 C  r:   z@Iterator with string representation of body data without counts.Nr$   r;   r$   r$   r%   r     r>   z1TableBuilderVerboseMixin._gen_rows_without_countsrU   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         z<TableBuilderVerboseMixin.add_header_line.<locals>.<listcomp>)r   r   r   r   r   r   r   )r<   header_liner$   r$   r%   add_header_line  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     s    z?TableBuilderVerboseMixin.add_separator_line.<locals>.<listcomp>)r   r   r   r   r   r   r   )r<   separator_liner$   r$   r%   add_separator_line  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   )r<   row	body_liner$   r$   r%   add_body_lines  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)rD   )r<   rw   r$   r$   r%   _gen_non_null_counts  s   
z-TableBuilderVerboseMixin._gen_non_null_countsc                 c      | j D ]}t|V  qdS )z5Iterator with string representation of column dtypes.N)r=   r   )r<   dtyper$   r$   r%   _gen_dtypes     
z$TableBuilderVerboseMixin._gen_dtypesNr!   r   rZ   r!   r   r   r!   r   )r^   r_   r`   ra   r   rb   rc   r   r   r   r   r   r   r   r   r   r   r   r   r   r$   r$   r$   r%   r   X  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.
    r{   rd   r   r   r!   rU   c                C  (   || _ || _t|  | _|  | _d S rV   r{   r   r   r   r   r   r   r<   r{   r   r$   r$   r%   rh        z%DataFrameTableBuilderVerbose.__init__c                 C  N   |    |   |   |   |   |   |   | jr%|   dS dS r   )	r   r   r   r   r   r   r   r   r   r;   r$   r$   r%   r        z1DataFrameTableBuilderVerbose._fill_non_empty_infor   c                 C  s   | j rg dS g dS )r   ) # ColumnNon-Null Countr   )r  r  r   r   r;   r$   r$   r%   r     s   z$DataFrameTableBuilderVerbose.headersc                 C  s   | j d| j d d S )NzData columns (total z
 columns):)r   r   rt   r;   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   r;   r$   r$   r%   r     s   z5DataFrameTableBuilderVerbose._gen_rows_without_countsc                 c  s*    t |  |  |  |  E dH  dS r   )r   r  r  r   r   r;   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)	enumeraterq   )r<   i_r$   r$   r%   r    s   z.DataFrameTableBuilderVerbose._gen_line_numbersc                 c  r   )z4Iterator with string representation of column names.N)rq   r   )r<   r   r$   r$   r%   r    r   z)DataFrameTableBuilderVerbose._gen_columnsN)r{   rd   r   r   r!   rU   r   r   r   r   )r^   r_   r`   ra   rh   r   rc   r   r   r   r   r  r  r$   r$   r$   r%   r     s    





	r   c                   @  sJ   e Zd ZdZdddZdd	d
ZedddZdddZe	dddZ
dS )r   z
    Abstract builder for series info table.

    Parameters
    ----------
    info : SeriesInfo.
        Instance of SeriesInfo.
    r{   r   r!   rU   c                C  r   rV   r   r   r$   r$   r%   rh     r   zSeriesTableBuilder.__init__r   c                 C  s   g | _ |   | j S rV   )r   r   r;   r$   r$   r%   r     s   zSeriesTableBuilder.get_linesr   c                 C  rm   )zSeries.r   r;   r$   r$   r%   r8   	  r   zSeriesTableBuilder.datac                 C  r   r   r   r;   r$   r$   r%   r     r   z(SeriesTableBuilder.add_memory_usage_linec                 C  r:   z<Add lines to the info table, pertaining to non-empty series.Nr$   r;   r$   r$   r%   r     r>   z'SeriesTableBuilder._fill_non_empty_infoN)r{   r   r!   rU   r   )r!   r   r   )r^   r_   r`   ra   rh   r   rc   r8   r   r   r   r$   r$   r$   r%   r     s    
	

r   c                   @  s   e Zd ZdZdddZdS )r   z;
    Series info table builder for non-verbose output.
    r!   rU   c                 C  s.   |    |   |   | jr|   dS dS r  )r   r   r   r   r   r;   r$   r$   r%   r     s   z1SeriesTableBuilderNonVerbose._fill_non_empty_infoNr   )r^   r_   r`   ra   r   r$   r$   r$   r%   r     s    r   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dddZ	dddZ
dS )r   z7
    Series info table builder for verbose output.
    r{   r   r   r   r!   rU   c                C  r  rV   r  r  r$   r$   r%   rh   *  r  z"SeriesTableBuilderVerbose.__init__c                 C  r  r  )	r   r   add_series_name_liner   r   r   r   r   r   r;   r$   r$   r%   r   5  r  z.SeriesTableBuilderVerbose._fill_non_empty_infoc                 C  s   | j d| jj  d S )NzSeries name: )r   r   r8   r   r;   r$   r$   r%   r  A  r   z.SeriesTableBuilderVerbose.add_series_name_liner   c                 C  s   | j rddgS dgS )r   r	  r   r
  r;   r$   r$   r%   r   D  s   z!SeriesTableBuilderVerbose.headersr   c                 c  s    |   E dH  dS r   )r   r;   r$   r$   r%   r   K  s   z2SeriesTableBuilderVerbose._gen_rows_without_countsc                 c  s    t |  |  E dH  dS r   )r   r   r   r;   r$   r$   r%   r   O  s
   z/SeriesTableBuilderVerbose._gen_rows_with_countsN)r{   r   r   r   r!   rU   r   r   r   )r^   r_   r`   ra   rh   r   r  rc   r   r   r   r$   r$   r$   r%   r   %  s    



r   dfr?   c                 C  s   | j  dd  S )zK
    Create mapping between datatypes and their number of occurrences.
    c                 S  s   | j S rV   r   )r0   r$   r$   r%   <lambda>\  s    z-_get_dataframe_dtype_counts.<locals>.<lambda>)r=   value_countsgroupbyry   )r  r$   r$   r%   rk   W  s   rk   )r   r   r   r    r!   r"   )r'   r(   r)   r"   r!   r"   rV   )r2   r3   r!   r4   )r  r   r!   r?   )8
__future__r   abcr   r   r   textwrapr   typingr   r   r   r	   r
   pandas._configr   pandas._typingr   r   pandas.io.formatsr   r   pandas.io.formats.printingr   pandasr   r   r   frame_max_cols_subr   r   frame_examples_subframe_see_also_subframe_sub_kwargsseries_examples_subseries_see_also_subseries_sub_kwargsINFO_DOCSTRINGr&   r1   r5   r6   rd   r   r   r|   r   r   r   r   r   r   r   r   r   rk   r$   r$   r$   r%   <module>   s    

V	>
3
 	SL?Q+83]B 2