o
    ŀgO                    @  s  U d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	l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ZddlmZm Z  ddl!m"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-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZA dd	lBmC  mDZE ddlFmGZGmHZHmIZImJZJ ddlKmLZL ddlMmNZN ddlOmPZP ddlQmRZRmSZS ddlTmUZU erddlVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZb ddlcmdZdmeZe dZfd egd!< d"Zhd#Zid egd$< G d%d& d&Zjdd)d*Zkdd+d,ZlG d-d. d.ZmG d/d0 d0Zn				ddd7d8Zoe			ddd:d;Zp			<					=	>	?				dddRdSZqG dTdU dUZrG dVdW dWerZsG dXdY dYerZtG dZd[ d[erZuG d\d] d]erZvdd`daZwddddeZxdddjdkZy	f		dddmdnZz		dddrdsZ{G dtdu dueuZ|G dvdw dwerZ}	f	xddd|d}Z~	=				ddddZddddZdddZ	>ddddZdddZG dd dZddddZ	ddddZdddZd	S )z
Internal module for formatting output data in csv, html, xml,
and latex files. This module also applies to display formatting.
    )annotations)	GeneratorHashableMappingSequence)contextmanager)
QUOTE_NONE)Decimal)partial)StringION)get_terminal_size)TYPE_CHECKINGAnyCallableFinalcast)
get_option
set_option)lib)NA)NaT	Timedelta	Timestamp)NaTType)is_complex_dtypeis_float
is_integeris_list_likeis_numeric_dtype	is_scalar)CategoricalDtypeDatetimeTZDtypeExtensionDtype)isnanotna)CategoricalDatetimeArrayExtensionArrayTimedeltaArray)StringDtype)PandasObject)Index
MultiIndexPeriodIndexensure_index)DatetimeIndex)TimedeltaIndex)concat)check_parent_directorystringify_path)printing)	ArrayLikeAxesColspaceArgTypeColspaceTypeCompressionOptionsFilePathFloatFormatTypeFormattersType
IndexLabelSequenceNotStrStorageOptionsWriteBuffer)	DataFrameSeriesa	  
        Parameters
        ----------
        buf : str, Path or StringIO-like, optional, default None
            Buffer to write to. If None, the output is returned as a string.
        columns : array-like, optional, default None
            The subset of columns to write. Writes all columns by default.
        col_space : %(col_space_type)s, optional
            %(col_space)s.
        header : %(header_type)s, optional
            %(header)s.
        index : bool, optional, default True
            Whether to print index (row) labels.
        na_rep : str, optional, default 'NaN'
            String representation of ``NaN`` to use.
        formatters : list, tuple or dict of one-param. functions, optional
            Formatter functions to apply to columns' elements by position or
            name.
            The result of each function must be a unicode string.
            List/tuple must be of length equal to the number of columns.
        float_format : one-parameter function, optional, default None
            Formatter function to apply to columns' elements if they are
            floats. This function must return a unicode string and will be
            applied only to the non-``NaN`` elements, with ``NaN`` being
            handled by ``na_rep``.
        sparsify : bool, optional, default True
            Set to False for a DataFrame with a hierarchical index to print
            every multiindex key at each row.
        index_names : bool, optional, default True
            Prints the names of the indexes.
        justify : str, default None
            How to justify the column labels. If None uses the option from
            the print configuration (controlled by set_option), 'right' out
            of the box. Valid values are

            * left
            * right
            * center
            * justify
            * justify-all
            * start
            * end
            * inherit
            * match-parent
            * initial
            * unset.
        max_rows : int, optional
            Maximum number of rows to display in the console.
        max_cols : int, optional
            Maximum number of columns to display in the console.
        show_dimensions : bool, default False
            Display DataFrame dimensions (number of rows by number of columns).
        decimal : str, default '.'
            Character recognized as decimal separator, e.g. ',' in Europe.
    r   common_docstring)leftrightcenterjustifyzjustify-allstartendinheritzmatch-parentinitialunsetz
        Returns
        -------
        str or None
            If buf is None, returns the result as a string. Otherwise returns
            None.
    return_docstringc                
   @  sX   e Zd ZdZdddddddddd	d$ddZd%ddZd&ddZd'd d!Zd&d"d#ZdS )(SeriesFormatterz\
    Implement the main logic of Series.to_string, which underlies
    Series.__repr__.
    TNaNFN)	lengthheaderindexna_repnamefloat_formatdtypemax_rowsmin_rowsseriesrB   rP   
bool | strrQ   boolrR   rS   strrT   rU   
str | NonerV   rW   
int | NonerX   returnNonec       	         C  sj   || _ t | _|| _|| _|| _|| _|| _|	| _|
| _	|d u r$t
d}|| _|| _t | _|   d S )Ndisplay.float_format)rY   r   bufrT   rS   rQ   rP   rR   rW   rX   r   rU   rV   r4   get_adjustmentadj_chk_truncate)selfrY   rP   rQ   rR   rS   rT   rU   rV   rW   rX    rg   L/var/www/html/myenv/lib/python3.10/site-packages/pandas/io/formats/format.py__init__   s   
zSeriesFormatter.__init__c                 C  s   |  | j }| j}|ot| j|k}| j}|rItt|}|r"t||}|dkr0|}|jd | }n|d }t|jd | |j| d  f}|| _	nd | _	|| _
|| _d S )N      )rX   rW   lenrY   r   intminilocr1   
tr_row_num	tr_seriesis_truncated_vertically)rf   rX   rW   rr   rY   row_numrg   rg   rh   re      s$   

"
zSeriesFormatter._chk_truncatec                 C  s0  | j j}d}| j j}t|tttfr|jd ur|d|j 7 }| jdur<|d ur<|r.|d7 }t	j
|dd}|d| 7 }| jdu sI| jd	krY| jrY|rO|d7 }|d
t| j  7 }| jdur}| jd ur}t| jjdd }|r}|rs|d7 }|dt	
| 7 }t| jjtr| jj }|r|d7 }||7 }t|S )N zFreq: Fz, 	
)escape_charszName: TtruncatezLength: rT   zdtype: rx   )rY   rT   rR   
isinstancer/   r-   r0   freqfreqstrr4   pprint_thingrP   rr   rl   rV   getattrrq   r    _values_get_repr_footerr\   )rf   rT   footerrR   series_name
dtype_name
level_inforg   rg   rh   _get_footer   s:   

zSeriesFormatter._get_footer	list[str]c                 C  s   t | jjd | j| j| jdS )N)rU   rS   leading_space)format_arrayrq   r   rU   rS   rR   rf   rg   rg   rh   _get_formatted_values(  s   z%SeriesFormatter._get_formatted_valuesc                 C  st  | j }|  }t|dkrt| jj d| dS |j}t|}t|t	r=|j
dd d}t }|jdg|R  d}n|jdd}|  }| jrd}| j}	tt|	}	| j||	d	  }
|
d
kred}nd}| jj|g|
ddd }||	| | ||	d	 d | jr| jjd
g|d	d  |gR  }n| jd
|}| jr|r|d d | }|r|d| 7 }td|S )Nr   z([], )T)include_namessparsifyrk   rx   include_namerj      ...z..rF   modert   )rq   r   rl   typerY   __name__rR   
_has_namesr{   r,   _format_multir4   rc   adjoinsplit_format_flatr   rr   rp   r   rm   rd   rG   insertrQ   r\   join)rf   rY   r   rR   have_header	fmt_indexrd   
fmt_valuesn_header_rowsrs   widthdot_strresultrg   rg   rh   	to_string1  s>   

"
zSeriesFormatter.to_string)rY   rB   rP   rZ   rQ   r[   rR   r[   rS   r\   rT   r[   rU   r]   rV   r[   rW   r^   rX   r^   r_   r`   r_   r`   r_   r\   r_   r   )	r   
__module____qualname____doc__ri   re   r   r   r   rg   rg   rg   rh   rN      s     	
 

*	rN   r_   dict[str, Any]c                  C  sL   ddl m}  tdr|  \}}nd}tdtdtdtdtd	|d
S )a  Get the parameters used to repr(dataFrame) calls using DataFrame.to_string.

    Supplying these parameters to DataFrame.to_string is equivalent to calling
    ``repr(DataFrame)``. This is useful if you want to adjust the repr output.

    .. versionadded:: 1.4.0

    Example
    -------
    >>> import pandas as pd
    >>>
    >>> df = pd.DataFrame([[1, 2], [3, 4]])
    >>> repr_params = pd.io.formats.format.get_dataframe_repr_params()
    >>> repr(df) == df.to_string(**repr_params)
    True
    r   )consolezdisplay.expand_frame_reprNdisplay.max_rowsdisplay.min_rowszdisplay.max_columnsdisplay.max_colwidthdisplay.show_dimensions)rW   rX   max_colsmax_colwidthshow_dimensions
line_width)pandas.io.formatsr   r   get_console_size)r   r   _rg   rg   rh   get_dataframe_repr_params_  s   r   c                  C  sJ   t  \} }td}|dkr|n|}|dkr|ntd}dd||tddS )a  Get the parameters used to repr(Series) calls using Series.to_string.

    Supplying these parameters to Series.to_string is equivalent to calling
    ``repr(series)``. This is useful if you want to adjust the series repr output.

    .. versionadded:: 1.4.0

    Example
    -------
    >>> import pandas as pd
    >>>
    >>> ser = pd.Series([1, 2, 3, 4])
    >>> repr_params = pd.io.formats.format.get_series_repr_params()
    >>> repr(ser) == ser.to_string(**repr_params)
    True
    r   r   r   Tr   )rT   rV   rX   rW   rP   )r   r   )r   heightmax_rows_optrW   rX   rg   rg   rh   get_series_repr_params  s   
r   c                   @  s  e Zd ZdZer
endZeee 7 Z																	dtdud(d)Zdvd+d,Zedwd-d.Z	edwd/d0Z
edwd1d2Zedwd3d4Zedxd5d6Zedwd7d8Zedwd9d:Zedwd;d<Zedwd=d>Zedyd@dAZdzdBdCZd{dEdFZd|dGdHZd}dJdKZd~dMdNZddOdPZddQdRZddSdTZdwdUdVZdwdWdXZdwdYdZZdyd[d\Zdd]d^Zdd_d`Z ddadbZ!dvdcddZ"ddgdhZ#ddkdlZ$ddmdnZ%ddodpZ&ddrdsZ'dS )DataFrameFormatterz
    Class for processing dataframe formatting options and data.

    Used by DataFrame.to_string, which backs DataFrame.__repr__.
    rt   NTrO   F.framerA   columnsAxes | None	col_spaceColspaceArgType | NonerQ   bool | SequenceNotStr[str]rR   r[   rS   r\   
formattersFormattersType | NonerG   r]   rU   FloatFormatType | Noner   bool | Noneindex_namesrW   r^   rX   r   r   rZ   decimal	bold_rowsescaper_   r`   c                 C  s   || _ | || _| || _|| _|| _|| _| || _	| 
|| _|	| _| |
| _|| _|| _|| _|| _|| _|| _|| _|| _|  | _|  | _| j | _|   t | _d S N) r   _initialize_columnsr   _initialize_colspacer   rQ   rR   rS   _initialize_formattersr   _initialize_justifyrG   rU   _initialize_sparsifyr   show_index_namesr   r   r   rW   rX   r   r   _calc_max_cols_fittedmax_cols_fitted_calc_max_rows_fittedmax_rows_fittedtr_framerz   r4   rc   rd   )rf   r   r   r   rQ   rR   rS   r   rG   rU   r   r   rW   rX   r   r   r   r   r   rg   rg   rh   ri     s.   

zDataFrameFormatter.__init__list[list[str]]c                 C  s*   |   }| jr| | j}|d| |S )zP
        Render a DataFrame to a list of columns (as lists of strings).
        r   )_get_strcols_without_indexrR   _get_formatted_indexr   r   )rf   strcols	str_indexrg   rg   rh   get_strcols  s
   zDataFrameFormatter.get_strcolsc                 C  s   | j du p| j dko| jS )NTrz   )r   is_truncatedr   rg   rg   rh   should_show_dimensions  s   
z)DataFrameFormatter.should_show_dimensionsc                 C  s   t | jp| jS r   )r[   is_truncated_horizontallyrr   r   rg   rg   rh   r     s   zDataFrameFormatter.is_truncatedc                 C     t | jot| j| jkS r   )r[   r   rl   r   r   rg   rg   rh   r        z,DataFrameFormatter.is_truncated_horizontallyc                 C  r   r   )r[   r   rl   r   r   rg   rg   rh   rr     r   z*DataFrameFormatter.is_truncated_verticallyc                 C  s    dt | j dt | jj dS )Nz

[z rows x z	 columns])rl   r   r   r   rg   rg   rh   dimensions_info  s    z"DataFrameFormatter.dimensions_infoc                 C     t | jjS r   )r   r   rR   r   rg   rg   rh   has_index_names     z"DataFrameFormatter.has_index_namesc                 C  r   r   )r   r   r   r   rg   rg   rh   has_column_names  r   z#DataFrameFormatter.has_column_namesc                 C     t | j| j| jfS r   )allr   rR   r   r   rg   rg   rh   show_row_idx_names     z%DataFrameFormatter.show_row_idx_namesc                 C  r   r   )r   r   r   rQ   r   rg   rg   rh   show_col_idx_names  r   z%DataFrameFormatter.show_col_idx_namesrm   c                 C  s   t | jpt| jt| jS r   )rn   rW   rl   r   r   rg   rg   rh   max_rows_displayed
  s   z%DataFrameFormatter.max_rows_displayedc                 C     |d u rt dS |S )Nzdisplay.multi_sparser   )rf   r   rg   rg   rh   r     s   z'DataFrameFormatter._initialize_sparsifyr<   c                 C  sP   |d u ri S t | jjt |kst|tr|S tdt | dt | jj d)NzFormatters length(+) should match DataFrame number of columns(r   )rl   r   r   r{   dict
ValueError)rf   r   rg   rg   rh   r     s   
z)DataFrameFormatter._initialize_formattersc                 C  r   )Nzdisplay.colheader_justifyr   )rf   rG   rg   rg   rh   r      s   z&DataFrameFormatter._initialize_justifyr+   c                 C  s(   |d urt |}| j| | _|S | jjS r   )r.   r   r   )rf   r   colsrg   rg   rh   r   &  s
   z&DataFrameFormatter._initialize_columnsr8   c                   s    d u ri }|S t  ttfr#d i}| fdd| jjD  |S t  trD  D ]}|| jjvr?|dkr?td| q, }|S t	| jjt	 kr_tdt	  dt	| jj dt
t| jj }|S )Nrt   c                   s   i | ]}| qS rg   rg   ).0columnr   rg   rh   
<dictcomp>5      z;DataFrameFormatter._initialize_colspace.<locals>.<dictcomp>z,Col_space is defined for an unknown column: zCol_space length(r   r   )r{   rm   r\   updater   r   r   keysr   rl   r   zip)rf   r   r   r   rg   r   rh   r   .  s0   

z'DataFrameFormatter._initialize_colspacec                 C  s,   |   s| jS t \}}| |r|S | jS )z%Number of columns fitting the screen.)_is_in_terminalr   r   _is_screen_narrow)rf   r   r   rg   rg   rh   r   F  s   

z(DataFrameFormatter._calc_max_cols_fittedc                 C  sP   |   r t \}}| jdkr||   S | |r|}n| j}n| j}| |S )z,Number of rows with data fitting the screen.r   )r   r   rW   _get_number_of_auxiliary_rows_is_screen_short_adjust_max_rows)rf   r   r   rW   rg   rg   rh   r   Q  s   



z(DataFrameFormatter._calc_max_rows_fittedc                 C  s(   |rt | j|kr| jrt| j|}|S )zAdjust max_rows using display logic.

        See description here:
        https://pandas.pydata.org/docs/dev/user_guide/options.html#frequently-used-options

        GH #37359
        )rl   r   rX   rn   )rf   rW   rg   rg   rh   r  d  s   z#DataFrameFormatter._adjust_max_rowsc                 C  s   t | jdkp
| jdkS )z/Check if the output is to be shown in terminal.r   )r[   r   rW   r   rg   rg   rh   r   r  s   z"DataFrameFormatter._is_in_terminalc                 C  s   t | jdkot| jj|kS Nr   )r[   r   rl   r   r   )rf   	max_widthrg   rg   rh   r   v  s   z$DataFrameFormatter._is_screen_narrowc                 C  s   t | jdkot| j|kS r  )r[   rW   rl   r   )rf   
max_heightrg   rg   rh   r   y  s   z#DataFrameFormatter._is_screen_shortc                 C  s:   d}d}|| }| j r|t| j 7 }| jr|d7 }|S )z?Get number of rows occupied by prompt, dots and dimension info.rj   )r   rl   r   
splitlinesrQ   )rf   dot_row
prompt_rownum_rowsrg   rg   rh   r   |  s   z0DataFrameFormatter._get_number_of_auxiliary_rowsc                 C  s$   | j r|   | jr|   dS dS )zY
        Check whether the frame should be truncated. If so, slice the frame up.
        N)r   _truncate_horizontallyrr   _truncate_verticallyr   rg   rg   rh   rz     s
   zDataFrameFormatter.truncatec                 C  s   | j dusJ | j d }|dkrM| jjddd|f }| jjdd| df }t||fdd| _t| jttfrLg | jd| | j| d | _ntt	| j
}| jjddd|f | _|| _dS )zRemove columns, which are not to be displayed and adjust formatters.

        Attributes affected:
            - tr_frame
            - formatters
            - tr_col_num
        Nrk   rj   axis)r   r   ro   r1   r{   r   listtupler   rm   r   
tr_col_num)rf   col_numrD   rE   rg   rg   rh   r	    s    

z)DataFrameFormatter._truncate_horizontallyc                 C  s   | j dusJ | j d }|dkr-t| j}tt|t|| |g}| jj| | _ntt| j	}| jjd|ddf | _|| _
dS )zRemove rows, which are not to be displayed.

        Attributes affected:
            - tr_frame
            - tr_row_num
        Nrk   rj   )r   rl   r   nphstackarangero   r   rm   rW   rp   )rf   rs   _len_slicerg   rg   rh   r
    s   

 
z'DataFrameFormatter._truncate_verticallyc           
   	     s  g }t  js1 js1t jD ]\}} |}t| jt j	|d j
d}|| q|S t  jrcttt  j _t jt jkrZtdt j dt j ddd  jD }n  j} jrv|D ]}|d qnt jD ]N\}}|| }tt j	|dg fd	d
|D R  } |}t| j| j
d}tg  fdd
|D |R  }	 j
j||	 jd}|||  q{|S )Nr   )stringsrG   minimumrd   zWriting z cols but got z aliasesc                 S  s   g | ]}|gqS rg   rg   )r   labelrg   rg   rh   
<listcomp>  r   zADataFrameFormatter._get_strcols_without_index.<locals>.<listcomp>rt   c                 3      | ]	} j |V  qd S r   rd   rl   r   xr   rg   rh   	<genexpr>      z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>)r  rd   c                 3  r  r   r  r  r   rg   rh   r    r  r   )r   rQ   	enumerater   
format_col_make_fixed_widthrG   rm   r   getrd   appendr   r  r\   rl   r   r   _get_formatted_column_labelsr   max)
rf   r   icr   str_columnsr  cheaderheader_colwidthmax_lenrg   r   rh   r     sP   


 z-DataFrameFormatter._get_strcols_without_indexr'  r   c              	   C  sL   | j }| |}t|jd d |f j|| j| j| j|j	| | j
| jdS )N)rU   rS   spacer   r   )r   _get_formatterr   ro   r   rU   rS   r   r#  r   r   rR   )rf   r'  r   	formatterrg   rg   rh   r!    s   
zDataFrameFormatter.format_col	str | intCallable | Nonec                 C  sZ   t | jttfrt|rtt|}| j| S d S t|r&|| jvr&| j| }| j|d S r   )	r{   r   r  r  r   r   rm   r   r#  )rf   r'  rg   rg   rh   r.    s   


z!DataFrameFormatter._get_formatterc                   s  ddl m} |j}t|tr_|jddd}tt| }jj	j
}tdd |jD tt|tt|  fddttfd	d|D  }jrTt|rT||}d
d t| D }|S |jdd}jj	}tt|tt|  fddt|D }|S )Nr   )sparsify_labelsF)r   r   c                 s  s    | ]}|j V  qd S r   )is_floating)r   levelrg   rg   rh   r    s    zBDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>c                   s"   |j vr |  rsd| S |S )N )r   )r  y)need_leadsprestrict_formattingrf   rg   rh   space_format  s   
zEDataFrameFormatter._get_formatted_column_labels.<locals>.space_formatc                 3  s$    | ]  fd d D V  qdS )c                   s   g | ]} |qS rg   rg   )r   r6  )r9  r  rg   rh   r         zMDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>.<listcomp>Nrg   )r   )r9  r  rh   r     s   " c                 S     g | ]}t |qS rg   )r  r  rg   rg   rh   r  %      zCDataFrameFormatter._get_formatted_column_labels.<locals>.<listcomp>r   c                   s0   g | ]\}} |s | rd | n|gqS )r5  )r.  )r   r'  r  )r7  rf   rg   rh   r  *  s    )pandas.core.indexes.multir2  r   r{   r,   r   r  r   r   dtypesr   anylevelsr   mapr   r   rl   r   r   )rf   r   r2  r   fmt_columnsr?  str_columns_tupler)  rg   )r7  r8  rf   r9  rh   r%    s.   

	
z/DataFrameFormatter._get_formatted_column_labelsc                   s   dd j  D  |j}|j}d}t|tr%|jjj	|d}n	|j
j	|dg} fdd|D }jjdg|R  d	}jrRd
d  D }ndg|j }jr_|| S |S )Nc                 S  s   i | ]
\}}|t t|qS rg   )r   rm   )r   kvrg   rg   rh   r   4  s    z;DataFrameFormatter._get_formatted_index.<locals>.<dictcomp>	__index__)r   r   r/  )r   r/  c              
     s.   g | ]}t tt|d  ddjdqS )rD   rt   r   )rG   r  rd   )r  r"  r  r#  rd   r  r   rf   rg   rh   r  D  s    z;DataFrameFormatter._get_formatted_index.<locals>.<listcomp>rj   rx   c                 S  r<  rg   r\   r  rg   rg   rh   r  Q  r=  rt   )r   itemsrR   r   r.  r{   r,   r   r   r   r   rd   r   r   r   _get_column_name_listnlevelsrQ   )rf   r   rR   r   fmtr   adjoined
col_headerrg   rH  rh   r   1  s,   

	z'DataFrameFormatter._get_formatted_indexlist[Hashable]c                 C  sN   g }| j j}t|tr|dd |jD  |S ||jd u r!dn|j |S )Nc                 s  s     | ]}|d u r
dn|V  qd S )Nrt   rg   )r   rT   rg   rg   rh   r  ^  s    z;DataFrameFormatter._get_column_name_list.<locals>.<genexpr>rt   )r   r   r{   r,   extendnamesr$  rT   )rf   rR  r   rg   rg   rh   rK  Z  s   
z(DataFrameFormatter._get_column_name_list)NNTTrO   NNNNTNNNFr   FT)&r   rA   r   r   r   r   rQ   r   rR   r[   rS   r\   r   r   rG   r]   rU   r   r   r   r   r[   rW   r^   rX   r^   r   r^   r   rZ   r   r\   r   r[   r   r[   r_   r`   )r_   r   r_   r[   r   )r_   rm   )r   r   r_   r[   )r   r   r_   r<   )rG   r]   r_   r\   )r   r   r_   r+   )r   r   r_   r8   )r_   r^   )rW   r^   r_   r^   r   )r'  rm   r_   r   )r'  r0  r_   r1  )r   rA   r_   r   )r   rA   r_   r   )r_   rP  )(r   r   r   r   rC   rM   ri   r   propertyr   r   r   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   rz   r	  r
  r   r!  r.  r%  r   rK  rg   rg   rg   rh   r     s    
/

















/


))r   c                   @  sr   e Zd ZdZd9ddZ									d:d;ddZ			d<d=ddZ													 		!	d>d?d7d8ZdS )@DataFrameRendereraJ  Class for creating dataframe output in multiple formats.

    Called in pandas.core.generic.NDFrame:
        - to_csv
        - to_latex

    Called in pandas.core.frame.DataFrame:
        - to_html
        - to_string

    Parameters
    ----------
    fmt : DataFrameFormatter
        Formatter with the formatting options.
    rM  r   r_   r`   c                 C  s
   || _ d S r   )rM  )rf   rM  rg   rg   rh   ri   u  s   
zDataFrameRenderer.__init__NFrb   "FilePath | WriteBuffer[str] | Noneencodingr]   classesstr | list | tuple | Nonenotebookr[   borderint | bool | Nonetable_idrender_linksc                 C  sF   ddl m}m}	 |r|	n|}
|
| j||||d}| }t|||dS )uJ  
        Render a DataFrame to a html table.

        Parameters
        ----------
        buf : str, path object, file-like object, or None, default None
            String, path object (implementing ``os.PathLike[str]``), or file-like
            object implementing a string ``write()`` function. If None, the result is
            returned as a string.
        encoding : str, default “utf-8”
            Set character encoding.
        classes : str or list-like
            classes to include in the `class` attribute of the opening
            ``<table>`` tag, in addition to the default "dataframe".
        notebook : {True, False}, optional, default False
            Whether the generated HTML is for IPython Notebook.
        border : int
            A ``border=border`` attribute is included in the opening
            ``<table>`` tag. Default ``pd.options.display.html.border``.
        table_id : str, optional
            A css id is included in the opening `<table>` tag if specified.
        render_links : bool, default False
            Convert URLs to HTML links.
        r   )HTMLFormatterNotebookFormatter)rX  r[  r]  r^  rb   rW  )pandas.io.formats.htmlr_  r`  rM  r   save_to_buffer)rf   rb   rW  rX  rZ  r[  r]  r^  r_  r`  Klasshtml_formatterstringrg   rg   rh   to_htmlx  s   "zDataFrameRenderer.to_htmlr   r^   c                 C  s0   ddl m} || j|d}| }t|||dS )u%  
        Render a DataFrame to a console-friendly tabular output.

        Parameters
        ----------
        buf : str, path object, file-like object, or None, default None
            String, path object (implementing ``os.PathLike[str]``), or file-like
            object implementing a string ``write()`` function. If None, the result is
            returned as a string.
        encoding: str, default “utf-8”
            Set character encoding.
        line_width : int, optional
            Width to wrap a line in characters.
        r   )StringFormatter)r   ra  )pandas.io.formats.stringrh  rM  r   rc  )rf   rb   rW  r   rh  string_formatterrf  rg   rg   rh   r     s   zDataFrameRenderer.to_string,winfer"Tstrictpath_or_buf7FilePath | WriteBuffer[bytes] | WriteBuffer[str] | Nonesepr\   r   Sequence[Hashable] | Noneindex_labelIndexLabel | Noner   compressionr9   quoting	quotecharlineterminator	chunksizedate_formatdoublequote
escapecharerrorsstorage_optionsStorageOptions | Nonec                 C  s   ddl m} |du rd}t }nd}|di d|d|
d|d	|d
|d|d|d|d|d|d|d|	d|d|d|d|d| j}|  |rbt|tsXJ | }|  |S dS )z;
        Render dataframe as comma-separated file.
        r   )CSVFormatterNTFrp  ry  rr  rW  r~  rv  rw  r   rt  r   rz  rx  r{  r|  r}  r  r/  rg   )pandas.io.formats.csvsr  r   rM  saver{   getvalueclose)rf   rp  rW  rr  r   rt  r   rv  rw  rx  ry  rz  r{  r|  r}  r~  r  r  created_buffercsv_formattercontentrg   rg   rh   to_csv  s^   	
zDataFrameRenderer.to_csv)rM  r   r_   r`   )NNNFNNF)rb   rV  rW  r]   rX  rY  rZ  r[   r[  r\  r]  r]   r^  r[   r_   r]   )NNN)rb   rV  rW  r]   r   r^   r_   r]   )NNrk  NNrl  rm  Nrn  NNNTNro  N)"rp  rq  rW  r]   rr  r\   r   rs  rt  ru  r   r\   rv  r9   rw  r^   rx  r\   ry  r]   rz  r^   r{  r]   r|  r[   r}  r]   r~  r\   r  r  r_   r]   )r   r   r   r   ri   rg  r   r  rg   rg   rg   rh   rU  d  s@    
5rU  rf  r\   rb   rV  rW  r]   c                 C  s\   t ||d}||  |du r| W  d   S 	 W d   dS 1 s'w   Y  dS )zQ
    Perform serialization. Write to buf or return as string if buf is None.
    )rW  N)_get_bufferwriter  )rf  rb   rW  fdrg   rg   rh   rc    s   
$rc  IGenerator[WriteBuffer[str], None, None] | Generator[StringIO, None, None]c                 c  s    | dur
t | } nt } |du rd}n	t| tstdt| dr'| V  dS t| trPtt|  t| d|dd}|V  W d   dS 1 sIw   Y  dS td)	z
    Context manager to open, yield and close buffer for filenames or Path-like
    objects, otherwise yield buf unchanged.
    Nzutf-8z1buf is not a file name and encoding is specified.r  rl  rt   )rW  newlinez1buf is not a file name and it has no write method)	r3   r   r{   r\   r   hasattrr2   open	TypeError)rb   rW  frg   rg   rh   r    s    




"r  rO   rE   r   Tvaluesr5   r/  r1  rU   r   rS   digitsr^   r-  str | int | NonerG   r   r   r   rw  fallback_formatterr   c                 C  s   t | jdrt}tt| } n<t| jtrt}tt| } n.t | jdr,t	}tt
| } nt| jtr5t}nt | jdr?t}nt | jdrIt}nt}|du rQd}|du rYtd}|du ratd}|| |||||||||	|
d	}| S )
a  
    Format an array for printing.

    Parameters
    ----------
    values : np.ndarray or ExtensionArray
    formatter
    float_format
    na_rep
    digits
    space
    justify
    decimal
    leading_space : bool, optional, default True
        Whether the array should be formatted with a leading space.
        When an array as a column of a Series or DataFrame, we do want
        the leading space to pad between columns.

        When formatting an Index subclass
        (e.g. IntervalIndex._get_values_for_csv), we don't want the
        leading space since it should be left-aligned.
    fallback_formatter

    Returns
    -------
    List[str]
    MmfciuN   ra   display.precision)
r  rS   rU   r/  r-  rG   r   r   rw  r  )r   is_np_dtyperV   _Datetime64Formatterr   r&   r{   r!   _Datetime64TZFormatter_Timedelta64Formatterr(   r"   _ExtensionArrayFormatterFloatArrayFormatter_IntArrayFormatter_GenericArrayFormatterr   
get_result)r  r/  rU   rS   r  r-  rG   r   r   rw  r  	fmt_klassfmt_objrg   rg   rh   r   7  sH   )r   c                   @  sB   e Zd Z											d&d'dd Zd(d"d#Zd(d$d%ZdS ))r     NrO   r  rE   r   Tr  r5   r  rm   r/  r1  rS   r\   r-  r0  rU   r   rG   r   rw  r^   fixed_widthr[   r   r   r  r_   r`   c                 C  sL   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _d S r   )r  r  rS   r-  r/  rU   rG   r   rw  r  r   r  )rf   r  r  r/  rS   r-  rU   rG   r   rw  r  r   r  rg   rg   rh   ri     s   
z_GenericArrayFormatter.__init__r   c                 C  s   |   }t|| jS r   )_format_stringsr"  rG   )rf   r   rg   rg   rh   r    s   z!_GenericArrayFormatter.get_resultc                   st  j d u rtd}|d u rtdfdd}nj }jd ur$j njd ur-j njd uo6jtk}ttjd|d  fdd}j	}t
|tjsStd	t|t}|tjt|ttd
t|jd@ }j}|d u rw| }g }t|D ]:\}	}
||	 rjd ur|r|d||
  q}||	 r|||
 q}|du rd}nd}||j||
d q}|S )Nra   r  c                   s   t | d ddS )Nz .dr  )_trim_zeros_single_floatr;  )	precisionrg   rh   <lambda>  s    z8_GenericArrayFormatter._format_strings.<locals>.<lambda>ru   )ry   quote_stringsc                   s   j d ur;t| r;t| r;| d u rdS | tu rttS t| r)t| r)t| S | t	u s6t
| tjtjfr8dS j S t
| trDt| S t
| trMt| S t | S )Nr`   r   )rS   r   r#   r   r\   r   r   r  isinfr   r{   
datetime64timedelta64r*   r)   reprr;  )r/  rf   rg   rh   _format  s   

z7_GenericArrayFormatter._format_strings.<locals>._formatz=ExtensionArray formatting should use _ExtensionArrayFormatterrj   r  r5  Fz{v}z {v}rF  )rU   r   r/  r  rw  r   r
   r4   r~   r  r{   r  ndarrayr  r   	map_inferr   r   r$   r  rangerl   shaper   r@  r   r$  format)rf   rU   r  r  valsinferredis_float_typer   r   r'  rF  tplrg   )r/  r  rf   rh   r    sT   


 z&_GenericArrayFormatter._format_strings)r  NrO   r  NrE   r   NTTN)r  r5   r  rm   r/  r1  rS   r\   r-  r0  rU   r   rG   r\   r   r\   rw  r^   r  r[   r   r   r  r1  r_   r`   r   )r   r   r   ri   r  r  rg   rg   rg   rh   r    s    
r  c                      sB   e Zd Zd fddZ		ddddZdddZdddZ  ZS )r  r_   r`   c                   sT   t  j|i | | jd ur$| jd u r&d| _t| jr(| j| _d | _d S d S d S d S NF)superri   rU   r/  r  callable)rf   argskwargs	__class__rg   rh   ri     s   

zFloatArrayFormatter.__init__NrU   r   	thresholdfloat | Noner   c                   sl   du rj rfdd nfdd jdkr$ fddn du r,S fdd	}|S )
z;Returns a function to be applied on each value to format itNc                   s$    d usJ t | r | dS jS )Nvalue)r$   rS   r  )rU   rf   rg   rh   base_formatter  s   
z<FloatArrayFormatter._value_formatter.<locals>.base_formatterc                   s   t | rt| S  jS r   )r$   r\   rS   r  r   rg   rh   r  &  s   r   c                   s    |  djdS )Nr   rj   )replacer   r  )r  rf   rg   rh   decimal_formatter+  s   z?FloatArrayFormatter._value_formatter.<locals>.decimal_formatterc                   s*   t | rt| kr | S  dS jS )Ng        )r$   absrS   r  )r  rf   r  rg   rh   r/  4  s
   z7FloatArrayFormatter._value_formatter.<locals>.formatter)rU   r   )rf   rU   r  r/  rg   )r  r  rU   rf   r  rh   _value_formatter  s   
	z$FloatArrayFormatter._value_formatter
np.ndarrayc           
        sT  ddddd	d
 j durjj jS jr tdnd fdd}jdu rJjrFjdu r;d}nd}t|jj	d}n
j}nfdd}||}jsY|S t
|dkrptdd |D }|j	d k}nd}tj}|dk }|dj	  k |dk@  }	|	s|r|rjdu rd}nd}t|jj	d}||}|S )z
        Returns the float values converted into strings using
        the parameters given at initialisation, as a numpy array
        r  r5   r/  r   rS   r\   c                   s<   t | }t fddt|  | D | j}|S )Nc                   s    g | ]\}}|s |nqS rg   rg   )r   valr  r/  rS   rg   rh   r  H  s    zWFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_rep.<locals>.<listcomp>)r#   r  arrayr   ravelreshaper  )r  r/  rS   mask	formattedrg   r  rh   format_with_na_repE  s   zCFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_repc                 S  s   t |  }t |  }t|t|}}g }t|  ||||D ]R\}}	}
}}|s6|s6||| q#|sF|||	 d| d q#|sj||
 }|dr^|| | d q#|| d| d q#|| d| d q#t 	|
| jS )N+j-)r  realr  imagr#   r   r$  strip
startswithr  r  r  )r  r/  rS   real_valuesimag_values	real_mask	imag_maskformatted_lstr  real_valimag_valre_isnaim_isnaimag_formattedrg   rg   rh   format_complex_with_na_repO  s,   
zKFloatArrayFormatter.get_result_as_array.<locals>.format_complex_with_na_repNzdisplay.chop_thresholdc                   s    | }jdkrdj nj}j}t|}|r# |||}n|||}jrB|r5t|j}nt|j}t	j
|ddS |S )NrD   r5  objectrV   )r  rG   rS   r  r   r  _trim_zeros_complexr   _trim_zeros_floatr  asarray)rU   r/  rS   r  
is_complexr   r  r  rf   r  rg   rh   format_values_withu  s   zCFloatArrayFormatter.get_result_as_array.<locals>.format_values_withTz{value: .{digits:d}f}z{value:.{digits:d}f})r  c                   s
    j |  S r   )rU   r  r   rg   rh   r    s   
 z9FloatArrayFormatter.get_result_as_array.<locals>.<lambda>r   c                 s      | ]}t |V  qd S r   rl   r  rg   rg   rh   r        z:FloatArrayFormatter.get_result_as_array.<locals>.<genexpr>   Fg    .A
   z{value: .{digits:d}e}z{value:.{digits:d}e})r  r5   r/  r   rS   r\   )r/  r  rS   r  r   rU   r   r
   r  r  rl   r&  r  r  r@  )
rf   r  fmt_strrU   formatted_valuesmaxlentoo_longabs_valshas_large_valueshas_small_valuesrg   r  rh   get_result_as_array?  sB   







z'FloatArrayFormatter.get_result_as_arrayr   c                 C  s   t |  S r   )r  r  r   rg   rg   rh   r    s   z#FloatArrayFormatter._format_stringsr   NN)rU   r   r  r  r_   r   )r_   r  r   )r   r   r   ri   r  r  r  __classcell__rg   rg   r  rh   r    s    
8 r  c                   @  s   e Zd ZdddZdS )r  r_   r   c                   s>   | j du r
dd }ndd }| jp|  fdd| jD }|S )NFc                 S     | dj | dS )Nr  r;  r  r;  rg   rg   rh   r        z4_IntArrayFormatter._format_strings.<locals>.<lambda>c                 S  r  )Nz dr;  r  r;  rg   rg   rh   r    r  c                      g | ]} |qS rg   rg   r  r/  rg   rh   r    r=  z6_IntArrayFormatter._format_strings.<locals>.<listcomp>)r   r/  r  )rf   formatter_strr   rg   r  rh   r    s   


z"_IntArrayFormatter._format_stringsNr   )r   r   r   r  rg   rg   rg   rh   r    s    r  c                      s8   e Zd ZU ded< 		dd fd
dZdddZ  ZS )r  r&   r  r   Nnat_repr\   r{  r`   r_   c                   s$   t  j|fi | || _|| _d S r   )r  ri   r  r{  )rf   r  r  r{  r  r  rg   rh   ri     s   
z_Datetime64Formatter.__init__r   c                   s<    j } jdur fdd|D S |j j jd}| S )z&we by definition have DO NOT have a TZNc                   s   g | ]}  |qS rg   r  r  r   rg   rh   r    r:  z8_Datetime64Formatter._format_strings.<locals>.<listcomp>)rS   r{  )r  r/  _format_native_typesr  r{  tolist)rf   r  r   rg   r   rh   r    s   
z$_Datetime64Formatter._format_stringsr   N)r  r&   r  r\   r{  r`   r_   r`   r   r   r   r   __annotations__ri   r  r   rg   rg   r  rh   r    s   
 r  c                   @      e Zd ZU ded< dddZdS )	r  r'   r  r_   r   c                 C  sx   | j }| j}d }|d u r|jdd}t|tr| }ntj|td}t	||| j
| j| j| j| j| j| j| j|d}|S )NT)boxedr  )	rU   rS   r  r-  rG   r   r   rw  r  )r  r/  
_formatterr{   r%   _internal_get_valuesr  r  r  r   rU   rS   r  r-  rG   r   r   rw  )rf   r  r/  r  r  r   rg   rg   rh   r    s,   

z(_ExtensionArrayFormatter._format_stringsNr   r   r   r   r  r  rg   rg   rg   rh   r       
 r  percentilesnp.ndarray | Sequence[float]c                 C  s   t | } t| rt | dkrt | dkstdd|  } t| }| |t}t 	|| }t |rB|t
}dd |D S t | }t|}t j| td}| |  tt
||< | |  |t
|| < dd |D S )	a  
    Outputs rounded and formatted percentiles.

    Parameters
    ----------
    percentiles : list-like, containing floats from interval [0,1]

    Returns
    -------
    formatted : list of strings

    Notes
    -----
    Rounding precision is chosen so that: (1) if any two elements of
    ``percentiles`` differ, they remain different after rounding
    (2) no entry is *rounded* to 0% or 100%.
    Any non-integer is always rounded to at least 1 decimal place.

    Examples
    --------
    Keeps all entries different after rounding:

    >>> format_percentiles([0.01999, 0.02001, 0.5, 0.666666, 0.9999])
    ['1.999%', '2.001%', '50%', '66.667%', '99.99%']

    No element is rounded to 0% or 100% (unless already equal to it).
    Duplicates are allowed:

    >>> format_percentiles([0, 0.5, 0.02001, 0.5, 0.666666, 0.9999])
    ['0%', '50%', '2.0%', '50%', '66.67%', '99.99%']
    r   rj   z/percentiles should all be in the interval [0,1]d   c                 S     g | ]}|d  qS %rg   r   r'  rg   rg   rh   r  >  r=  z&format_percentiles.<locals>.<listcomp>r  c                 S  r  r  rg   r  rg   rg   rh   r  F  r=  )r  r  r   r   r   get_precisionroundastyperm   iscloser\   unique
empty_liker  )r  precpercentiles_round_typeint_idxoutunique_pctsrg   rg   rh   format_percentiles
  s*   
"


r%  r  rm   c                 C  sx   | d dkr
| d nd }| d dk rd| d  nd }t j| ||d}t|}t t t |t }td|}|S )Nr   r  )to_beginto_endrj   )	r  ediff1dr  floorlog10rn   r  rm   r&  )r  r'  r(  diffr   rg   rg   rh   r  I  s   
r  r   r  NaTType | Timestampr  c                 C  s   | t u r|S t| S r   )r   r\   )r  r  rg   rg   rh   _format_datetime64S  s   r.  r{  c                 C  s"   t | tr|S |r| |S | jS r   )r{   r   strftime
_date_repr)r  r  r{  rg   rg   rh   _format_datetime64_dateonly\  s
   

r1  is_dates_onlyr[   r   c                   s   | r	 fddS fddS )z]Return a formatter callable taking a datetime64 as input and providing
    a string as outputc                   s   t |  dS )N)r  r{  )r1  r;  r{  r  rg   rh   r  r  s    z'get_format_datetime64.<locals>.<lambda>c                   s   t |  dS )Nr  )r.  r;  r4  rg   rh   r  v  s    rg   )r2  r  r{  rg   r3  rh   get_format_datetime64k  s   r5  c                   @  r  )	r  r&   r  r_   r   c                   s>   | j j}| j t}| jpt|| jd  fdd|D }|S )zwe by definition have a TZ)r{  c                   r  rg   rg   r  r  rg   rh   r    r=  z:_Datetime64TZFormatter._format_strings.<locals>.<listcomp>)r  _is_dates_onlyr  r  r/  r5  r{  )rf   idor  r   rg   r  rh   r  |  s   z&_Datetime64TZFormatter._format_stringsNr   r  rg   rg   rg   rh   r  y  r  r  c                      s6   e Zd ZU ded< 	dd fdd	ZdddZ  ZS )r  r(   r  r   r  r\   r_   r`   c                   s   t  j|fi | || _d S r   )r  ri   r  )rf   r  r  r  r  rg   rh   ri     s   
z_Timedelta64Formatter.__init__r   c                   s,   | j pt| j| jdd  fdd| jD S )NF)r  boxc                   r  rg   rg   r  r  rg   rh   r    r=  z9_Timedelta64Formatter._format_strings.<locals>.<listcomp>)r/  get_format_timedelta64r  r  r   rg   r  rh   r    s   
z%_Timedelta64Formatter._format_stringsr   )r  r(   r  r\   r_   r`   r   r  rg   rg   r  rh   r    s
   
 
r  Fr(   str | floatr8  c                   s(   | j }|rdnd fdd}|S )z
    Return a formatter function for a range of timedeltas.
    These will all have the same format argument

    If box, then show the return in quotes
    Nlongc                   sN   | d u st | rt| rS t| tst| } | jd} r%d| d}|S )Nr  ')r   r#   r{   r   
_repr_base)r  r   r8  r  r  rg   rh   r    s   
z*get_format_timedelta64.<locals>._formatter)r6  )r  r  r8  	even_daysr  rg   r?  rh   r9    s   r9  r  r  rd   printing._TextAdjustment | Nonec                   s   t | dks
|dkr| S |d u rt  n| t fdd| D |d ur+t|tdd ur9kr9d fd	d
fdd| D }  j| |d}|S )Nr   r   c                 3  s    | ]}  |V  qd S r   r  r  )
adjustmentrg   rh   r        z$_make_fixed_width.<locals>.<genexpr>r   r  r\   r_   c                   s6   d urdk  | k@ r| d d  d } | S )Nr   r   r  r;  )rB  conf_maxr,  rg   rh   just  s   z_make_fixed_width.<locals>.justc                   r  rg   rg   r  )rE  rg   rh   r    r=  z%_make_fixed_width.<locals>.<listcomp>r   )r  r\   r_   r\   )rl   r4   rc   r&  r   rG   )r  rG   r  rd   r   rg   )rB  rD  rE  r,  rh   r"    s   

r"  str_complexesc           	        s   g g }}| D ] }t d|}|d|dd  |d|dd  qt| }t|| |}t|dkr;g S tdd |D d	   fd
dt|d| ||d D }|S )z
    Separates the real and imaginary parts from the complex number, and
    executes the _trim_zeros_float method on each of those.
    z([j+-])rt   Nr   c                 s  r  r   r  )r   partrg   rg   rh   r    r  z&_trim_zeros_complex.<locals>.<genexpr>rj   c                   s6   g | ]\}}||d   |dd d   d qS )r   rj   N>r  rg   )r   real_ptimag_ptpadded_lengthrg   rh   r    s    z'_trim_zeros_complex.<locals>.<listcomp>)rer   r$  r   rl   r  r&  r   )	rF  r   	real_part	imag_partr  trimmednpadded_partspaddedrg   rM  rh   r    s   

r  	str_floatc                 C  s    |  d} | dr| d7 } | S )zX
    Trims trailing zeros after a decimal point,
    leaving just one if necessary.
    0r   )rstripendswith)rV  rg   rg   rh   r    s   

r  
str_floatsArrayLike | list[str]c                   sl   | }t d  ddfdddfd	d
}||r*fdd|D }||s fdd|D }|S )z
    Trims the maximum number of trailing zeros equally from
    all numbers containing decimals, leaving just one if
    necessary.
    z^\s*[\+-]?[0-9]+\z[0-9]*$r_   r[   c                   s   t  | d uS r   )rO  matchr;  )number_regexrg   rh   is_number_with_decimal  s   z1_trim_zeros_float.<locals>.is_number_with_decimalr  r[  c                   s0    fdd| D }t |dkotdd |D S )z
        Determine if an array of strings should be trimmed.

        Returns True if all numbers containing decimals (defined by the
        above regular expression) within the array end in a zero, otherwise
        returns False.
        c                   s   g | ]} |r|qS rg   rg   r  r^  rg   rh   r  #  s    z:_trim_zeros_float.<locals>.should_trim.<locals>.<listcomp>r   c                 s  s    | ]}| d V  qdS )rW  NrY  r  rg   rg   rh   r  $  rC  z9_trim_zeros_float.<locals>.should_trim.<locals>.<genexpr>)rl   r   )r  numbersr_  rg   rh   should_trim  s   z&_trim_zeros_float.<locals>.should_trimc                   s$   g | ]} |r|d d n|qS )Nr&  rg   r  r_  rg   rh   r  '  s   $ z%_trim_zeros_float.<locals>.<listcomp>c                   s*   g | ]}|r|  r|d  n|qS )rW  r`  r  )r   r^  rg   rh   r  *  s    NrS  )r  r[  r_   r[   )rO  compile)rZ  r   rR  rb  r   rg   )r   r^  r]  rh   r    s   r  rR   r+   c                 C  s    t | trtj| j S | jd uS r   )r{   r,   comany_not_nonerR  rT   )rR   rg   rg   rh   r   1  s   

r   c                   @  s   e Zd ZdZi dddddddd	d
dddddddddddddddddddddd d!d"d#Z	%d3d4d,d-Zd5d1d2Zd$S )6EngFormatterzl
    Formats float values according to engineering format.

    Based on matplotlib.ticker.EngFormatter
    ir6  iziair  ipirS  iur  r   rt   r   rE  r  r  	   Gr  T   P   E   Z   YNFaccuracyr^   use_eng_prefixr[   r_   r`   c                 C  s   || _ || _d S r   rw  rx  )rf   rw  rx  rg   rg   rh   ri   T  s   
zEngFormatter.__init__numfloatr\   c           
      C  s  t t|}t |rdS t |rdS d}|dk rd}| }|dkr3t tt| d d }nt d}|t	| j
 }|	t| j
 }t|}| jrX| j
| }n|dk rdd| d}nd	|d}|| d
|  }| jdu rzd}nd| jdd}|j||d}	|	S )a  
        Formats a number in engineering notation, appending a letter
        representing the power of 1000 of the original number. Some examples:
        >>> format_eng = EngFormatter(accuracy=0, use_eng_prefix=True)
        >>> format_eng(0)
        ' 0'
        >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix=True)
        >>> format_eng(1_000_000)
        ' 1.0M'
        >>> format_eng = EngFormatter(accuracy=2, use_eng_prefix=False)
        >>> format_eng("-1e-6")
        '-1.00E-06'

        @param num: the value to represent
        @type num: either a numeric value or a string that can be converted to
                   a numeric value (as per decimal.Decimal constructor)

        @return: engineering formatted string
        rO   infrj   r   r&  r   zE-02dzE+r  Nz{mant: g}{prefix}z{mant: .r  z
f}{prefix})mantprefix)r	   r\   is_nanis_infiniterm   mathr*  r+  rn   r&  ENG_PREFIXESr   rx  rw  r  )
rf   rz  dnumsignpow10	int_pow10r  r~  
format_strr  rg   rg   rh   __call__Z  s4   

 
zEngFormatter.__call__r  )rw  r^   rx  r[   r_   r`   )rz  r{  r_   r\   )r   r   r   r   r  ri   r  rg   rg   rg   rh   rf  8  sP    	
rf  r   rw  rx  r`   c                 C  s   t dt| | dS )a  
    Format float representation in DataFrame with SI notation.

    Parameters
    ----------
    accuracy : int, default 3
        Number of decimal digits after the floating point.
    use_eng_prefix : bool, default False
        Whether to represent a value with SI prefixes.

    Returns
    -------
    None

    Examples
    --------
    >>> df = pd.DataFrame([1e-9, 1e-3, 1, 1e3, 1e6])
    >>> df
                  0
    0  1.000000e-09
    1  1.000000e-03
    2  1.000000e+00
    3  1.000000e+03
    4  1.000000e+06

    >>> pd.set_eng_float_format(accuracy=1)
    >>> df
             0
    0  1.0E-09
    1  1.0E-03
    2  1.0E+00
    3  1.0E+03
    4  1.0E+06

    >>> pd.set_eng_float_format(use_eng_prefix=True)
    >>> df
            0
    0  1.000n
    1  1.000m
    2   1.000
    3  1.000k
    4  1.000M

    >>> pd.set_eng_float_format(accuracy=1, use_eng_prefix=True)
    >>> df
          0
    0  1.0n
    1  1.0m
    2   1.0
    3  1.0k
    4  1.0M

    >>> pd.set_option("display.float_format", None)  # unset option
    ra   N)r   rf  ry  rg   rg   rh   set_eng_float_format  s   7r  rt   rA  r   sentinelbool | object | strlist[dict[int, int]]c           	      C  s   t | dkrg S dgt | d  }g }| D ]1}d}i }t|D ]\}}|| r,||kr,qd||< || ||< |}qt || ||< || q|S )a  
    For each index in each level the function returns lengths of indexes.

    Parameters
    ----------
    levels : list of lists
        List of values on for level.
    sentinel : string, optional
        Value which states that no new index starts on there.

    Returns
    -------
    Returns list of maps. For each level returns map of indexes (key is index
    in row and value is length of index).
    r   TF)rl   r   r$  )	rA  r  controlr   r4  
last_indexlengthsr'  keyrg   rg   rh   get_level_lengths  s    r  WriteBuffer[str]linesc                 C  s4   t dd |D rdd |D }| d| dS )z
    Appends lines to a buffer.

    Parameters
    ----------
    buf
        The buffer to write to
    lines
        The lines to append.
    c                 s  s    | ]}t |tV  qd S r   )r{   r\   r  rg   rg   rh   r    rC  z#buffer_put_lines.<locals>.<genexpr>c                 S  r<  rg   rI  r  rg   rg   rh   r  	  r=  z$buffer_put_lines.<locals>.<listcomp>rx   N)r@  r  r   )rb   r  rg   rg   rh   buffer_put_lines  s   r  )r_   r   r  )rf  r\   rb   rV  rW  r]   r_   r]   r   )rb   rV  rW  r]   r_   r  )	NrO   NNrE   r   TNN)r  r5   r/  r1  rU   r   rS   r\   r  r^   r-  r  rG   r\   r   r\   r   r   rw  r^   r  r1  r_   r   )r  r  r_   r   )r  r  r_   rm   r:  )r  r-  r  r\   r_   r\   r
  )r  r-  r  r\   r{  r]   r_   r\   )r2  r[   r  r\   r{  r]   r_   r   )r   F)r  r(   r  r;  r8  r[   r_   r   )rE   NN)
r  r   rG   r\   r  r^   rd   rA  r_   r   )r   )rF  r5   r   r\   r_   r   )rV  r\   r_   r\   )rZ  r[  r   r\   r_   r   )rR   r+   r_   r[   )r   F)rw  rm   rx  r[   r_   r`   )rt   )rA  r   r  r  r_   r  )rb   r  r  r   r_   r`   )r   
__future__r   collections.abcr   r   r   r   
contextlibr   csvr   r   r	   	functoolsr
   ior   r  rO  shutilr   typingr   r   r   r   r   numpyr  pandas._config.configr   r   pandas._libsr   pandas._libs.missingr   pandas._libs.tslibsr   r   r   pandas._libs.tslibs.nattyper   pandas.core.dtypes.commonr   r   r   r   r   r   pandas.core.dtypes.dtypesr    r!   r"   pandas.core.dtypes.missingr#   r$   pandas.core.arraysr%   r&   r'   r(   pandas.core.arrays.string_r)   pandas.core.baser*   pandas.core.commoncorecommonrd  pandas.core.indexes.apir+   r,   r-   r.   pandas.core.indexes.datetimesr/   pandas.core.indexes.timedeltasr0   pandas.core.reshape.concatr1   pandas.io.commonr2   r3   r   r4   pandas._typingr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   pandasrA   rB   rC   r  VALID_JUSTIFY_PARAMETERSrM   rN   r   r   r   rU  rc  r  r   r  r  r  r  r  r%  r  r.  r1  r5  r  r  r9  r"  r  r  r  r   rf  r  r  r  rg   rg   rg   rh   <module>   s     88	 
#
!   H  (Un J
!
?
$"
!
$`;+