
    o[we)                      U d 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 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mZ ddl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-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@ ddlAmBZBmCZCmDZD ddlEmFZF ddlGmHZH dd	lImJc mKZL ddlMmNZN ddlOmPZPmQZQmRZRmSZS ddlTmUZU ddlVmWZW ddlXmYZY ddlZm[Z[m\Z\ ddl]m^Z^ er"ddl_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZj dd lkmlZlmmZm d!Znd"eod#<   d$Zpd%Zqd"eod&<    G d' d(          Zr G d) d*          Zs G d+ d,          Zt G d- d.et          Zudd0Zvdd2Zwdd3Zx G d4 d5          Zy G d6 d7          Zz	 	 ddd>Z{e
	 ddd@            Z|	 	 	 	 	 	 	 	 	 dddWZ} G dX dY          Z~ G dZ d[e~          Z G d\ d]e~          Z G d^ d_e~          Z G d` dae~          ZdddZddgZdddlZ	 	 dddnZ	 dddqZddsZ G dt due          Z G dv dwe~          Z	 	 ddd|Z	 	 	 dddZdddZddZ	 dddZddZ G d d          ZdddZ	 dddZdd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IterableMappingSequence)contextmanager)
QUOTE_NONEQUOTE_NONNUMERIC)Decimal)partial)StringION)get_terminal_size)IOTYPE_CHECKINGAnyCallableFinalcast)east_asian_width)
get_option
set_option)lib)NA)NaT	Timedelta	Timestampget_unit_from_dtypeiNaTperiods_per_day)NaTType)is_complex_dtypeis_float
is_integeris_list_likeis_numeric_dtype	is_scalar)CategoricalDtypeDatetimeTZDtypeExtensionDtype)isnanotna)CategoricalDatetimeArrayTimedeltaArray)StringDtype)PandasObject)extract_array)Index
MultiIndexPeriodIndexensure_index)DatetimeIndex)TimedeltaIndex)concat)check_parent_directorystringify_path)printing)	ArrayLikeAxesColspaceArgTypeColspaceTypeCompressionOptionsFilePathFloatFormatTypeFormattersType
IndexLabel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``.

            .. versionchanged:: 1.2.0

        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                  8    e Zd Z	 	 	 	 dddZddZddZddZdS )CategoricalFormatterNTNaNcategoricalr-   bufIO[str] | Nonelengthboolna_repstrfooterreturnNonec                    || _         ||nt          d          | _        || _        || _        || _        t          | _        d S N )rX   r   rY   r]   r[   r_   r   quoting)selfrX   rY   r[   r]   r_   s         8lib/python3.11/site-packages/pandas/io/formats/format.py__init__zCategoricalFormatter.__init__   sA     '/33x||'    c                    d}| j         r!|r|dz  }|dt          | j                   z  }| j                                        }|r|dz  }||z  }t	          |          S )Nrd   , Length: 
)r[   lenrX   _repr_categories_infor^   )rf   r_   
level_infos      rg   _get_footerz CategoricalFormatter._get_footer   s}    ; 	9 $8T%5!6!6888F%;;==
  	dNF*6{{ri   	list[str]c                l    t          | j                                        d d | j        | j                  S )N)float_formatr]   re   )format_arrayrX   _internal_get_valuesr]   re   rf   s    rg   _get_formatted_valuesz*CategoricalFormatter._get_formatted_values   s;    1133;L
 
 
 	
ri   c                   | j         }t          |          dk    r| j        r|                                 S dS |                                 }d |D             }d                    |          }d|z   dz   g}| j        r+|                                 }|r|                    |           t          d                    |                    S )Nr   rd   c                6    g | ]}|                                 S  )strip.0is     rg   
<listcomp>z2CategoricalFormatter.to_string.<locals>.<listcomp>   s     444Aaggii444ri   rk   []rm   )rX   rn   r_   rq   rx   joinappendr^   )rf   rX   
fmt_valuesvaluesresultr_   s         rg   	to_stringzCategoricalFormatter.to_string   s    &{q  { '')))r//11
44444
:&&,$%; 	&%%''F &f%%%499V$$%%%ri   )NTrW   T)rX   r-   rY   rZ   r[   r\   r]   r^   r_   r\   r`   ra   r`   r^   r`   rr   )__name__
__module____qualname__rh   rq   rx   r   r{   ri   rg   rV   rV      sw         #( ( ( ( (   "
 
 
 
& & & & & &ri   rV   c                  T    e Zd Z	 	 	 	 	 	 	 	 	 	 d!d"dZd#dZd$dZd%dZd&dZd$d ZdS )'SeriesFormatterNTrW   FseriesrI   rY   rZ   r[   
bool | strheaderr\   indexr]   r^   namert   
str | Nonedtypemax_rows
int | Nonemin_rowsr`   ra   c                0   || _         ||nt                      | _        || _        || _        || _        || _        || _        |
| _        || _	        |t          d          }|| _        |	| _        t                      | _        |                                  d S )Ndisplay.float_format)r   r   rY   r   r]   r   r[   r   r   r   r   rt   r   get_adjustmentadj_chk_truncate)rf   r   rY   r[   r   r   r]   r   rt   r   r   r   s               rg   rh   zSeriesFormatter.__init__	  s     /33xzz	
  %&<==L(
!##ri   c                   |  | j         }| j        }|ot          | j                  |k    }| j        }|rxt	          t
          |          }|rt          ||          }|dk    r|}|j        d |         }n1|dz  }t          |j        d |         |j        | d          f          }|| _	        nd | _	        || _
        || _        d S )N      )r   r   rn   r   r   intminilocr9   
tr_row_num	tr_seriesis_truncated_vertically)rf   r   r   r   r   row_nums         rg   r   zSeriesFormatter._chk_truncate)  s    #== #+"LDK0@0@80K" 	#C**H 3 x221}}"YhY/"a-XgX!6WHII8N OPP%DOO"DO'>$$$ri   c                   | j         j        }d}t          | j         j        dd           Et	          | j         j        t
          t          t          f          sJ |d| j         j        j         z  }| j        dur'|%|r|dz  }t          j
        |d          }|d| z  }| j        d	u s| j        d
k    r(| j        r!|r|dz  }|dt          | j                    z  }| j        durE| j        >t          | j        j        dd           }|r!|r|dz  }|dt          j
        |           z  }t	          | j        j        t                     r*| j        j                                        }|r|dz  }||z  }t'          |          S )Nrd   freqzFreq: Frk   	rm   )escape_charszName: Ttruncaterl   r   zdtype: rm   )r   r   getattrr   
isinstancer7   r5   r8   freqstrr<   pprint_thingr[   r   rn   r   r   r(   _valuesro   r^   )rf   r   r_   series_name
dtype_namerp   s         rg   rq   zSeriesFormatter._get_footerD  s   {4;$fd33?!M;#O     :t{08:::F9E!!d&6 $"/CUVVVK,{,,,F;$K:%%$*F% $3T[!1!1333F:U""tz'= !5vtDDJ H #dNFGH$9*$E$EGGG dn*,<== 	!/EEGGJ $j F6{{ri   tuple[list[str], bool]c                    | j         j        }t          |t                    r5t	          d |j        D                       }|                    d          }n|j        d u}|                    d          }||fS )Nc              3     K   | ]}|V  d S Nr{   r~   r   s     rg   	<genexpr>z7SeriesFormatter._get_formatted_index.<locals>.<genexpr>q  s"      ;;td;;;;;;ri   T)names)r   )r   r   r   r4   anyr   formatr   )rf   r   have_header	fmt_indexs       rg   _get_formatted_indexz$SeriesFormatter._get_formatted_indexm  s{    $eZ(( 	0;;u{;;;;;K400II*D0K$//I+%%ri   rr   c                \    t          | j        j        d | j        | j        | j                  S )N)rt   r]   leading_space)ru   r   r   rt   r]   r   rw   s    rg   rx   z%SeriesFormatter._get_formatted_valuesx  s4    N"*;*
 
 
 	
ri   c                J   | j         }|                                 }t          |          dk    rt          | j                  j         d| dS |                                 \  }}|                                 }| j        rd}| j	        }t          t          |          }| j                            ||dz
                     }|dk    rd}	nd}	| j                            |	g|d	          d         }	|                    ||z   |	           |                    |dz   d
           | j        r | j        j        dg|dd          |gR  }
n| j                            d|          }
| j        r|r|d         dz   |
z   }
|r|
d|z   z  }
t%          d
                    |
                    S )Nr   z([], )r      ...z..rM   moderd   rm   )r   rq   rn   typer   r   r   rx   r   r   r   r   r   rN   insertr   adjoinr   r^   r   )rf   r   r_   r   r   r   n_header_rowsr   widthdot_strr   s              rg   r   zSeriesFormatter.to_string  s   !!##v;;!4;''0@@v@@@@!%!:!:!<!<	;//11
' 	.MoG3((GHLLGaK!899Eqyy h&&y%h&GGJGg5w???Wq["---: 	4$TX_QE)ABB-)DEEEFFX__Q
33F; 	2; 	2q\D(61F 	$dVm#F2776??###ri   )
NTTTrW   FNTNN)r   rI   rY   rZ   r[   r   r   r\   r   r\   r]   r^   r   r\   rt   r   r   r\   r   r   r   r   r`   ra   r`   ra   r   )r`   r   r   )	r   r   r   rh   r   rq   r   rx   r   r{   ri   rg   r   r     s         #!#'##    @? ? ? ?6' ' ' 'R	& 	& 	& 	&
 
 
 
$$ $$ $$ $$ $$ $$ri   r   c                  0    e Zd ZddZddZdddZddZdS )TextAdjustmentr`   ra   c                .    t          d          | _        d S )Nzdisplay.encoding)r   encodingrw   s    rg   rh   zTextAdjustment.__init__  s    "#566ri   textr^   r   c                     t          |          S r   rn   rf   r   s     rg   rn   zTextAdjustment.len  s    4yyri   rL   textsr   max_lenr   rr   c                0    t          j        |||          S )Nr   )r<   rN   )rf   r   r   r   s       rg   rN   zTextAdjustment.justify  s    wT::::ri   spacec                F    t          j        |g|R | j        | j        d|S )N)strlenjustfunc)r<   r   rn   rN   )rf   r   listskwargss       rg   r   zTextAdjustment.adjoin  sA    

 
"&(T\
 
EK
 
 	
ri   Nr   r   r^   r`   r   rL   )r   r   r   r   r   r^   r`   rr   )r   r   r`   r^   )r   r   r   rh   rn   rN   r   r{   ri   rg   r   r     si        7 7 7 7   ; ; ; ; ;
 
 
 
 
 
ri   r   c                  4     e Zd Zd fdZddZ	 dddZ xZS )EastAsianTextAdjustmentr`   ra   c                    t                                                       t          d          rd| _        nd| _        dddddd| _        d S )Nz!display.unicode.ambiguous_as_wider   r   )NaNWFH)superrh   r   ambiguous_width_EAW_MAP)rf   	__class__s    rg   rh   z EastAsianTextAdjustment.__init__  sX    9:: 	%#$D  #$D 
  !qqqqAAri   r   r^   r   c                     t          |t                    st          |          S t           fd|D                       S )zN
        Calculate display width considering unicode East Asian Width
        c              3  r   K   | ]1}j                             t          |          j                  V  2d S r   )r   getr   r   )r~   crf   s     rg   r   z.EastAsianTextAdjustment.len.<locals>.<genexpr>  sR       
 
MNDM.q1143GHH
 
 
 
 
 
ri   )r   r^   rn   sumr   s   ` rg   rn   zEastAsianTextAdjustment.len  s[     $$$ 	t99 
 
 
 
RV
 
 
 
 
 	
ri   rL   r   Iterable[str]r   r   rr   c                      fd|dk    rfd|D             S |dk    rfd|D             S fd|D             S )Nc                T                         |           z
  t          |           z   S r   r   )tr   rf   s    rg   _get_padz1EastAsianTextAdjustment.justify.<locals>._get_pad  s#    TXXa[[(3q6611ri   rK   c                L    g | ] }|                      |                    !S r{   )ljustr~   xr   s     rg   r   z3EastAsianTextAdjustment.justify.<locals>.<listcomp>  -    888QAGGHHQKK((888ri   rM   c                L    g | ] }|                      |                    !S r{   )rM   r   s     rg   r   z3EastAsianTextAdjustment.justify.<locals>.<listcomp>  s-    999aAHHXXa[[))999ri   c                L    g | ] }|                      |                    !S r{   )rjustr   s     rg   r   z3EastAsianTextAdjustment.justify.<locals>.<listcomp>  r   ri   r{   )rf   r   r   r   r   s   ` ` @rg   rN   zEastAsianTextAdjustment.justify  s    	2 	2 	2 	2 	2 	2 6>>8888%8888X9999599998888%8888ri   r   r   r   )r   r   r   r   r   r^   r`   rr   )r   r   r   rh   rn   rN   __classcell__r   s   @rg   r   r     sv        
B 
B 
B 
B 
B 
B	
 	
 	
 	
 ?F9 9 9 9 9 9 9 9 9ri   r   r`   c                 \    t          d          } | rt                      S t                      S )Nz display.unicode.east_asian_width)r   r   r   )use_east_asian_widths    rg   r   r     s1    %&HII  &(((ri   dict[str, Any]c                     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)r   r   max_colsmax_colwidthshow_dimensions
line_width)pandas.io.formatsr	  r   get_console_size)r	  r  _s      rg   get_dataframe_repr_paramsr    s    " *)))))-.. 0022
AA
122122455"#9::%&?@@   ri   c                     t                      \  } }t          d          dk    r|nt          d          }t          d          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  )r   r   r   r   r[   )r   r   )r   heightr   r   s       rg   get_series_repr_paramsr    s    " &''ME6 ())Q.. 	*++  ())Q.. 	*++  677  ri   c                     e Zd ZdZerendZeeez   z  Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dSdTd(ZdUd*ZedVd+            Z	edVd,            Z
edVd-            ZedVd.            ZedWd/            ZedVd0            ZedVd1            ZedVd2            ZedVd3            ZedXd5            ZdYd6ZdZd8Zd[d9Zd\d;Zd]d=Zd^d>Zd^d?Zd_d@ZdVdAZdVdBZdVdCZdXdDZd`dEZd`dFZ d`dGZ!dUdHZ"dadKZ#dbdNZ$dcdOZ%dddPZ&dedRZ'dS )fDataFrameFormatterz;Class for processing dataframe formatting options and data.rd   NTrW   F.framerH   columnsAxes | None	col_spaceColspaceArgType | Noner   bool | list[str]r   r\   r]   r^   
formattersFormattersType | NonerN   r   rt   FloatFormatType | Nonesparsifybool | Noneindex_namesr   r   r   r  r  r   decimal	bold_rowsescaper`   ra   c                   || _         |                     |          | _        |                     |          | _        || _        || _        || _        |                     |          | _	        | 
                    |          | _        |	| _        |                     |
          | _        || _        || _        || _        || _        || _        || _        || _        || _        |                                 | _        |                                 | _        | j         | _        |                                  t;                      | _        d S r   )r  _initialize_columnsr  _initialize_colspacer  r   r   r]   _initialize_formattersr"  _initialize_justifyrN   rt   _initialize_sparsifyr%  show_index_namesr(  r)  r*  r   r   r  r  _calc_max_cols_fittedmax_cols_fitted_calc_max_rows_fittedmax_rows_fittedtr_framer   r   r   )rf   r  r  r  r   r   r]   r"  rN   rt   r%  r'  r   r   r  r  r(  r)  r*  s                      rg   rh   zDataFrameFormatter.__init__4  s   * 
//88229==
55jAA//88(11(;; +"   .#99;;#99;;
!##ri   list[list[str]]c                    |                                  }| j        r0|                     | j                  }|                    d|           |S )zP
        Render a DataFrame to a list of columns (as lists of strings).
        r   )_get_strcols_without_indexr   r   r6  r   )rf   strcols	str_indexs      rg   get_strcolszDataFrameFormatter.get_strcolsc  sM     1133: 	)11$-@@INN1i(((ri   c                8    | j         du p| j         dk    o| j        S )NTr   )r  is_truncatedrw   s    rg   should_show_dimensionsz)DataFrameFormatter.should_show_dimensionso  s*    #t+ 
 J.D43D	
ri   c                8    t          | j        p| j                  S r   )r\   is_truncated_horizontallyr   rw   s    rg   r>  zDataFrameFormatter.is_truncatedu  s    D2Rd6RSSSri   c                d    t          | j        ot          | j                  | j        k              S r   )r\   r3  rn   r  rw   s    rg   rA  z,DataFrameFormatter.is_truncated_horizontallyy  s*    D(Wc$,.?.?$BV.VXXXri   c                d    t          | j        ot          | j                  | j        k              S r   )r\   r5  rn   r  rw   s    rg   r   z*DataFrameFormatter.is_truncated_vertically}  s(    D(Uc$*oo@T.TVVVri   c                f    dt          | j                   dt          | j        j                   dS )Nz

[z rows x z	 columns])rn   r  r  rw   s    rg   dimensions_infoz"DataFrameFormatter.dimensions_info  s0    Rs4:RRDJ4F0G0GRRRRri   c                4    t          | j        j                  S r   )
_has_namesr  r   rw   s    rg   has_index_namesz"DataFrameFormatter.has_index_names  s    $**+++ri   c                4    t          | j        j                  S r   )rG  r  r  rw   s    rg   has_column_namesz#DataFrameFormatter.has_column_names  s    $*,---ri   c                D    t          | j        | j        | j        f          S r   )allrH  r   r1  rw   s    rg   show_row_idx_namesz%DataFrameFormatter.show_row_idx_names  s    D($*d6KLMMMri   c                D    t          | j        | j        | j        f          S r   )rL  rJ  r1  r   rw   s    rg   show_col_idx_namesz%DataFrameFormatter.show_col_idx_names  s    D)4+@$+NOOOri   r   c                x    t          | j        pt          | j                  t          | j                            S r   )r   r   rn   r  rw   s    rg   max_rows_displayedz%DataFrameFormatter.max_rows_displayed  s)    4=3C
OOS__EEEri   c                (    |t          d          S |S )Nzdisplay.multi_sparser   )rf   r%  s     rg   r0  z'DataFrameFormatter._initialize_sparsify  s    4555ri   rD   c                    |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   )rn   r  r  r   dict
ValueError)rf   r"  s     rg   r.  z)DataFrameFormatter._initialize_formatters  s     I#$$J77:jRV;W;W7JS__ J J/24:3E/F/FJ J J  ri   c                (    |t          d          S |S )Nzdisplay.colheader_justifyrS  )rf   rN   s     rg   r/  z&DataFrameFormatter._initialize_justify  s    ?9:::Nri   r3   c                d    |#t          |          }| j        |         | _        |S | j        j        S r   )r6   r  r  )rf   r  colss      rg   r,  z&DataFrameFormatter._initialize_columns  s3    ((DD)DJK:%%ri   r@   c                l   i }n,t          t          t          f          r0di}|                    fd| j        j        D                        nt          t                    r@                                D ](}|| j        j        vr|dk    rt          d|           )}nt          | j        j                  t                    k    r:t          dt                     dt          | j        j                   d          t          t          | j        j                            }|S )Nrd   c                    i | ]}|S r{   r{   )r~   columnr  s     rg   
<dictcomp>z;DataFrameFormatter._initialize_colspace.<locals>.<dictcomp>  s    NNN69NNNri   z,Col_space is defined for an unknown column: zCol_space length(rU  r   )r   r   r^   updater  r  r   keysrW  rn   rV  zip)rf   r  r   r]  s    `  rg   r-  z'DataFrameFormatter._initialize_colspace  sY    FF	C:.. 	>)_FMMNNNN4:;MNNNOOOO	7++ 	>#..**  !333"$OvOO   FF4:%&&#i..88 NI N N36tz7I3J3JN N N   #dj0)<<==Fri   c                    |                                  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  s      rg   r2  z(DataFrameFormatter._calc_max_cols_fitted  sP    ##%% 	!= $&&q!!%(( 	!L= ri   c                   |                                  rSt                      \  }}| j        dk    r||                                 z
  S |                     |          r|}n| j        }n| j        }|                     |          S )z,Number of rows with data fitting the screen.r   )rc  r   r   _get_number_of_auxiliary_rows_is_screen_short_adjust_max_rows)rf   r  r  r   s       rg   r4  z(DataFrameFormatter._calc_max_rows_fitted  s     !! 	%)++IAv}!! B B D DDD$$V,, )!=}H$$X...ri   c                r    |r4t          | 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
        )rn   r  r   r   )rf   r   s     rg   rh  z#DataFrameFormatter._adjust_max_rows  s<      	8DJ(***t}h77ri   c                H    t          | j        dk    p
| j        dk              S )z/Check if the output is to be shown in terminal.r   )r\   r  r   rw   s    rg   rc  z"DataFrameFormatter._is_in_terminal  s#    DMQ&<$-1*<===ri   c                l    t          | j        dk    ot          | j        j                  |k              S Nr   )r\   r  rn   r  r  )rf   	max_widths     rg   rd  z$DataFrameFormatter._is_screen_narrow  s.    DMQ&N3tz/A+B+BY+NOOOri   c                b    t          | j        dk    ot          | j                  |k              S rl  )r\   r   rn   r  )rf   
max_heights     rg   rg  z#DataFrameFormatter._is_screen_short  s)    DMQ&G3tz??Z+GHHHri   c                    d}d}||z   }| j         r)|t          | j                                                  z  }| j        r|dz  }|S )z?Get number of rows occupied by prompt, dots and dimension info.r   )r  rn   rE  
splitlinesr   )rf   dot_row
prompt_rownum_rowss       rg   rf  z0DataFrameFormatter._get_number_of_auxiliary_rows  sZ    
Z' 	?D0;;==>>>H; 	MHri   c                v    | j         r|                                  | j        r|                                  dS dS )zY
        Check whether the frame should be truncated. If so, slice the frame up.
        N)rA  _truncate_horizontallyr   _truncate_verticallyrw   s    rg   r   zDataFrameFormatter.truncate  sN     ) 	*'')))' 	(%%'''''	( 	(ri   c                   | j         J | j         dz  }|dk    r| j        j        ddd|f         }| j        j        dd| df         }t          ||fd          | _        t	          | j        t          t          f          r&g | j        d|         | j        | d         | _        n7t          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
        Nr   r   axis)r3  r6  r   r9   r   r"  listtupler   r   r  
tr_col_num)rf   col_numrK   rL   s       rg   rv  z)DataFrameFormatter._truncate_horizontally  s     #///&!+a<<=%aaa'k2DM&qqq7())|4E"D%=q999DM $/D%=99 #_XgX.#_gXYY/#
 3..G M.qqq(7({;DM!ri   c                D   | j         J | j         dz  }|dk    rH| j        j        d|ddf         }| j        j        | dddf         }t          ||f          | _        n7t	          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
        Nr   r   )r5  r6  r   r9   r   r   r   r   )rf   r   headtails       rg   rw  z'DataFrameFormatter._truncate_vertically9  s     #///&!+a<<=%hwhk2D=%whiil3D"D$<00DMM3..G M.xx{;DM!ri   c                     g }t           j                  s j        st           j                  D ]r\  }}                     |          }t          | j        t           j        	                    |d                     j
                  }|                    |           s|S t           j                  rt          t          t                    j                   _        t           j                  t           j                  k    r:t#          dt           j                   dt           j                   d          d  j        D             }n                      j                  } j        r|D ]}|                    d           t           j                  D ]\  }}||         }t)          t           j        	                    |d                    g fd|D             R  }                     |          }t          | j        | j
        	          }t)          g  fd
|D             |R  }	 j
                            ||	 j                  }|                    ||z              |S )Nr   )stringsrN   minimumr   zWriting z cols but got z aliasesc                    g | ]}|gS r{   r{   )r~   labels     rg   r   zADataFrameFormatter._get_strcols_without_index.<locals>.<listcomp>b  s    <<<uE7<<<ri   rd   c              3  L   K   | ]}j                             |          V  d S r   r   rn   r~   r   rf   s     rg   r   z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>m  s/      0R0RQa0R0R0R0R0R0Rri   )r  r   c              3  L   K   | ]}j                             |          V  d S r   r  r  s     rg   r   z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>t  s/      @@DHLLOO@@@@@@ri   r   )r%   r   	enumerater6  
format_col_make_fixed_widthrN   r   r  r   r   r   r   r{  r^   rn   r  rW  _get_formatted_column_labelsrM  max)
rf   r:  r   r   r   str_columnsr   cheaderheader_colwidthr   s
   `         rg   r9  z-DataFrameFormatter._get_strcols_without_indexK  s   #%DK(( 
	 
	!$-00 + +1!__Q//
.& L 2 21a 8 899	  
 z****N$$ 
	KtCy$+66DK4;3t|#4#444 :s4<00 : :"4;//: : :   =<<<<KK;;DMJJK" 	   dm,, 	1 	1DAq!!nG!DN&&q!,,--0R0R0R0R'0R0R0R  O ++J*DL/tx  J R@@@@Z@@@R/RRRGh&&wdl&KKGNN7Z/0000ri   r   rr   c           
         | j         }|                     |          }t          |j        d d |f         j        || j        | j        | j                            |j	        |                   | j
        | j                  S )N)rt   r]   r   r(  r   )r6  _get_formatterru   r   r   rt   r]   r  r   r  r(  r   )rf   r   r  	formatters       rg   r  zDataFrameFormatter.format_colz  sz    ''**	Jqqq!t$*;.$$U]1%566L*
 
 
 	
ri   	str | intCallable | Nonec                *   t          | j        t          t          f          r3t	          |          r"t          t          |          }| j        |         S d S t	          |          r|| j        vr| j        |         }| j                            |d           S r   )	r   r"  r{  r|  r$   r   r   r  r   )rf   r   s     rg   r  z!DataFrameFormatter._get_formatter  s    doe}55 		0!}} aLLq))t!}} $$,!6!6LO?&&q$///ri   c           	        	 ddl m} |j        }t          |t                    r|                    dd          }t          t          |           } j        j	        j
        }t          d |j        D                       t          t          |t          t          |                               fd	t          t          	fd|D                        } j        rt#          |          r ||          }d t          | D             }nl|                                } j        j	        }t          t          |t          t          |                               fd	t%          |          D             }|S )
Nr   )sparsify_labelsF)r%  r   c              3  $   K   | ]}|j         V  d S r   )is_floating)r~   levels     rg   r   zBDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>  s%      %T%TEe&7%T%T%T%T%T%Tri   c                8    |j         vr|          rsd|z   S |S )N )r"  )r   yneed_leadsprestrict_formattingrf   s     rg   space_formatzEDataFrameFormatter._get_formatted_column_labels.<locals>.space_format  s4    T_,,#A -/ - 7Nri   c              3  8   K   | ]fd D             V  dS )c                (    g | ]} |          S r{   r{   )r~   r  r  r   s     rg   r   zMDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>.<listcomp>  s%    555a||Aq))555ri   Nr{   )r~   r   r  s    @rg   r   zBDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>  s<      KK!555551555KKKKKKri   c                ,    g | ]}t          |          S r{   )r{  r~   r   s     rg   r   zCDataFrameFormatter._get_formatted_column_labels.<locals>.<listcomp>  s    >>>q477>>>ri   c                `    g | ]*\  }}                     |          s|         rd |z   n|g+S )r  )r  )r~   r   r   r  rf   s      rg   r   zCDataFrameFormatter._get_formatted_column_labels.<locals>.<listcomp>  sT       Aq !% 3 3A 6 6P;q>PqqQ  ri   )pandas.core.indexes.multir  r  r   r4   r   r{  ra  r  dtypesr   r   levelsrV  mapr&   r%  rn   r  )
rf   r  r  r  fmt_columnsr  r  r  r  r  s
   `      @@@rg   r  z/DataFrameFormatter._get_formatted_column_labels  s   ======-gz**  	!..%.FFKsK011KZ&.F #&%T%TW^%T%T%T"T"Ts;4Df0M0MNNOOK       KKKK{KKKL K } ;[!1!1 ;-ok::>>C,=>>>KK!..**KZ&Fs;4Df0M0MNNOOK    %k22  K
 ri   c                &    d  j                                         D             |j        }|j        }                     d          }t          |t                    r$|                     j        d j	        |          }n|                     j	        |          g} fd|D             }  j
        j        dg|R                      d          } j        rd	                                  D             }nd
g|j        z  } j        r||z   S |S )Nc                @    i | ]\  }}|t          t          |          S r{   )r   r   )r~   kvs      rg   r^  z;DataFrameFormatter._get_formatted_index.<locals>.<dictcomp>  s&    HHHAQS!HHHri   	__index__F)r%  r   r   r  )r   r  c                    g | ]H}t          t          t          |          d                     dd          j                            IS )rK   rd   r   )rN   r  r   )r|  r  r{  r   r   )r~   r   r  rf   s     rg   r   z;DataFrameFormatter._get_formatted_index.<locals>.<listcomp>  sf     
 
 
  !GGVY]]2q5I5Itx   
 
 
ri   r   rm   c                ,    g | ]}t          |          S r{   r^   r  s     rg   r   z;DataFrameFormatter._get_formatted_index.<locals>.<listcomp>  s    GGGQ#a&&GGGri   rd   )r  itemsr   r  r  r   r4   r   r%  rM  r   r   splitrO  _get_column_name_listnlevelsr   )	rf   r  r   r  fmtr   adjoined
col_headerr  s	   `       @rg   r   z'DataFrameFormatter._get_formatted_index  sT    IH1E1E1G1GHHH	-!!+..eZ(( 	T-	 %  II 4+BcRRSI
 
 
 
 
 
 
 
	 #48?11y11177== " 	0GG$*D*D*F*FGGGJJ/J; 	((Ori   list[Hashable]c                    g }| j         j        }t          |t                    r%|                    d |j        D                        n#|                    |j        dn|j                   |S )Nc              3  "   K   | ]
}|dn|V  d S rc   r{   r   s     rg   r   z;DataFrameFormatter._get_column_name_list.<locals>.<genexpr>  s*      PP$t|PPPPPPri   rd   )r  r  r   r4   extendr   r   r   )rf   r   r  s      rg   r  z(DataFrameFormatter._get_column_name_list  sn     "*$gz** 	GLLPP'-PPPPPPPLLw|3FFFri   )NNTTrW   NNNNTNNNFr  FT)&r  rH   r  r  r  r   r   r!  r   r\   r]   r^   r"  r#  rN   r   rt   r$  r%  r&  r'  r\   r   r   r   r   r  r   r  r   r(  r^   r)  r\   r*  r\   r`   ra   )r`   r7  r`   r\   r   )r`   r   )r%  r&  r`   r\   )r"  r#  r`   rD   )rN   r   r`   r^   )r  r  r`   r3   )r  r   r`   r@   )r`   r   )r   r   r`   r   r   )r   r   r`   rr   )r   r  r`   r  )r  rH   r`   r7  )r  rH   r`   rr   )r`   r  )(r   r   r   __doc__rJ   rT   rh   r<  propertyr?  r>  rA  r   rE  rH  rJ  rM  rO  rQ  r0  r.  r/  r,  r-  r2  r4  rh  rc  rd  rg  rf  r   rv  rw  r9  r  r  r  r   r  r{   ri   rg   r  r  .  s       EE (ggbG"222G
  $,0#',0"/3 $ ###&+'-$ -$ -$ -$ -$^
 
 
 
 
 
 
 X

 T T T XT Y Y Y XY W W W XW S S S XS , , , X, . . . X. N N N XN P P P XP F F F XF   
      & & & &   0	! 	! 	! 	!/ / / /&   > > > >P P P PI I I I   ( ( ( (" " " "4" " " "$- - - -^
 
 
 

0 
0 
0 
0' ' ' 'R& & & &P     ri   r  c                  l    e Zd ZdZd5dZ	 	 	 	 	 	 	 d6d7dZ	 	 	 d8d9dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d:d;d4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.
    r  r  r`   ra   c                    || _         d S r   )r  )rf   r  s     rg   rh   zDataFrameRenderer.__init__  s    ri   NFrY   "FilePath | WriteBuffer[str] | Noner   r   classesstr | list | tuple | Nonenotebookr\   borderint | bool | Nonetable_idrender_linksc                    ddl m}m}	 |r|	n|}
 |
| j        ||||          }|                                }t          |||          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)r  r  r  r  rY   r   )pandas.io.formats.htmlr  r  r  r   save_to_buffer)rf   rY   r   r  r  r  r  r  r  r  Klasshtml_formatterstrings                rg   to_htmlzDataFrameRenderer.to_html  s    D	
 	
 	
 	
 	
 	
 	
 	

 &.@!!=H%
 
 
  ))++f#AAAAri   r  r   c                ~    ddl m}  || j        |          }|                                }t	          |||          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  r  )pandas.io.formats.stringr  r  r   r  )rf   rY   r   r  r  string_formatterr  s          rg   r   zDataFrameRenderer.to_string5  sS    ( 	=<<<<<*?48
KKK!++--f#AAAAri   ,winfer"Tstrictpath_or_buf7FilePath | WriteBuffer[bytes] | WriteBuffer[str] | Nonesepr^   r  Sequence[Hashable] | Noneindex_labelIndexLabel | Noner   compressionrA   re   	quotecharlineterminator	chunksizedate_formatdoublequote
escapecharerrorsstorage_optionsStorageOptions | Nonec                f   ddl m} |d}t                      }nd} |di d|d|
d|d	|d
|d|d|d|d|d|d|d|	d|d|d|d|d| j        }|                                 |rAt          |t                    sJ |                                }|                                 |S dS )z;
        Render dataframe as comma-separated file.
        r   )CSVFormatterNTFr  r  r  r   r  r  re   rZ  r  r   r  r  r  r  r  r  r  r{   )pandas.io.formats.csvsr  r   r  saver   getvalueclose)rf   r  r   r  r  r  r   r  re   r  r  r  r  r  r  r  r  r  created_buffercsv_formattercontents                        rg   to_csvzDataFrameRenderer.to_csvO  sp   , 	877777!N"**KK"N$ 
 
 
#
)>
 
 X	

 6
 $
 G
 
 $
 
  i
  i
 $
 $
 "z
  ,O!
" hh#
& 	 	k844444!**,,GNtri   )r  r  r`   ra   )NNNFNNF)rY   r  r   r   r  r  r  r\   r  r  r  r   r  r\   r`   r   )NNN)rY   r  r   r   r  r   r`   r   )NNr  NNr  r  Nr  NNNTNr  N)"r  r  r   r   r  r^   r  r  r  r  r   r^   r  rA   re   r   r  r^   r  r   r  r   r  r   r  r\   r  r   r  r^   r  r  r`   r   )r   r   r   r  rh   r  r   r  r{   ri   rg   r  r    s             
 37#-1$(#"1B 1B 1B 1B 1Bj 37#!%	B B B B B8 PT#-1)-*1"%) $"& !%15#9 9 9 9 9 9 9ri   r  r  r^   rY   r  r   r   c                    t          ||          5 }|                    |            | |                                cddd           S 	 ddd           dS # 1 swxY w Y   dS )zQ
    Perform serialization. Write to buf or return as string if buf is None.
    )r   N)
get_bufferwriter  )r  rY   r   fs       rg   r  r    s     
C(	+	+	+ q	;::<<	       
                  s   +A
AAAIGenerator[WriteBuffer[str], None, None] | Generator[StringIO, None, None]c              #    K   | t          |           } nt                      } |d}n$t          | t                    st	          d          t          | d          r| V  dS t          | t                    rNt          t          |                      t          | d|d          5 }|V  ddd           dS # 1 swxY w 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  r  rd   )r   newlinez1buf is not a file name and it has no write method)	r;   r   r   r^   rW  hasattrr:   open	TypeError)rY   r   r  s      rg   r  r    s1      S!!jjS!! NLMMMsG M 						C		 	Ms3xx(((#sXr::: 	a
 GGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 KLLLs   &B88B<?B<rW   rL   r  Tr   r   r  r  rt   r$  r]   digitsr   r   str | int | NonerN   r(  r   r&  re   fallback_formatterrr   c                H   t          j        | j        d          rt          }nt	          | j        t
                    rt          }nt          j        | j        d          rt          }nmt	          | j        t                    rt          }nKt          j        | j        d          rt          }n)t          j        | j        d          rt          }nt          }|d}|t          d          }|t          d          } || |||||||||	|
	          }|                                S )
a{  
    Format an array for printing.

    Parameters
    ----------
    values
    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._format_native_types), we don't want the
        leading space since it should be left-aligned.
    fallback_formatter

    Returns
    -------
    List[str]
    MmfciuN   r   display.precision)
r  r]   rt   r  r   rN   r(  r   re   r  )r   is_np_dtyper   Datetime64Formatterr   r)   Datetime64TZFormatterTimedelta64Formatterr*   ExtensionArrayFormatterFloatArrayFormatterIntArrayFormatterGenericArrayFormatterr   
get_result)r   r  rt   r]   r  r   rN   r(  r   re   r  	fmt_klassfmt_objs                rg   ru   ru     s0   R v|S)) *'			FL/	2	2 *)			s	+	+ 	*(			FL.	1	1 *+			t	,	, *'			t	,	, *%		)	}!"899~/00i!#-  G ri   c                  >    e Zd Z	 	 	 	 	 	 	 	 	 	 	 d#d$dZd%d!Zd%d"ZdS )&r     NrW   r  rL   r  Tr   r   r  r   r  r  r]   r^   r   r  rt   r$  rN   r(  re   r   fixed_widthr\   r   r&  r  r`   ra   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        d S r   )r   r  r]   r   r  rt   rN   r(  re   r  r   r  )rf   r   r  r  r]   r   rt   rN   r(  re   r  r   r  s                rg   rh   zGenericArrayFormatter.__init__  sb     
"(&*"4ri   rr   c                T    |                                  }t          || j                  S r   )_format_stringsr  rN   )rf   r   s     rg   r  z GenericArrayFormatter.get_result0  s%    ))++
 T\:::ri   c                     j         &t          d          }|t          d          fd}n j         } j         j        nD j         j        n5 j        d uo j        t
          k    }t          t          j        d|           fd}t           j
        d          }t          |t          j                  st          d	          t          j        |t"                    }|t          j        t'          |          t)          t+          d
t-          |j                                                z  } j        }||                                }g }t5          |          D ]\  }	}
||	         r j        $|r"|                    d ||
                      8||	         r|                     ||
                     _|du rd}nd}|                    |                     ||
                               |S )Nr   r  c                0    t          | ddd          S )Nz .dr  )_trim_zeros_single_float)r   	precisions    rg   <lambda>z7GenericArrayFormatter._format_strings.<locals>.<lambda>9  s)    )A+I+++++* * ri   r   )r   quote_stringsc                   j         ~t          |           rot          |           r`	 | dS | t          u rt	          t                    S | t
          u st          j        |           rdS n# t          t          f$ r Y nw xY wj         S t          | t                    rt	          |           S t          | t                    rt          |           S t	           |                     S )Nra   r   )r]   r'   r+   r   r^   r   npisnatr  rW  r   r1   r0   repr)r   r  rf   s    rg   _formatz6GenericArrayFormatter._format_strings.<locals>._formatK  s    {&9Q<<&DGG& y%vb"2wwcRXa[[$u "!:.   D {"A|,, )1vvA{++ )Aww 99Q<<(((s   A) A) 	A) )A=<A=Textract_numpyz<ExtensionArray formatting should use ExtensionArrayFormatterr   ry  r  Fz{v}z {v})r  )rt   r   r  r  re   r
   r   r<   r   r2   r   r   r)  ndarrayr  r   	map_inferr#   rL  r,   r|  rangern   shaper   r   r  r   r   )rf   rt   r'  r,  valsinferredis_float_typer   r   r   r  tplr  r%  s   `           @@rg   r   z%GenericArrayFormatter._format_strings4  sU   $%&<==L#&':;;	         ,L>%II$0/II L4S9SM%/+  I	) 	) 	) 	) 	) 	). T[===$
++ 	N   =x00fU4[[uU1c$*oo-F-F'G'GHHHI 	
 * )--//M
dOO 	< 	<DAq!!$ <(B(B!!"2ggajj"2"23333q! 	<!!,,q//2222 E))  CC C!!#**wwqzz*":":;;;;ri   )r  NrW   r  NrL   r  NTTN)r   r   r  r   r  r  r]   r^   r   r  rt   r$  rN   r^   r(  r^   re   r   r  r\   r   r&  r  r  r`   ra   r   )r   r   r   rh   r  r   r{   ri   rg   r  r    s~         %)/3" %).25 5 5 5 58; ; ; ;L L L L L Lri   r  c                  >     e Zd Zd fdZ	 	 ddd
ZddZddZ xZS )r  r`   ra   c                     t                      j        |i | | j        7| j        2d| _        t          | j                  r| j        | _        d | _        d S d S d S d S NF)r   rh   rt   r  r  callable)rf   argsr   r   s      rg   rh   zFloatArrayFormatter.__init__  s|    $)&))) (T^-C$D)** )!%!2$(!!! )(-C-C) )ri   Nrt   r$  	thresholdfloat | Noner   c                |      j         r fdn fd j        dk    r fdnS  fd}|S )z;Returns a function to be applied on each value to format itNc                P    J t          |           r |           nj        S )N)value)r,   r]   )r  rt   rf   s    rg   base_formatterz<FloatArrayFormatter._value_formatter.<locals>.base_formatter  s;    #/// Qxx%LLq))))ri   c                N    t          |           rt          |           nj        S r   )r,   r^   r]   )r  rf   s    rg   rA  z<FloatArrayFormatter._value_formatter.<locals>.base_formatter  s     !&q:s1vvvt{:ri   r  c                N     |                                dj        d          S )Nr  r   )replacer(  )r  rA  rf   s    rg   decimal_formatterz?FloatArrayFormatter._value_formatter.<locals>.decimal_formatter  s'    %~a((00dlAFFFri   c                    t          |           r)t          |           k    r |           S  d          S j        S )Ng        )r,   absr]   )r@  rE  rf   r<  s    rg   r  z7FloatArrayFormatter._value_formatter.<locals>.formatter  sL    U|| #u::	)),,U333,,S111{"ri   )rt   r(  )rf   rt   r<  r  rA  rE  s   ``` @@rg   _value_formatterz$FloatArrayFormatter._value_formatter  s     ,L  	;	 	 	 	 	 	 	; ; ; ; ; <3G G G G G G G !/$$	# 	# 	# 	# 	# 	# 	# ri   
np.ndarrayc                   
 dddd
 j           j         j          j                  S  j        rt	          d
          nd	
 fd} j        9 j        r* j        du rd}nd}t          |j         j	                  }n j        }n fd} ||          } j        s|S t          |          dk    r(t          d |D                       }| j	        dz   k    }nd}t          j         j                  }|dk                                    }|d j	         z  k     |dk    z                                  }	|	s|r6|r4 j        du rd}nd}t          |j         j	                  } ||          }|S )z
        Returns the float values converted into strings using
        the parameters given at initialisation, as a numpy array
        r   r=   r  r   r]   r^   c                    t          |           }t          j        fdt          |                                 |                                          D                                           | j                  }|S )Nc                4    g | ]\  }}|s |          nS r{   r{   )r~   valr  r  r]   s      rg   r   zWFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_rep.<locals>.<listcomp>  s>       Q +,7IIcNNN  ri   )r+   r)  arrayra  ravelreshaper2  )r   r  r]   mask	formatteds    ``  rg   format_with_na_repzCFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_rep  s    <<D    "%fllnndjjll"C"C   
 gfl##  ri   c                .   t          j        |                                           }t          j        |                                           }t	          |          t	          |          }}g }t          |                                 ||||          D ]\  }}	}
}}|s!|s|                     ||                     +|s%|                     ||	           d| d           R|si ||
                                          }|                    d          r|                    | | d           |                    | d| d           |                    | d| d           t          j	        |          
                    | j                  S )N+j-)r)  realrO  imagr+   ra  r   r|   
startswithrN  rP  r2  )r   r  r]   real_valuesimag_values	real_mask	imag_maskformatted_lstrM  real_valimag_valre_isnaim_isnaimag_formatteds                 rg   format_complex_with_na_repzKFloatArrayFormatter.get_result_as_array.<locals>.format_complex_with_na_rep  s    '&////11K'&////11K#'#4#4d;6G6GyIM=@> > @ @9Xx'  @w @!((38888  
@!((IIh,?,?)K)K&)K)K)KLLLL  @%.Yx%8%8%>%>%@%@N%0055 L%,,-I-I-I-IJJJJ%,,-J-J-J-J-JKKKK!((F)>)>V)>)>)>????8M**226<@@@ri   Nzdisplay.chop_thresholdc                f                        | 	          }j        dk    r
dj        z   nj        }j        }t	          |          }|r |||          }n |||          }j        rC|rt          |j                  }nt          |j                  }t          j
        |d          S |S )NrK   r  objectr   )rH  rN   r]   r   r"   r  _trim_zeros_complexr(  _trim_zeros_floatr)  asarray)
rt   r  r]   r   
is_complexr   re  rS  rf   r<  s
         rg   format_values_withzCFloatArrayFormatter.get_result_as_array.<locals>.format_values_with  s    --lIFFI +/,&*@*@S4;&&dkF [F)&11J  G33FIvNN++FIvFF : E0FFFF.vt|DDFz&9999Mri   Tz{value: .{digits:d}f}z{value:.{digits:d}f})r  c                    j         | z  S r   )rt   )r@  rf   s    rg   r&  z9FloatArrayFormatter.get_result_as_array.<locals>.<lambda>&  s    ):U)B ri   r   c              3  4   K   | ]}t          |          V  d S r   r   r  s     rg   r   z:FloatArrayFormatter.get_result_as_array.<locals>.<genexpr>2  s(      ::AQ::::::ri      Fg    .A
   z{value: .{digits:d}e}z{value:.{digits:d}e})r   r=   r  r   r]   r^   )r  r   r]   r  r   rt   r   r   r   r  rn   r  r)  rG  r   )rf   rm  fmt_strrt   formatted_valuesmaxlentoo_longabs_valshas_large_valueshas_small_valuesre  rS  r<  s   `         @@@rg   get_result_as_arrayz'FloatArrayFormatter.get_result_as_array  s   	 	 	 		A 	A 	A 	A: >%%%dk4>4;OOO 	"#;<<III	 	 	 	 	 	 	 	< $ 1%--5GG4G&w~dkJJJ#0BBBBL--l;; 	$##   1$$::)9:::::Fa/HHH6$+&& %sN//11%|(<<ANSSUU 	@ 	@-= 	@!T))10"7>$+FFFL11,??ri   rr   c                D    t          |                                           S r   )r{  ry  rw   s    rg   r   z#FloatArrayFormatter._format_stringsH  s    D,,..///ri   r   NN)rt   r$  r<  r=  r`   r   )r`   rI  r   )r   r   r   rh   rH  ry  r   r  r  s   @rg   r  r    s        
) 
) 
) 
) 
) 
) 04"&6 6 6 6 6p~  ~  ~  ~ @0 0 0 0 0 0 0 0ri   r  c                      e Zd ZddZdS )r  r`   rr   c                `    | j         du rd }nd }| j        p|fd| j        D             }|S )NFc                2    | d                     |           S )Nr#  r   r   r  s    rg   r&  z3IntArrayFormatter._format_strings.<locals>.<lambda>O  s    hhooo&:&: ri   c                2    | d                     |           S )Nz dr  r  r  s    rg   r&  z3IntArrayFormatter._format_strings.<locals>.<lambda>Q  s    ii&6&6&6&;&; ri   c                &    g | ]} |          S r{   r{   r~   r   r  s     rg   r   z5IntArrayFormatter._format_strings.<locals>.<listcomp>S  s!    888qiill888ri   )r   r  r   )rf   formatter_strr   r  s      @rg   r   z!IntArrayFormatter._format_stringsM  sP    &&::MM;;MN3m	8888DK888
ri   Nr   r   r   r   r   r{   ri   rg   r  r  L  s(             ri   r  c                  .     e Zd Z	 	 dd fd
ZddZ xZS )r  r   Nr   3np.ndarray | Series | DatetimeIndex | DatetimeArraynat_repr^   r  ra   r`   c                X     t                      j        |fi | || _        || _        d S r   )r   rh   r  r  )rf   r   r  r  r   r   s        rg   rh   zDatetime64Formatter.__init__X  s9     	**6***&ri   rr   c                      j         }t          |t                    st          |          } j        "t	           j                  r fd|D             S |j                             j         j                  }|	                                S )z&we by definition have DO NOT have a TZNc                :    g | ]}                     |          S r{   )r  r  s     rg   r   z7Datetime64Formatter._format_strings.<locals>.<listcomp>k  s%    666!DNN1%%666ri   )r]   r  )
r   r   r7   r  r:  _data_format_native_typesr  r  tolist)rf   r   r   s   `  rg   r   z#Datetime64Formatter._format_stringsc  s    &-00 	+"6**F>%(4>*B*B%6666v6666\66<T-= 7 
 

   """ri   r   N)r   r  r  r^   r  ra   r`   ra   r   r   r   r   rh   r   r  r  s   @rg   r  r  W  s^          		' 	' 	' 	' 	' 	' 	'# # # # # # # #ri   r  c                      e Zd ZddZdS )r  r`   rr   c                t   t          | j        d          }| j        }d }||                    d          }t	          |t
                    r|                                }nt          j        |          }t          ||| j
        | j        | j        | j        | j        | j        | j        | j        |          }|S )NTr-  )boxed)	rt   r]   r  r   rN   r(  r   re   r  )r2   r   r  
_formatterr   r-   rv   r)  rk  ru   rt   r]   r  r   rN   r(  r   re   )rf   r   r  r  rN  r   s         rg   r   z'ExtensionArrayFormatter._format_stringst  s    t{$???N	!!'!2!2!2!>!>fk** 	'//11EEJv&&E!*;;*LL,L1
 
 

 ri   Nr   r  r{   ri   rg   r  r  s  s(             ri   r  percentilesnp.ndarray | Sequence[float]c                   t          j        |           } t          |           r0t          j        | dk              rt          j        | dk              st	          d          d| z  } |                                                     t                    }t          j        ||           }t          j        |          r&|                    t                    }d |D             S t          j
        |           }|d         dk    r|d         nd}|d         dk     rd|d         z
  nd}t          j        t          j        t          j        t          j        |||                                                            t                     }t          d|          }t          j        | t"          	          }| |                                                             t                                        t                    ||<   | |                              |                              t                    || <   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   r   z/percentiles should all be in the interval [0,1]d   c                    g | ]}|d z   S %r{   r}   s     rg   r   z&format_percentiles.<locals>.<listcomp>  s    %%%AC%%%ri   N)to_beginto_endrh  c                    g | ]}|d z   S r  r{   r}   s     rg   r   z&format_percentiles.<locals>.<listcomp>  s    !!!AG!!!ri   )r)  rk  r&   rL  rW  roundastyper   iscloser^   uniquefloorlog10r   ediff1dr  
empty_likerg  )r  percentiles_round_typeint_idxoutunique_pctsr  r  precs           rg   format_percentilesr    s   D *[))K [))LvkQ&''L vkQ&''L
 JKKK#K(..0077<<j/==G	vg &$++C00%%%%%%)K((K!,Q!!3!3{1~~H&1"o&;&;S;r?""F H

;&QQQRRSS fSkkD q$<<D
-6
2
2
2Cw'--//66s;;BB3GGCL)//55<<SAACM!!S!!!!ri   2np.ndarray | DatetimeArray | Index | DatetimeIndexr\   c                   t          | t                    s|                                 } t          | t          t          f          st	          |           } | j        dS | j        }|t          k    }t          | j	                  }t          |          }t          j        |||z  dk                                              dk    }|rdS dS )NFr   T)r   r3   rO  r.   r7   tzasi8r   r   r   r    r)  logical_andr   )r   
values_intconsider_valuesresoppd	even_dayss         rg   is_dates_onlyr    s    fe$$  f}m<== 'v&&yuJ D(O v|,,D
$

C 
S0@A0EFFJJLLPQQI t5ri   r   r   NaTType | Timestampr  c                6    | t           u r|S t          |           S r   )r   r^   r   r  s     rg   _format_datetime64r    s    Cxx q66Mri   r  c                l    t          | t                    r|S |r|                     |          S | j        S r   )r   r!   strftime
_date_repr)r   r  r  s      rg   _format_datetime64_dateonlyr    s?    
 !W  zz+&&& |ri   is_dates_only_r   c                     | rfdS fdS )z]Return a formatter callable taking a datetime64 as input and providing
    a string as outputc                (    t          |           S )N)r  r  )r  )r   r  r  s    rg   r&  z'get_format_datetime64.<locals>.<lambda>  s    4wK
 
 
 ri   c                &    t          |           S )N)r  )r  r  s    rg   r&  z'get_format_datetime64.<locals>.<lambda>  s    +Aw??? ri   r{   )r  r  r  s    ``rg   get_format_datetime64r    s?      @
 
 
 
 
 	
 @????ri   *np.ndarray | DatetimeArray | DatetimeIndexc                    t          | t          j                  r| j        dk    r|                                 } t          |           }|r|pdS |S )z6given values and a date_format, return a string formatr   z%Y-%m-%d)r   r)  r/  ndimrO  r  )r   r  idos      rg   !get_format_datetime64_from_valuesr    sW     &"*%%  &+// 


C
 )(j(ri   c                      e Zd ZddZdS )r  r`   rr   c                    t          | j                  }| j                            t                    }| j        pt          || j                  fd|D             }|S )zwe by definition have a TZ)r  c                &    g | ]} |          S r{   r{   r  s     rg   r   z9Datetime64TZFormatter._format_strings.<locals>.<listcomp>.  s!    333qiill333ri   )r  r   r  rg  r  r  r  )rf   r  r   r   r  s       @rg   r   z%Datetime64TZFormatter._format_strings'  sn    DK((##F++N 
&;T-'
 '
 '
	 4333F333
ri   Nr   r  r{   ri   rg   r  r  &  s(        	 	 	 	 	 	ri   r  c                  .     e Zd Z	 	 dd fdZddZ xZS )r  r   Fr   np.ndarray | TimedeltaIndexr  r^   boxr\   r`   ra   c                X     t                      j        |fi | || _        || _        d S r   )r   rh   r  r  )rf   r   r  r  r   r   s        rg   rh   zTimedelta64Formatter.__init__4  s6     	**6***ri   rr   c                z    | j         p t          | j        | j        | j                  fd| j        D             S )N)r  r  c                &    g | ]} |          S r{   r{   r  s     rg   r   z8Timedelta64Formatter._format_strings.<locals>.<listcomp>C  s!    222		!222ri   )r  get_format_timedelta64r   r  r  )rf   r  s    @rg   r   z$Timedelta64Formatter._format_strings?  sL    N 
&<K48'
 '
 '
	 3222dk2222ri   r   F)r   r  r  r^   r  r\   r`   ra   r   r  r  s   @rg   r  r  3  s^         		 	 	 	 	 	 	3 3 3 3 3 3 3 3ri   r  F,np.ndarray | TimedeltaIndex | TimedeltaArraystr | floatr  c                   
 |                      t          j                  }|t          k    }d}||z  dk    }t          j        ||          }|                                dk    }|rd
nd

f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
    l     "R: r   Nlongc                    | t          |           rt          |           rS t          | t                    st          |           } |                               }rd| d}|S )Nr  ')r'   r+   r   r   
_repr_base)r   r   r  r   r  s     rg   r  z*get_format_timedelta64.<locals>._formattere  sm    919$q''9N!Y'' 	!A V,, 	#"]]]Fri   )viewr)  int64r   r  r   )r   r  r  r  r  one_day_nanosnot_midnightbothr  r  r   s    ``       @rg   r  r  F  s     RX&&J D(O!M-2L >/<88D

aI        ri   r  r  r   TextAdjustment | Nonec                R   t          |           dk    s|dk    r| S |t                      n|t          fd| D                       |t          |          t          d          k    rdfdfd	| D             }                     | |
          }|S )Nr   rL  c              3  B   K   | ]}                     |          V  d S r   r   )r~   r   
adjustments     rg   r   z$_make_fixed_width.<locals>.<genexpr>  s/      55*..##555555ri   r  r   r^   r`   c                l    0dk                         |           k    z  r| d dz
           dz   } | S )Nr   r   r   )r   r  conf_maxr   s    rg   justz_make_fixed_width.<locals>.just  sG    1!2!2W!<= -m!m$u,ri   c                &    g | ]} |          S r{   r{   )r~   r   r  s     rg   r   z%_make_fixed_width.<locals>.<listcomp>  s!    (((1ttAww(((ri   r   )r   r^   r`   r^   )rn   r   r  r   rN   )	r  rN   r  r   r   r  r  r  r   s	        @@@@rg   r  r  u  s     7||qGu,,
{#%%


5555W55555Ggw''011H( 2 2        )((((((Gw??FMri   str_complexesrI  c                  	 g g }}| D ]w}t          j        d|          }|                    d                    |dd                              |                    d                    |dd                              xt	          |           }t          ||z   |          }t	          |          dk    rg S t          d |D                       dz
  		f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+-])rd   Nr   c              3  4   K   | ]}t          |          V  d S r   r   )r~   parts     rg   r   z&_trim_zeros_complex.<locals>.<genexpr>  s(      ;;dD		;;;;;;ri   r   c                R    g | ]#\  }}||d          z   |dd         d z   dz   $S )r   r   N>rV  r{   )r~   real_ptimag_ptpadded_lengths      rg   r   z'_trim_zeros_complex.<locals>.<listcomp>  sc       
 GW	 	
!*	QRR[
+=
+
+
+	, 	  ri   )rer  r   r   rn   rj  r  ra  )
r  r(  	real_part	imag_partr   trimmednpadded_partspaddedr  s
            @rg   ri  ri    s,   
 ryI 2 2
 (:q))"..///B001111
 	MA$Y%:GDDL
<A	;;l;;;;;a?M   
 !$L!$4l1226F G G  F Mri   	str_floatc                d    |                      d          } |                     d          r| dz  } | S )zX
    Trims trailing zeros after a decimal point,
    leaving just one if necessary.
    0r  )rstripendswith)r  s    rg   r$  r$    s=    
   %%I# S	ri   
str_floatsnp.ndarray | list[str]c                    | }t          j        d d          dfddfd} ||          rfd	|D             } ||          f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                2    t          j        |           d uS r   )r  match)r   number_regexs    rg   is_number_with_decimalz1_trim_zeros_float.<locals>.is_number_with_decimal  s    xa((44ri   r   r  c                x    fd| D             }t          |          dk    ot          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                *    g | ]} |          |S r{   r{   r~   r   r  s     rg   r   z:_trim_zeros_float.<locals>.should_trim.<locals>.<listcomp>  s*    BBB(>(>q(A(AB1BBBri   r   c              3  @   K   | ]}|                     d           V  dS )r  Nr   r  s     rg   r   z9_trim_zeros_float.<locals>.should_trim.<locals>.<genexpr>  s,      'I'IA

3'I'I'I'I'I'Iri   )rn   rL  )r   numbersr  s     rg   should_trimz&_trim_zeros_float.<locals>.should_trim  sL     CBBBfBBB7||aIC'I'I'I'I'I$I$IIri   c                >    g | ]} |          r
|d d         n|S )Nr  r{   r
  s     rg   r   z%_trim_zeros_float.<locals>.<listcomp>  s6    OOO!33A66=1SbS66AOOOri   c                ^    g | ])} |          r|                               r|d z   n|*S )r  r  )r~   r   r(  r  s     rg   r   z%_trim_zeros_float.<locals>.<listcomp>  sR        *)!,,KG1D1DKC!  ri   r  )r   r  r`   r\   )r  compile)r  r(  r  r  r   r  r  s    `   @@rg   rj  rj    s     G:C7CCCDDL5 5 5 5 5 5	J 	J 	J 	J 	J 	J +g

 POOOOwOOO +g

 P      F Mri   r   r3   c                d    t          | t                    rt          j        | j         S | j        d uS r   )r   r4   comany_not_noner   r   )r   s    rg   rG  rG    s1    %$$ &--z%%ri   c                      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	 d1d2d,Zd3d0Zd$S )4EngFormatterzl
    Formats float values according to engineering format.

    Based on matplotlib.ticker.EngFormatter
    ir  iziair  ipir  iur  r   rd   r   r  rp  r
  	   Gr  T   P   E   Z   YNFaccuracyr   use_eng_prefixr\   r`   ra   c                "    || _         || _        d S r   r'  r(  )rf   r'  r(  s      rg   rh   zEngFormatter.__init__  s     !,ri   numfloatr^   c                ,   t          t          |                    }t          j        |          rdS t          j        |          rdS d}|dk     rd}| }|dk    rGt          t	          t          j        |                                dz            dz                      }nt          d          }|                    t          | j
                                                            }|	                    t          | j
                                                            }t	          |          }| j        r| j
        |         }n|dk     rd| d}nd	|d}||z  d
|z  z  }| j        d}nd| j        d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
        rW   infr   r   r  r   zE-02dzE+rq  Nz{mant: g}{prefix}z{mant: .r#  z
f}{prefix})mantprefix)r   r^   is_nanis_infiniter   mathr  r  r   r  ENG_PREFIXESr`  r(  r'  r   )
rf   r+  dnumsignpow10	int_pow10r1  r0  
format_strrR  s
             rg   __call__zEngFormatter.__call__  s   ( s3xx  >$ 	5t$$ 	5!88D5D199C
4::<<!+; < <q @AABBEEAJJE		#d/44667788		#d/44667788JJ	 	*&y1FF]]*9****FF)))))Fd{b%i(= ,JJCT]CCCCJ%%4%??	ri   r9  )r'  r   r(  r\   r`   ra   )r+  r,  r`   r^   )r   r   r   r  r5  rh   r;  r{   ri   rg   r  r    s!        SS 	S 	S	
 	S 	C 	C 	C 	
2 	
3 	
3 	
3 	C 	C 	C  	C!" 	C#L* CH- - - - -; ; ; ; ; ;ri   r  r   r'  r   r(  ra   c                B    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
    r   N)r   r  r*  s     rg   set_eng_float_formatr=  O  s&    n %|Hn'M'MNNNNNri   rd   r  sentinelbool | object | strlist[dict[int, int]]c                2   t          |           dk    rg S dgt          | d                   z  }g }| D ]c}d}i }t          |          D ]#\  }}||         r||k    rd||<   ||z
  ||<   |}$t          |          |z
  ||<   |                    |           d|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)rn   r  r   )	r  r>  controlr   r  
last_indexlengthsr   keys	            rg   get_level_lengthsrF    s    $ 6{{a	fs6!9~~%GF  
&& 	 	FAsqz cXoo"
&'*n
#

!%jj:5
gMri   WriteBuffer[str]linesc                    t          d |D                       rd |D             }|                     d                    |                     dS )z
    Appends lines to a buffer.

    Parameters
    ----------
    buf
        The buffer to write to
    lines
        The lines to append.
    c              3  @   K   | ]}t          |t                    V  d S r   )r   r^   r  s     rg   r   z#buffer_put_lines.<locals>.<genexpr>  s,      
-
-!:a
-
-
-
-
-
-ri   c                ,    g | ]}t          |          S r{   r  r  s     rg   r   z$buffer_put_lines.<locals>.<listcomp>  s    '''AQ'''ri   rm   N)r   r  r   )rY   rH  s     rg   buffer_put_linesrL    sZ     
-
-u
-
-
--- ('''''IIdiiri   )r`   r   )r`   r  r{  )r  r^   rY   r  r   r   r`   r   r   )rY   r  r   r   r`   r   )	NrW   NNrL   r  TNN)r   r   r  r  rt   r$  r]   r^   r  r   r   r  rN   r^   r(  r^   r   r&  re   r   r  r  r`   rr   )r  r  r`   rr   )r   r  r`   r\   )r   )r   r  r  r^   r`   r^   r  )r   r  r  r^   r  r   r`   r^   )r  r\   r  r^   r  r   r`   r   )r   r  r  r   r`   r   r  )r   r  r  r  r  r\   r`   r   )rL   NN)
r  rr   rN   r^   r  r   r   r  r`   rr   )r  )r  rI  r(  r^   r`   rr   )r  r^   r`   r^   )r  r  r(  r^   r`   rr   )r   r3   r`   r\   )r   F)r'  r   r(  r\   r`   ra   )rd   )r  r   r>  r?  r`   r@  )rY   rG  rH  rr   r`   ra   )r  
__future__r   collections.abcr   r   r   r   r   
contextlibr	   csvr
   r   r(  r   	functoolsr   ior   r4  r  shutilr   typingr   r   r   r   r   r   unicodedatar   numpyr)  pandas._config.configr   r   pandas._libsr   pandas._libs.missingr   pandas._libs.tslibsr   r   r   r   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/   pandas.core.arrays.string_r0   pandas.core.baser1   pandas.core.commoncorecommonr  pandas.core.constructionr2   pandas.core.indexes.apir3   r4   r5   r6   pandas.core.indexes.datetimesr7   pandas.core.indexes.timedeltasr8   pandas.core.reshape.concatr9   pandas.io.commonr:   r;   r  r<   pandas._typingr=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   pandasrH   rI   rJ   __annotations___VALID_JUSTIFY_PARAMETERSrT   rV   r   r   r   r   r  r  r  r  r  r  ru   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ri  r$  rj  rG  r  r=  rF  rL  r{   ri   rg   <module>ro     s	     # " " " " "              & % % % % %                           				 $ $ $ $ $ $                ) ( ( ( ( (           
       # # # # # #                0 / / / / /                        
       
         
 3 2 2 2 2 2 ) ) ) ) ) )                   2 2 2 2 2 2            8 7 7 7 7 7 9 9 9 9 9 9 - - - - - -        ' & & & & &                                 9  9 9 9 9v      =& =& =& =& =& =& =& =&@]$ ]$ ]$ ]$ ]$ ]$ ]$ ]$@
 
 
 
 
 
 
 
 $9 $9 $9 $9 $9n $9 $9 $9N          B# # # #L} } } } } } } }@Z Z Z Z Z Z Z Z~ /3      DHM M M M MP ,0"!%*.O  O  O  O  O dm m m m m m m m`F0 F0 F0 F0 F0/ F0 F0 F0R    -   # # # # #/ # # #8    3   >B" B" B" B"J   2     "      KO@ @ @ @ @    
 
 
 
 
/ 
 
 
3 3 3 3 30 3 3 3* !, , , , ,b !%	    D    B	 	 	 	 8;! ! ! ! !H& & & &] ] ] ] ] ] ] ]@7O 7O 7O 7O 7Ov 24( ( ( ( (V           ri   