3
®yb­,  ã               @   sâ   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rˆd d	lmZ e
eef eed
œdd„Ze
eef eedœdd„ZG dd„ ded�ZG dd„ deƒZdS )é    )ÚABCMetaÚabstractmethodN)ÚIOÚTYPE_CHECKINGÚListÚOptionalÚTupleÚUnion)Ú
get_option)ÚDtypeÚFrameOrSeries)ÚIndex)Úformat)Úpprint_thing)ÚSeries)ÚsÚspaceÚreturnc             C   s   t | ƒd|… j|ƒ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)ÚstrÚljust)r   r   © r   ú:/tmp/pip-install-4cy230dp/pandas/pandas/io/formats/info.pyÚ_put_str   s    r   )ÚnumÚsize_qualifierr   c             C   sB   x0d
D ](}| dk r&| d›|› d|› �S | d } qW | 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 PB)r   r   r   r   r   r   )r   r   Úxr   r   r   Ú_sizeof_fmt,   s
    
r"   c            	   @   s¶   e Zd Zdeee eee  ee ee	eef  ee dœdd„Z
eeedœdd„ƒZeed d
œdd„ƒZeee dd	eddœdd„ƒZeee dddœdd„ƒZdd
œdd„ZdS )ÚBaseInfoN)ÚdataÚverboseÚbufÚmax_colsÚmemory_usageÚnull_countsc             C   sF   |d krt j}|d krtdƒ}|| _|| _|| _|| _|| _|| _d S )Nzdisplay.memory_usage)	ÚsysÚstdoutr
   r$   r%   r&   r'   r(   r)   )Úselfr$   r%   r&   r'   r(   r)   r   r   r   Ú__init__L   s    	zBaseInfo.__init__)Údeepr   c             C   s   dS )a…  
        Get memory usage in bytes.

        Parameters
        ----------
        deep : bool
            If True, introspect the data deeply by interrogating object dtypes
            for system-level memory consumption, and include it in the returned
            values.

        Returns
        -------
        mem_usage : int
            Object's total memory usage in bytes.
        Nr   )r,   r.   r   r   r   Ú_get_mem_usagea   s    zBaseInfo._get_mem_usager   r   )r   c             C   s   dS )z×
        Get column names and dtypes.

        Returns
        -------
        ids : Index
            DataFrame's column names.
        dtypes : Series
            Dtype of each of the DataFrame's columns.
        Nr   )r,   r   r   r   Ú_get_ids_and_dtypest   s    zBaseInfo._get_ids_and_dtypes)ÚlinesÚidsÚdtypesÚshow_countsr   c             C   s   dS )aÑ  
        Append name, non-null count (optional), and dtype for each column to `lines`.

        Parameters
        ----------
        lines : List[str]
            Lines that will contain `info` representation.
        ids : Index
            The DataFrame's column names.
        dtypes : Series
            The DataFrame's columns' dtypes.
        show_counts : bool
            If True, count of non-NA cells for each column will be appended to `lines`.
        Nr   )r,   r1   r2   r3   r4   r   r   r   Ú_verbose_repr‚   s    zBaseInfo._verbose_repr)r1   r2   r   c             C   s   dS )zþ
        Append short summary of columns' names to `lines`.

        Parameters
        ----------
        lines : List[str]
            Lines that will contain `info` representation.
        ids : Index
            The DataFrame's column names.
        Nr   )r,   r1   r2   r   r   r   Ú_non_verbose_repr–   s    zBaseInfo._non_verbose_reprc             C   sÜ  g }|j tt| jƒƒƒ |j | jjjƒ ƒ | jƒ \}}t|ƒ}|dkrp|j dt| jƒj› �ƒ t	j
| j|ƒ dS | j}|dkrŒtd|d ƒ}tdt| jƒd ƒ}| jdkrÂ||ko¾t| jƒ|k }n| j}||k}| jrè| j||||ƒ n>| jdk�r| j||ƒ n$|�r| j||ƒ n| j||||ƒ |jƒ jdd	„ ƒjƒ }	d
d„ t|	jƒ ƒD ƒ}
|j ddj|
ƒ› �ƒ | j�rÊd}| jdk�r†d}n d}d|	k�s¢| jjjƒ �r¦d}| j|d�}|j dt||ƒ› d�ƒ t	j
| j|ƒ dS )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.

        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.
        null_counts : bool, optional
            Whether to show the non-null counts. By default, this is shown
            only if the %(klass)s 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.

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

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

        Examples
        --------
        %(examples_sub)s
        r   zEmpty Nzdisplay.max_info_columnsé   zdisplay.max_info_rowsFc             S   s   | j S )N)Úname)r!   r   r   r   Ú<lambda>ý   s    zBaseInfo.info.<locals>.<lambda>c             S   s&   g | ]}|d  › d|d d›d�‘qS )r   ú(r7   Údú)r   )Ú.0Úkr   r   r   ú
<listcomp>þ   s    z!BaseInfo.info.<locals>.<listcomp>zdtypes: z, Ú r.   TÚobjectú+)r.   zmemory usage: Ú
)Úappendr   Útyper$   ÚindexÚ_summaryr0   ÚlenÚ__name__ÚfmtZbuffer_put_linesr&   r'   r
   r)   r%   r5   r6   Zvalue_countsÚgroupbyÚsumÚsortedÚitemsÚjoinr(   Z_is_memory_usage_qualifiedr/   r"   )r,   r1   r2   r3   Ú	col_countr'   Zmax_rowsr4   Zexceeds_info_colsÚcountsZcollected_dtypesr   r.   Z	mem_usager   r   r   Úinfo¤   sJ    4
zBaseInfo.info)NNNNN)r   r   )rI   Ú
__module__Ú__qualname__r   r   Úboolr   r   Úintr	   r-   r   r/   r   r0   r   r5   r6   rR   r   r   r   r   r#   K   s       :r#   )Ú	metaclassc               @   s^   e Zd Zeedœdd„Zed dœdd„Zee	 dded	d
œdd„Z
ee	 dd	dœdd„Zd	S )ÚDataFrameInfo)r.   r   c             C   s   | j jd|d�jƒ S )NT)rF   r.   )r$   r(   rL   )r,   r.   r   r   r   r/     s    zDataFrameInfo._get_mem_usager   r   )r   c             C   s   | j j| j jfS )N)r$   Úcolumnsr3   )r,   r   r   r   r0     s    z!DataFrameInfo._get_ids_and_dtypesN)r1   r2   r3   r4   r   c              C   s"  t |ƒ}|jd|› d�ƒ d}d}d}tdd„ |D ƒƒ}	t t|ƒƒ}
t|	|
ƒ| }t t|ƒƒ}t t|ƒƒ}t||ƒ| }t||ƒt||ƒ }|�r| jjƒ }|t |ƒkrÂtd|› d	t |ƒ› d
�ƒ‚d}t |ƒ}d}tdd„ |D ƒƒt |ƒ }t||ƒ| }d| }nd}t |ƒ}|}d}d}t |ƒ}tdd„ |D ƒƒ}t||ƒ}|t||ƒt||ƒ 7 }|j|ƒ |jtd| |ƒtd|
 |ƒ td| |ƒ td| |ƒ ƒ x|t|ƒD ]p\}}|j	| }t|ƒ}td|› �|ƒ}d}|�rè|j	| }|j|t||ƒ t|j
|d�|ƒ t||ƒ ƒ �qªW d S )NzData columns (total z
 columns):z # ZColumné   c             s   s   | ]}t t|ƒƒV  qd S )N)rH   r   )r=   r>   r   r   r   ú	<genexpr>#  s    z.DataFrameInfo._verbose_repr.<locals>.<genexpr>zColumns must equal counts (z != r<   zNon-Null Countz	 non-nullc             s   s   | ]}t t|ƒƒV  qd S )N)rH   r   )r=   r>   r   r   r   r[   5  s    z{count}r@   r   c             s   s   | ]}t t|ƒƒV  qd S )N)rH   r   )r=   r>   r   r   r   r[   @  s    ú-r    )Úcount)rH   rD   Úmaxr   r   r$   r]   ÚAssertionErrorÚ	enumerateZilocr   ) r,   r1   r2   r3   r4   rP   Zid_headZcolumn_headZ	col_spaceZmax_colZ
len_columnr   Zmax_idZlen_idZ	space_numÚheaderrQ   Zcount_headerZ	len_countZnon_nullÚ	max_countZspace_countZ
count_tempZdtype_headerZ	len_dtypeZ
max_dtypesZspace_dtypeÚiÚcolZdtypeZline_nor]   r   r   r   r5     sZ    



:

zDataFrameInfo._verbose_repr)r1   r2   r   c             C   s   |j |jdd�ƒ d S )NZColumns)r8   )rD   rG   )r,   r1   r2   r   r   r   r6   ^  s    zDataFrameInfo._non_verbose_repr)r   r   )rI   rS   rT   rU   rV   r/   r   r0   r   r   r5   r6   r   r   r   r   rX     s
   CrX   ) Úabcr   r   r*   Útypingr   r   r   r   r   r	   Zpandas._configr
   Zpandas._typingr   r   Zpandas.core.indexes.apir   Zpandas.io.formatsr   rJ   Zpandas.io.formats.printingr   Zpandas.core.seriesr   r   rV   r   Úfloatr"   r#   rX   r   r   r   r   Ú<module>   s     H