
    d>                      U d Z ddl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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l3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z> ddl?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZK ddlLmMZM ddlNmOZOmPZP ddlQmRZRmSZSmTZT ddlUmVZV ddlWmXZX ddlYmZc m[Z\ ddl]m^Z^ ddl_m`Z`maZambZbmcZc ddldmeZe ddlfmgZg ddlhmiZi ddljmkZkmlZl ddlmmnZn erddlompZpmqZq d Zrd!esd"<   d#Ztd$Zud!esd%<    G d& d'          Zv G d( d)          Zw G d* d+          Zx G d, d-ex          Zydd/Zzdd1Z{dd2Z| G d3 d4          Z} G d5 d6          Z~	 	 ddd=Ze	 ddd?            Z	 	 	 	 	 	 	 	 	 dddVZ G dW dX          Z G dY dZe          Z G d[ d\e          Z G d] d^e          Z G d_ d`e          ZddcZddfZdddkZ	 	 dddmZ	 dddpZddrZ G ds dte          Z G du dve          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)contextmanager)
QUOTE_NONEQUOTE_NONNUMERIC)Decimal)partial)StringION)get_terminal_size)IOTYPE_CHECKINGAnyCallableFinal	GeneratorHashableIterableListMappingSequencecast)east_asian_width)
get_option
set_option)lib)NA)NaT	Timedelta	Timestampget_unit_from_dtypeiNaTperiods_per_day)NaTType)	ArrayLikeAxesColspaceArgTypeColspaceTypeCompressionOptionsFilePathFloatFormatTypeFormattersType
IndexLabelStorageOptionsWriteBuffer)is_categorical_dtypeis_complex_dtypeis_datetime64_dtypeis_extension_array_dtypeis_floatis_float_dtype
is_integeris_integer_dtypeis_list_likeis_numeric_dtype	is_scalaris_timedelta64_dtype)DatetimeTZDtype)isnanotna)CategoricalDatetimeArrayTimedeltaArray)StringDtype)PandasObject)extract_array)Index
MultiIndexPeriodIndexensure_index)DatetimeIndex)TimedeltaIndex)concat)check_parent_directorystringify_path)printing)	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 : sequence, 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 )r]   r	   r^   rb   r`   rd   r   quoting)selfr]   r^   r`   rb   rd   s         T/var/www/html/t/fyr/venv311/lib/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 )Nri   , Length: 
)r`   lenr]   _repr_categories_inforc   )rk   rd   
level_infos      rl   _get_footerz CategoricalFormatter._get_footer   s}    ; 	9 $8T%5!6!6888F%;;==
  	dNF*6{{rn   	list[str]c                l    t          | j                                        d d | j        | j                  S )N)float_formatrb   rj   )format_arrayr]   _internal_get_valuesrb   rj   rk   s    rl   _get_formatted_valuesz*CategoricalFormatter._get_formatted_values   s;    1133;L
 
 
 	
rn   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   ri   c                6    g | ]}|                                 S  )strip.0is     rl   
<listcomp>z2CategoricalFormatter.to_string.<locals>.<listcomp>   s     444Aaggii444rn   rp   []rr   )r]   rs   rd   rv   r}   joinappendrc   )rk   r]   
fmt_valuesvaluesresultrd   s         rl   	to_stringzCategoricalFormatter.to_string   s    &{q  { '')))r//11
44444
:&&,$%; 	&%%''F &f%%%499V$$%%%rn   )NTr\   T)r]   r=   r^   r_   r`   ra   rb   rc   rd   ra   re   rf   re   rc   re   rw   )__name__
__module____qualname__rm   rv   r}   r   r   rn   rl   r[   r[      sw         #( ( ( ( (   "
 
 
 
& & & & & &rn   r[   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 )'SeriesFormatterNTr\   FseriesrN   r^   r_   r`   
bool | strheaderra   indexrb   rc   namery   
str | Nonedtypemax_rows
int | Nonemin_rowsre   rf   c                0   || _         ||nt                      | _        || _        || _        || _        || _        || _        |
| _        || _	        |t          d          }|| _        |	| _        t                      | _        |                                  d S )Ndisplay.float_format)r   r	   r^   r   rb   r   r`   r   r   r   r   ry   r   get_adjustmentadj_chk_truncate)rk   r   r^   r`   r   r   rb   r   ry   r   r   r   s               rl   rm   zSeriesFormatter.__init__	  s     /33xzz	
  %&<==L(
!##rn   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   rs   r   r   intminilocrI   
tr_row_num	tr_seriesis_truncated_vertically)rk   r   r   r   r   row_nums         rl   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'>$$$rn   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                  r*| j        j                                        }|r|dz  }||z  }t'          |          S )Nri   freqzFreq: Frp   	rr   )escape_charszName: Ttruncaterq   r   zdtype: rr   )r   r   getattrr   
isinstancerG   rE   rH   freqstrrL   pprint_thingr`   r   rs   r   r   r.   _valuesrt   rc   )rk   r   rd   series_name
dtype_nameru   s         rl   rv   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   455 	!/EEGGJ $j F6{{rn   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     rl   	<genexpr>z7SeriesFormatter._get_formatted_index.<locals>.<genexpr>q  s"      ;;td;;;;;;rn   T)names)r   )r   r   r   rD   anyr   formatr   )rk   r   have_header	fmt_indexs       rl   _get_formatted_indexz$SeriesFormatter._get_formatted_indexm  s{    $eZ(( 	0;;u{;;;;;K400II*D0K$//I+%%rn   rw   c                \    t          | j        j        d | j        | j        | j                  S )N)ry   rb   leading_space)rz   r   r   ry   rb   r   r|   s    rl   r}   z%SeriesFormatter._get_formatted_valuesx  s4    N"*;*
 
 
 	
rn   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..rR   moderi   rr   )r   rv   rs   typer   r   r   r}   r   r   r   r   r   rS   insertr   adjoinr   rc   r   )rk   r   rd   r   r   r   n_header_rowsr   widthdot_strr   s              rl   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??###rn   )
NTTTr\   FNTNN)r   rN   r^   r_   r`   r   r   ra   r   ra   rb   rc   r   ra   ry   r   r   ra   r   r   r   r   re   rf   re   rf   r   )re   r   r   )	r   r   r   rm   r   rv   r   r}   r   r   rn   rl   r   r     s         #!#'##    @? ? ? ?6' ' ' 'R	& 	& 	& 	&
 
 
 
$$ $$ $$ $$ $$ $$rn   r   c                  0    e Zd ZddZddZdddZddZdS )TextAdjustmentre   rf   c                .    t          d          | _        d S )Nzdisplay.encoding)r   encodingr|   s    rl   rm   zTextAdjustment.__init__  s    "#566rn   textrc   r   c                     t          |          S r   rs   rk   r   s     rl   rs   zTextAdjustment.len  s    4yyrn   rQ   textsr   max_lenr   rw   c                0    t          j        |||          S )Nr   )rL   rS   )rk   r   r   r   s       rl   rS   zTextAdjustment.justify  s    wT::::rn   spacec                F    t          j        |g|R | j        | j        d|S )N)strlenjustfunc)rL   r   rs   rS   )rk   r   listskwargss       rl   r   zTextAdjustment.adjoin  sA    

 
"&(T\
 
EK
 
 	
rn   Nr   r   rc   re   r   rQ   )r   r   r   r   r   rc   re   rw   )r   r   re   rc   )r   r   r   rm   rs   rS   r   r   rn   rl   r   r     si        7 7 7 7   ; ; ; ; ;
 
 
 
 
 
rn   r   c                  4     e Zd Zd fdZddZ	 dddZ xZS )EastAsianTextAdjustmentre   rf   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)superrm   r   ambiguous_width_EAW_MAP)rk   	__class__s    rl   rm   z EastAsianTextAdjustment.__init__  sX    9:: 	%#$D  #$D 
  !qqqqAArn   r   rc   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   crk   s     rl   r   z.EastAsianTextAdjustment.len.<locals>.<genexpr>  sR       
 
MNDM.q1143GHH
 
 
 
 
 
rn   )r   rc   rs   sumr   s   ` rl   rs   zEastAsianTextAdjustment.len  s[     $$$ 	t99 
 
 
 
RV
 
 
 
 
 	
rn   rQ   r   Iterable[str]r   r   rw   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   rk   s    rl   _get_padz1EastAsianTextAdjustment.justify.<locals>._get_pad  s#    TXXa[[(3q6611rn   rP   c                L    g | ] }|                      |                    !S r   )ljustr   xr   s     rl   r   z3EastAsianTextAdjustment.justify.<locals>.<listcomp>  -    888QAGGHHQKK((888rn   rR   c                L    g | ] }|                      |                    !S r   )rR   r  s     rl   r   z3EastAsianTextAdjustment.justify.<locals>.<listcomp>  s-    999aAHHXXa[[))999rn   c                L    g | ] }|                      |                    !S r   )rjustr  s     rl   r   z3EastAsianTextAdjustment.justify.<locals>.<listcomp>  r  rn   r   )rk   r   r   r   r   s   ` ` @rl   rS   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8rn   r   r   r   )r   r   r   r   r   rc   re   rw   )r   r   r   rm   rs   rS   __classcell__r   s   @rl   r   r     sv        
B 
B 
B 
B 
B 
B	
 	
 	
 	
 ?F9 9 9 9 9 9 9 9 9rn   r   re   c                 \    t          d          } | rt                      S t                      S )Nz display.unicode.east_asian_width)r   r   r   )use_east_asian_widths    rl   r   r     s1    %&HII  &(((rn   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      rl   get_dataframe_repr_paramsr    s    " *)))))-.. 0022
AA
122122455"#9::%&?@@   rn   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       rl   get_series_repr_paramsr    s    " &''ME6 ())Q.. 	*++  ())Q.. 	*++  677  rn   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.ri   NTr\   F.framerM   columnsSequence[Hashable] | None	col_spaceColspaceArgType | Noner   bool | Sequence[str]r   ra   rb   rc   
formattersFormattersType | NonerS   r   ry   FloatFormatType | Nonesparsifybool | Noneindex_namesr   r   r   r  r  r   decimal	bold_rowsescapere   rf   c                   || _         |                     |          | _        |                     |          | _        || _        || _        || _        |                     |          | _	        | 
                    |          | _        |	| _        |                     |
          | _        || _        || _        || _        || _        || _        || _        || _        || _        |                                 | _        |                                 | _        | j         | _        |                                  t;                      | _        d S r   )r!  _initialize_columnsr"  _initialize_colspacer$  r   r   rb   _initialize_formattersr'  _initialize_justifyrS   ry   _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   )rk   r!  r"  r$  r   r   rb   r'  rS   ry   r*  r,  r   r   r  r  r-  r.  r/  s                      rl   rm   zDataFrameFormatter.__init__4  s   * 
//88229==
55jAA//88(11(;; +"   .#99;;#99;;
!##rn   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   r;  r   )rk   strcols	str_indexs      rl   get_strcolszDataFrameFormatter.get_strcolsc  sM     1133: 	)11$-@@INN1i(((rn   c                8    | j         du p| j         dk    o| j        S )NTr   )r  is_truncatedr|   s    rl   should_show_dimensionsz)DataFrameFormatter.should_show_dimensionso  s*    #t+ 
 J.D43D	
rn   c                8    t          | j        p| j                  S r   )ra   is_truncated_horizontallyr   r|   s    rl   rC  zDataFrameFormatter.is_truncatedu  s    D2Rd6RSSSrn   c                d    t          | j        ot          | j                  | j        k              S r   )ra   r8  rs   r"  r|   s    rl   rF  z,DataFrameFormatter.is_truncated_horizontallyy  s*    D(Wc$,.?.?$BV.VXXXrn   c                d    t          | j        ot          | j                  | j        k              S r   )ra   r:  rs   r!  r|   s    rl   r   z*DataFrameFormatter.is_truncated_vertically}  s(    D(Uc$*oo@T.TVVVrn   c                f    dt          | j                   dt          | j        j                   dS )Nz

[z rows x z	 columns])rs   r!  r"  r|   s    rl   dimensions_infoz"DataFrameFormatter.dimensions_info  s0    Rs4:RRDJ4F0G0GRRRRrn   c                4    t          | j        j                  S r   )
_has_namesr!  r   r|   s    rl   has_index_namesz"DataFrameFormatter.has_index_names  s    $**+++rn   c                4    t          | j        j                  S r   )rL  r!  r"  r|   s    rl   has_column_namesz#DataFrameFormatter.has_column_names  s    $*,---rn   c                D    t          | j        | j        | j        f          S r   )allrM  r   r6  r|   s    rl   show_row_idx_namesz%DataFrameFormatter.show_row_idx_names  s    D($*d6KLMMMrn   c                D    t          | j        | j        | j        f          S r   )rQ  rO  r6  r   r|   s    rl   show_col_idx_namesz%DataFrameFormatter.show_col_idx_names  s    D)4+@$+NOOOrn   r   c                x    t          | j        pt          | j                  t          | j                            S r   )r   r   rs   r!  r|   s    rl   max_rows_displayedz%DataFrameFormatter.max_rows_displayed  s)    4=3C
OOS__EEErn   c                (    |t          d          S |S )Nzdisplay.multi_sparser   )rk   r*  s     rl   r5  z'DataFrameFormatter._initialize_sparsify  s    4555rn   r*   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   )rs   r!  r"  r   dict
ValueError)rk   r'  s     rl   r3  z)DataFrameFormatter._initialize_formatters  s     I#$$J77:jRV;W;W7JS__ J J/24:3E/F/FJ J J  rn   c                (    |t          d          S |S )Nzdisplay.colheader_justifyrX  )rk   rS   s     rl   r4  z&DataFrameFormatter._initialize_justify  s    ?9:::Nrn   rC   c                    |6t          t          t          |                    }| j        |         | _        |S | j        j        S r   )rF   r   r$   r!  r"  )rk   r"  colss      rl   r1  z&DataFrameFormatter._initialize_columns  s?      T7 3 344DD)DJK:%%rn   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 )Nri   c                    i | ]}|S r   r   )r   columnr$  s     rl   
<dictcomp>z;DataFrameFormatter._initialize_colspace.<locals>.<dictcomp>  s    NNN69NNNrn   z,Col_space is defined for an unknown column: zCol_space length(rZ  r   )r   r   rc   updater!  r"  r   keysr\  rs   r[  zip)rk   r$  r   rb  s    `  rl   r2  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rn   c                    |                                  s| j        S t                      \  }}|                     |          r|S | j        S )z%Number of columns fitting the screen.)_is_in_terminalr  r
   _is_screen_narrow)rk   r   r  s      rl   r7  z(DataFrameFormatter._calc_max_cols_fitted  sP    ##%% 	!= $&&q!!%(( 	!L= rn   c                   |                                  rSt                      \  }}| j        dk    r||                                 z
  S |                     |          r|}n| j        }n| j        }|                     |          S )z,Number of rows with data fitting the screen.r   )rh  r
   r   _get_number_of_auxillary_rows_is_screen_short_adjust_max_rows)rk   r  r  r   s       rl   r9  z(DataFrameFormatter._calc_max_rows_fitted  s     !! 	%)++IAv}!! B B D DDD$$V,, )!=}H$$X...rn   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
        )rs   r!  r   r   )rk   r   s     rl   rm  z#DataFrameFormatter._adjust_max_rows  s<      	8DJ(***t}h77rn   c                H    t          | j        dk    p
| j        dk              S )z/Check if the output is to be shown in terminal.r   )ra   r  r   r|   s    rl   rh  z"DataFrameFormatter._is_in_terminal  s#    DMQ&<$-1*<===rn   c                l    t          | j        dk    ot          | j        j                  |k              S Nr   )ra   r  rs   r!  r"  )rk   	max_widths     rl   ri  z$DataFrameFormatter._is_screen_narrow  s.    DMQ&N3tz/A+B+BY+NOOOrn   c                b    t          | j        dk    ot          | j                  |k              S rq  )ra   r   rs   r!  )rk   
max_heights     rl   rl  z#DataFrameFormatter._is_screen_short  s)    DMQ&G3tz??Z+GHHHrn   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  rs   rJ  
splitlinesr   )rk   dot_row
prompt_rownum_rowss       rl   rk  z0DataFrameFormatter._get_number_of_auxillary_rows	  sZ    
Z' 	?D0;;==>>>H; 	MHrn   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)rF  _truncate_horizontallyr   _truncate_verticallyr|   s    rl   r   zDataFrameFormatter.truncate  sN     ) 	*'')))' 	(%%'''''	( 	(rn   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)r8  r;  r   rI   r   r'  listtupler   r   r  
tr_col_num)rk   col_numrP   rQ   s       rl   r{  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!rn   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   )r:  r;  r   rI   r   r   r   r   )rk   r   headtails       rl   r|  z'DataFrameFormatter._truncate_vertically;  s     #///&!+a<<=%hwhk2D=%whiil3D"D$<00DMM3..G M.xx{;DM!rn   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)          t)           fd
|D                       |          }	 j
                            ||	 j                  }|                    ||z              |S )Nr   )stringsrS   minimumr   zWriting z cols but got z aliasesc                    g | ]}|gS r   r   )r   labels     rl   r   zADataFrameFormatter._get_strcols_without_index.<locals>.<listcomp>d  s    <<<uE7<<<rn   ri   c              3  L   K   | ]}j                             |          V  d S r   r   rs   r   r  rk   s     rl   r   z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>o  s/      0R0RQa0R0R0R0R0R0Rrn   )r  r   c              3  L   K   | ]}j                             |          V  d S r   r  r  s     rl   r   z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>v  s/      BB!dhll1ooBBBBBBrn   r   )r6   r   	enumerater;  
format_col_make_fixed_widthrS   r   r$  r   r   r   r   r   rc   rs   r"  r\  _get_formatted_column_labelsrR  max)
rk   r?  r   r   r   str_columnsr  cheaderheader_colwidthr   s
   `         rl   r>  z-DataFrameFormatter._get_strcols_without_indexM  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 #BBBBzBBBBBOTTGh&&wdl&KKGNN7Z/0000rn   r   rw   c           
         | j         }|                     |          }t          |j        d d |f         j        || j        | j        | j                            |j	        |                   | j
        | j                  S )N)ry   rb   r   r-  r   )r;  _get_formatterrz   r   r   ry   rb   r$  r   r"  r-  r   )rk   r   r!  	formatters       rl   r  zDataFrameFormatter.format_col|  sz    ''**	Jqqq!t$*;.$$U]1%566L*
 
 
 	
rn   	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  r4   r   r   r"  r   )rk   r   s     rl   r  z!DataFrameFormatter._get_formatter  s    doe}55 		0!}} aLLq))t!}} $$,!6!6LO?&&q$///rn   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     rl   r   zBDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>  s%      %T%TEe&7%T%T%T%T%T%Trn   c                8    |j         vr|          rsd|z   S |S )N )r'  )r  yneed_leadsprestrict_formattingrk   s     rl   space_formatzEDataFrameFormatter._get_formatted_column_labels.<locals>.space_format  s4    T_,,#A -/ - 7Nrn   c              3  8   K   | ]fd D             V  dS )c                (    g | ]} |          S r   r   )r   r  r  r  s     rl   r   zMDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>.<listcomp>  s%    555a||Aq))555rn   Nr   )r   r  r  s    @rl   r   zBDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>  s<      KK!555551555KKKKKKrn   c                ,    g | ]}t          |          S r   )r  r   r  s     rl   r   zCDataFrameFormatter._get_formatted_column_labels.<locals>.<listcomp>  s    >>>q477>>>rn   c                `    g | ]*\  }}                     |          s|         rd |z   n|g+S )r  )r  )r   r   r  r  rk   s      rl   r   zCDataFrameFormatter._get_formatted_column_labels.<locals>.<listcomp>  sT       Aq !% 3 3A 6 6P;q>PqqQ  rn   )pandas.core.indexes.multir  r"  r   rD   r   r  rf  r!  dtypesr   r   levelsr[  mapr7   r*  rs   r  )
rk   r!  r  r"  fmt_columnsr  r  r  r  r  s
   `      @@@rl   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
 rn   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      rl   rc  z;DataFrameFormatter._get_formatted_index.<locals>.<dictcomp>  s&    HHHAQS!HHHrn   	__index__F)r*  r   r   r  )r   r  c                    g | ]H}t          t          t          |          d                     dd          j                            IS )rP   ri   r   )rS   r  r   )r  r  r  r   r   )r   r  r$  rk   s     rl   r   z;DataFrameFormatter._get_formatted_index.<locals>.<listcomp>  sf     
 
 
  !GGVY]]2q5I5Itx   
 
 
rn   r   rr   c                ,    g | ]}t          |          S r   rc   r  s     rl   r   z;DataFrameFormatter._get_formatted_index.<locals>.<listcomp>  s    GGGQ#a&&GGGrn   ri   )r$  itemsr   r"  r  r   rD   r   r*  rR  r   r   splitrT  _get_column_name_listnlevelsr   )	rk   r!  r   r"  fmtr   adjoined
col_headerr$  s	   `       @rl   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; 	((Orn   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 rh   r   r   s     rl   r   z;DataFrameFormatter._get_column_name_list.<locals>.<genexpr>  s*      PP$t|PPPPPPrn   ri   )r!  r"  r   rD   extendr   r   r   )rk   r   r"  s      rl   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rn   )NNTTr\   NNNNTNNNFr   FT)&r!  rM   r"  r#  r$  r%  r   r&  r   ra   rb   rc   r'  r(  rS   r   ry   r)  r*  r+  r,  ra   r   r   r   r   r  r   r  r   r-  rc   r.  ra   r/  ra   re   rf   )re   r<  re   ra   r   )re   r   )r*  r+  re   ra   )r'  r(  re   r*   )rS   r   re   rc   )r"  r#  re   rC   )r$  r%  re   r&   )re   r   )r   r   re   r   r   )r   r   re   rw   )r   r  re   r  )r!  rM   re   r<  )r!  rM   re   rw   )re   r  )(r   r   r   __doc__rO   rY   rm   rA  propertyrD  rC  rF  r   rJ  rM  rO  rR  rT  rV  r5  r3  r4  r1  r2  r7  r9  rm  rh  ri  rl  rk  r   r{  r|  r>  r  r  r  r   r  r   rn   rl   r  r  .  s       EE (ggbG"222G
 .2,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     rn   r  c                      e Zd ZdZd?dZ	 	 	 	 	 	 	 	 	 	 d@dAdZ	 	 	 	 	 	 	 dBdCdZ	 	 	 dDdEd"Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dFdGd>ZdS )H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  re   rf   c                    || _         d S r   )r  )rk   r  s     rl   rm   zDataFrameRenderer.__init__  s    rn   NFr^   "FilePath | WriteBuffer[str] | Nonecolumn_formatr   	longtablera   r   multicolumnmulticolumn_formatmultirowcaptionstr | tuple[str, str] | Noner  positionc                    ddl m}  || j        |||||||	|
	  	        }|                                }t	          |||          S )zU
        Render a DataFrame to a LaTeX tabular/longtable environment output.
        r   )LatexFormatter)r  r  r  r  r  r  r  r  r^   r   )pandas.io.formats.latexr  r  r   save_to_buffer)rk   r^   r  r  r   r  r  r  r  r  r  r  latex_formatterstrings                 rl   to_latexzDataFrameRenderer.to_latex  sq      	;:::::(.H'#1

 

 

 !**,,f#AAAArn   classesstr | list | tuple | Nonenotebook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  r  )pandas.io.formats.htmlr  r  r  r   r  )rk   r^   r   r  r  r  r  r  r  r  Klasshtml_formatterr  s                rl   to_htmlzDataFrameRenderer.to_html$  s    D	
 	
 	
 	
 	
 	
 	
 	

 &.@!!=H%
 
 
  ))++f#AAAArn   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  )rk   r^   r   r  r  string_formatterr  s          rl   r   zDataFrameRenderer.to_stringW  sS    ( 	=<<<<<*?48
KKK!++--f#AAAArn   ,winfer"Tstrictpath_or_buf7FilePath | WriteBuffer[bytes] | WriteBuffer[str] | Noneseprc   r"  r#  index_labelIndexLabel | Noner   compressionr'   rj   	quotecharlineterminator	chunksizedate_formatdoublequote
escapecharerrorsstorage_optionsr,   c                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  rj   r_  r  r   r  r  r  r  r  r  r  r   )pandas.io.formats.csvsr  r	   r  saver   getvalueclose)rk   r  r   r  r"  r  r   r  rj   r  r  r  r  r  r  r   r  r  created_buffercsv_formattercontents                        rl   to_csvzDataFrameRenderer.to_csvq  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trn   )r  r  re   rf   )
NNFNFNFNNN)r^   r  r  r   r  ra   r   r   r  ra   r  r   r  ra   r  r  r  r   r  r   re   r   )NNNFNNF)r^   r  r   r   r  r  r  ra   r  r  r  r   r  ra   re   r   )NNN)r^   r  r   r   r  r   re   r   )NNr  NNr  r  Nr  NNNTNr  N)"r  r  r   r   r  rc   r"  r#  r  r  r   rc   r  r'   rj   r   r  rc   r  r   r  r   r  r   r  ra   r  r   r   rc   r  r,   re   r   )	r   r   r   r  rm   r  r  r   r  r   rn   rl   r  r    s            
 37$(#!)-04 #B B B B BD 37#-1$(#"1B 1B 1B 1B 1Bj 37#!%	B B B B B8 PT#-1)-*1"%) $"& !%*.#9 9 9 9 9 9 9rn   r  r  rc   r^   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  r^   r   fs       rl   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  ri   )r   newlinez1buf is not a file name and it has no write method)	rK   r	   r   rc   r\  hasattrrJ   open	TypeError)r^   r   r  s      rl   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<r\   rQ   r   Tr   r   r  r  ry   r)  rb   digitsr   r   str | int | NonerS   r-  r   r+  rj   fallback_formatterrw   c                4   t          | j                  rt          }nt          | j        t                    rt
          }nt          | j                  rt          }not          | j                  rt          }nSt          | j                  st          | j                  rt          }n#t          | j                  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]
    N   r   display.precision)
r  rb   ry   r  r   rS   r-  r   rj   r  )r0   r   Datetime64Formatterr   r:   Datetime64TZFormatterr9   Timedelta64Formatterr1   ExtensionArrayFormatterr3   r/   FloatArrayFormatterr5   IntArrayFormatterGenericArrayFormatterr   
get_result)r   r  ry   rb   r  r   rS   r-  r   rj   r  	fmt_klassfmt_objs                rl   rz   rz     s0   R 6<(( *'			FL/	2	2 *)			fl	+	+ 	*(			!&,	/	/ *+				%	% *)9&,)G)G *'			&,	'	' *%		)	}!"899~/00i!#-  G rn   c                  >    e Zd Z	 	 	 	 	 	 	 	 	 	 	 d#d$dZd%d!Zd%d"ZdS )&r"     Nr\   r  rQ   r   Tr   r   r  r   r  r  rb   rc   r   r  ry   r)  rS   r-  rj   r   fixed_widthra   r   r+  r  re   rf   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        d S r   )r   r  rb   r   r  ry   rS   r-  rj   r(  r   r  )rk   r   r  r  rb   r   ry   rS   r-  rj   r(  r   r  s                rl   rm   zGenericArrayFormatter.__init__6  sb     
"(&*"4rn   rw   c                T    |                                  }t          || j                  S r   )_format_stringsr  rS   )rk   r   s     rl   r#  z GenericArrayFormatter.get_resultR  s%    ))++
 T\:::rn   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    rl   <lambda>z7GenericArrayFormatter._format_strings.<locals>.<lambda>[  s)    )A+I+++++* * rn   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 )Nrf   r   )rb   r8   r;   r   rc   r   npisnatr  r\  r   rA   r@   repr)r  r  rk   s    rl   _formatz6GenericArrayFormatter._format_strings.<locals>._formatm  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   r~  r  Fz{v}z {v})r  )ry   r   r  r  rj   r   r   rL   r   rB   r   r   r4  ndarrayr  r   	map_inferr2   rQ  r<   r  rangers   shaper   r   r  r   r   )rk   ry   r2  r7  valsinferredis_float_typer   r   r   r  tplr  r0  s   `           @@rl   r+  z%GenericArrayFormatter._format_stringsV  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*":":;;;;rn   )r'  Nr\   r  NrQ   r   NTTN)r   r   r  r   r  r  rb   rc   r   r  ry   r)  rS   rc   r-  rc   rj   r   r(  ra   r   r+  r  r  re   rf   r   )r   r   r   rm   r#  r+  r   rn   rl   r"  r"  5  s~         %)/3" %).25 5 5 5 58; ; ; ;L L L L L Lrn   r"  c                  >     e Zd Zd fdZ	 	 ddd
ZddZddZ xZS )r   re   rf   c                     t                      j        |i | | j        7| j        2d| _        t          | j                  r| j        | _        d | _        d S d S d S d S NF)r   rm   ry   r  r(  callable)rk   argsr   r   s      rl   rm   zFloatArrayFormatter.__init__  s|    $)&))) (T^-C$D)** )!%!2$(!!! )(-C-C) )rn   Nry   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<   rb   )r  ry   rk   s    rl   base_formatterz<FloatArrayFormatter._value_formatter.<locals>.base_formatter  s;    #/// Qxx%LLq))))rn   c                N    t          |           rt          |           nj        S r   )r<   rc   rb   )r  rk   s    rl   rL  z<FloatArrayFormatter._value_formatter.<locals>.base_formatter  s     !&q:s1vvvt{:rn   r   c                N     |                                dj        d          S )Nr   r   )replacer-  )r  rL  rk   s    rl   decimal_formatterz?FloatArrayFormatter._value_formatter.<locals>.decimal_formatter  s'    %~a((00dlAFFFrn   c                    t          |           r)t          |           k    r |           S  d          S j        S )Ng        )r<   absrb   )rK  rP  rk   rG  s    rl   r  z7FloatArrayFormatter._value_formatter.<locals>.formatter  sL    U|| #u::	)),,U333,,S111{"rn   )ry   r-  )rk   ry   rG  r  rL  rP  s   ``` @@rl   _value_formatterz$FloatArrayFormatter._value_formatter  s     ,L  	;	 	 	 	 	 	 	; ; ; ; ; <3G G G G G G G !/$$	# 	# 	# 	# 	# 	# 	# rn   
np.ndarrayc                F   
 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        d          5  t          j         j                  }|dk                                    }|d j	         z  k     |dk    z                                  }	ddd           n# 1 swxY w Y   |	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   rb   rc   c                    t          |           }t          j        fdt          |                                 |                                          D                                           | j                  }|S )Nc                4    g | ]\  }}|s |          nS r   r   )r   valmr  rb   s      rl   r   zWFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_rep.<locals>.<listcomp>  s>       Q +,7IIcNNN  rn   )r;   r4  arrayrf  ravelreshaper=  )r   r  rb   mask	formatteds    ``  rl   format_with_na_repzCFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_rep  s    <<D    "%fllnndjjll"C"C   
 gfl##  rn   Nzdisplay.chop_thresholdc                H                        |           }j        dk    rdj        z   }nj        }j        }t	          |          } |||          }j        rC|rt          |j                  }nt          |j                  }t          j
        |d          S |S )NrP   r  objectr   )rS  rS   rb   r   r/   r(  _trim_zeros_complexr-  _trim_zeros_floatr4  asarray)	ry   r  rb   r   
is_complexr   r_  rk   rG  s	         rl   format_values_withzCFloatArrayFormatter.get_result_as_array.<locals>.format_values_with  s    --lIFFI |v%%t{* [F)&11J''	6BBF : E0FFFF.vt|DDFz&9999Mrn   Tz{value: .{digits:d}f}z{value:.{digits:d}f})r  c                    j         | z  S r   )ry   )rK  rk   s    rl   r1  z9FloatArrayFormatter.get_result_as_array.<locals>.<lambda>(  s    ):U)B rn   r   c              3  4   K   | ]}t          |          V  d S r   r   r  s     rl   r   z:FloatArrayFormatter.get_result_as_array.<locals>.<genexpr>4  s(      ::AQ::::::rn      Fignoreinvalidg    .A
   z{value: .{digits:d}e}z{value:.{digits:d}e})r   r#   r  r   rb   rc   )r  r   rb   r(  r   ry   r   r   r   r  rs   r  r4  errstaterR  r   )rk   rg  fmt_strry   formatted_valuesmaxlentoo_longabs_valshas_large_valueshas_small_valuesr_  rG  s   `         @@rl   get_result_as_arrayz'FloatArrayFormatter.get_result_as_array  si   	 	 	 	 >%%%dk4>4;OOO 	"#;<<III	 	 	 	 	 	 	6 $ 1%--5GG4G&w~dkJJJ#0BBBBL--l;; 	$##   1$$::)9:::::Fa/HHH[*** 	 	vdk**H !)33355BDK<00X\Bcee 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	@ 	@-= 	@!T))10"7>$+FFFL11,??s   6AEE #E rw   c                D    t          |                                           S r   )r  rw  r|   s    rl   r+  z#FloatArrayFormatter._format_stringsM  s    D,,..///rn   r   NN)ry   r)  rG  rH  re   r   )re   rT  r   )r   r   r   rm   rS  rw  r+  r  r	  s   @rl   r   r     s        
) 
) 
) 
) 
) 
) 04"&6 6 6 6 6pa  a  a  a F0 0 0 0 0 0 0 0rn   r   c                      e Zd ZddZdS )r!  re   rw   c                `    | j         du rd }nd }| j        p|fd| j        D             }|S )NFc                2    | d                     |           S )Nr.  r  r   r}  s    rl   r1  z3IntArrayFormatter._format_strings.<locals>.<lambda>T  s    hhooo&:&: rn   c                2    | d                     |           S )Nz dr}  r~  r}  s    rl   r1  z3IntArrayFormatter._format_strings.<locals>.<lambda>V  s    ii&6&6&6&;&; rn   c                &    g | ]} |          S r   r   r   r  r  s     rl   r   z5IntArrayFormatter._format_strings.<locals>.<listcomp>X  s!    888qiill888rn   )r   r  r   )rk   formatter_strr   r  s      @rl   r+  z!IntArrayFormatter._format_stringsR  sP    &&::MM;;MN3m	8888DK888
rn   Nr   r   r   r   r+  r   rn   rl   r!  r!  Q  s(             rn   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_reprc   r  rf   re   c                X     t                      j        |fi | || _        || _        d S r   )r   rm   r  r  )rk   r   r  r  r   r   s        rl   rm   zDatetime64Formatter.__init__]  s9     	**6***&rn   rw   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     rl   r   z7Datetime64Formatter._format_strings.<locals>.<listcomp>p  s%    666!DNN1%%666rn   )rb   r  )
r   r   rG   r  rE  _data_format_native_typesr  r  tolist)rk   r   r   s   `  rl   r+  z#Datetime64Formatter._format_stringsh  s    &-00 	+"6**F>%(4>*B*B%6666v6666\66<T-= 7 
 

   """rn   r   N)r   r  r  rc   r  rf   re   rf   r   r   r   r   rm   r+  r  r	  s   @rl   r  r  \  s^          		' 	' 	' 	' 	' 	' 	'# # # # # # # #rn   r  c                      e Zd ZddZdS )r  re   rw   c                t   t          | j        d          }| j        }d }||                    d          }t	          |t
                    r|                                }nt          j        |          }t          ||| j
        | j        | j        | j        | j        | j        | j        | j        |          }|S )NTr8  )boxed)	ry   rb   r  r   rS   r-  r   rj   r  )rB   r   r  
_formatterr   r=   r{   r4  re  rz   ry   rb   r  r   rS   r-  r   rj   )rk   r   r  r  rZ  r   s         rl   r+  z'ExtensionArrayFormatter._format_stringsy  s    t{$???N	!!'!2!2!2!>!>fk** 	'//11EEJv&&E!*;;*LL,L1
 
 

 rn   Nr   r  r   rn   rl   r  r  x  s(             rn   r  percentilesnp.ndarray | Sequence[float]c                   t          j        |           } t          j        d          5  t          |           r0t          j        | dk              rt          j        | dk              st          d          	 ddd           n# 1 swxY w Y   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%']
    rk  rl  r   r   z/percentiles should all be in the interval [0,1]Nd   c                    g | ]}|d z   S %r   r   s     rl   r   z&format_percentiles.<locals>.<listcomp>  s    %%%AC%%%rn   )to_beginto_endrb  c                    g | ]}|d z   S r  r   r   s     rl   r   z&format_percentiles.<locals>.<listcomp>  s    !!!AG!!!rn   )r4  re  ro  r7   rQ  r\  roundastyper   iscloserc   uniquefloorlog10r   ediff1dr  
empty_likera  )r  percentiles_round_typeint_idxoutunique_pctsr  r  precs           rl   format_percentilesr    s   D *[))K 
X	&	&	& P P --	P6+*++	P 6+*++	P
 NOOO	PP P P P P P P P P P P P P P P #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!!!!s   ABB
B
2np.ndarray | DatetimeArray | Index | DatetimeIndexra   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   rC   r[  r>   rG   tzasi8r    r   r   r!   r4  logical_andr   )r   
values_intconsider_valuesresoppd	even_dayss         rl   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5rn   r   r  NaTType | Timestampr  c                6    | t           u r|S t          |           S r   )r   rc   r  r  s     rl   _format_datetime64r    s    Cxx q66Mrn   r  c                l    t          | t                    r|S |r|                     |          S | j        S r   )r   r"   strftime
_date_repr)r  r  r  s      rl   _format_datetime64_dateonlyr    s?    
 !W  zz+&&& |rn   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    rl   r1  z'get_format_datetime64.<locals>.<lambda>  s    4wK
 
 
 rn   c                &    t          |           S )N)r  )r  r  s    rl   r1  z'get_format_datetime64.<locals>.<lambda>  s    +Aw??? rn   r   )r  r  r  s    ``rl   get_format_datetime64r    s?      @
 
 
 
 
 	
 @????rn   *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   r4  r:  ndimr[  r  )r   r  idos      rl   !get_format_datetime64_from_valuesr    sW     &"*%%  &+// 


C
 )(j(rn   c                      e Zd ZddZdS )r  re   rw   c                    | j                             t                    }t          |          }| j        pt          || j                  fd|D             }|S )zwe by definition have a TZ)r  c                &    g | ]} |          S r   r   r  s     rl   r   z9Datetime64TZFormatter._format_strings.<locals>.<listcomp>4  s!    333qiill333rn   )r   r  ra  r  r  r  r  )rk   r   r  r   r  s       @rl   r+  z%Datetime64TZFormatter._format_strings-  sl    ##F++F##N 
&;T-'
 '
 '
	 4333F333
rn   Nr   r  r   rn   rl   r  r  ,  s(        	 	 	 	 	 	rn   r  c                  .     e Zd Z	 	 dd fdZddZ xZS )r  r   Fr   np.ndarray | TimedeltaIndexr  rc   boxra   re   rf   c                X     t                      j        |fi | || _        || _        d S r   )r   rm   r  r  )rk   r   r  r  r   r   s        rl   rm   zTimedelta64Formatter.__init__:  s6     	**6***rn   rw   c                z    | j         p t          | j        | j        | j                  fd| j        D             S )N)r  r  c                &    g | ]} |          S r   r   r  s     rl   r   z8Timedelta64Formatter._format_strings.<locals>.<listcomp>I  s!    222		!222rn   )r  get_format_timedelta64r   r  r  )rk   r  s    @rl   r+  z$Timedelta64Formatter._format_stringsE  sL    N 
&<K48'
 '
 '
	 3222dk2222rn   r   F)r   r  r  rc   r  ra   re   rf   r   r  r	  s   @rl   r  r  9  s^         		 	 	 	 	 	 	3 3 3 3 3 3 3 3rn   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~  ')r8   r;   r   r   
_repr_base)r  r   r  r   r  s     rl   r  z*get_format_timedelta64.<locals>._formatterk  sm    919$q''9N!Y'' 	!A V,, 	#"]]]Frn   )viewr4  int64r    r  r   )r   r  r  r  r  one_day_nanosnot_midnightbothr  r  r   s    ``       @rl   r  r  L  s     RX&&J D(O!M-2L >/<88D

aI        rn   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   rQ  c              3  B   K   | ]}                     |          V  d S r   r   )r   r  
adjustments     rl   r   z$_make_fixed_width.<locals>.<genexpr>  s/      55*..##555555rn   r  r  rc   re   c                l    0dk                         |           k    z  r| d dz
           dz   } | S )Nr   r   r   )r  r  conf_maxr   s    rl   justz_make_fixed_width.<locals>.just  sG    1!2!2W!<= -m!m$u,rn   c                &    g | ]} |          S r   r   )r   r  r  s     rl   r   z%_make_fixed_width.<locals>.<listcomp>  s!    (((1ttAww(((rn   r   )r  rc   re   rc   )rs   r   r  r   rS   )	r  rS   r  r   r   r  r  r  r   s	        @@@@rl   r  r  {  s     7||qGu,,
{#%%


5555W55555Ggw''011H( 2 2        )((((((Gw??FMrn   str_complexesrT  c                    fd| D             }d |D             }t          |          fdt          ||          D             }|S )z
    Separates the real and imaginary parts from the complex number, and
    executes the _trim_zeros_float method on each of those.
    c           
     |    g | ]8}d                      t          t          j        d|                              9S )ri   z([j+-]))r   rd  rer  )r   r  r-  s     rl   r   z'_trim_zeros_complex.<locals>.<listcomp>  sL        	!"(:q"9"97CCDD  rn   c                ,    g | ]}t          |          S r   r   )r   ss     rl   r   z'_trim_zeros_complex.<locals>.<listcomp>  s    '''!s1vv'''rn   c                    g | ]h\  }}|d |dz
  dz  dz             |z
  dz  dz  z   ||dz
  dz  dz    |dz
  dz            z   ||dz
  dz   d         z   |z
  dz  dz  z   |d         z   iS )Nr   r   0r  r   )r   r  r  
max_lengths      rl   r   z'_trim_zeros_complex.<locals>.<listcomp>  s        Aq 	

q1ulQ
 >a
#
%	&
q1ulQQUqL/1
2	3 q1ulOb 
!	" >a
#
%		&
 B%	  rn   )r  rf  )r  r-  trimmedlengthspaddedr  s    `   @rl   rc  rc    s    
     G ('w'''GWJ    ))  F Mrn   	str_floatc                d    |                      d          } |                     d          r| dz  } | S )zX
    Trims trailing zeros after a decimal point,
    leaving just one if necessary.
    r  r   )rstripendswith)r  s    rl   r/  r/    s=    
   %%I# S	rn   
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]*$re   ra   c                2    t          j        |           d uS r   )r  match)r  number_regexs    rl   is_number_with_decimalz1_trim_zeros_float.<locals>.is_number_with_decimal  s    xa((44rn   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     rl   r   z:_trim_zeros_float.<locals>.should_trim.<locals>.<listcomp>  s*    BBB(>(>q(A(AB1BBBrn   r   c              3  @   K   | ]}|                     d           V  dS )r  Nr  r  s     rl   r   z9_trim_zeros_float.<locals>.should_trim.<locals>.<genexpr>  s,      'I'IA

3'I'I'I'I'I'Irn   )rs   rQ  )r   numbersr  s     rl   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Irn   c                >    g | ]} |          r
|d d         n|S )Nr  r   r  s     rl   r   z%_trim_zeros_float.<locals>.<listcomp>  s6    OOO!33A66=1SbS66AOOOrn   c                ^    g | ])} |          r|                               r|d z   n|*S )r  r  )r   r  r-  r  s     rl   r   z%_trim_zeros_float.<locals>.<listcomp>  sR        *)!,,KG1D1DKC!  rn   r  )r   r  re   ra   )r  compile)r  r-  r  r  r   r  r  s    `   @@rl   rd  rd    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 Mrn   r   rC   c                d    t          | t                    rt          j        | j         S | j        d uS r   )r   rD   comany_not_noner   r   )r   s    rl   rL  rL    s1    %$$ &--z%%rn   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piniurY  r   ri   r   r  rj  M	   Gr  T   P   E   Z   YNFaccuracyr   use_eng_prefixra   re   rf   c                "    || _         || _        d S r   r   r!  )rk   r   r!  s      rl   rm   zEngFormatter.__init__	  s     !,rn   numfloatrc   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
        r\   infr   r   r  r   zE-02dzE+rn  Nz{mant: g}{prefix}z{mant: .r.  z
f}{prefix})mantprefix)r   rc   is_nanis_infiniter   mathr  r  r   r  ENG_PREFIXESre  r!  r   r   )
rk   r$  dnumsignpow10	int_pow10r*  r)  
format_strr^  s
             rl   __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1}}.yj...-i---d{b%i(= ,JJCT]CCCCJ%%4%??	rn   rD  )r   r   r!  ra   re   rf   )r$  r%  re   rc   )r   r   r   r  r.  rm   r4  r   rn   rl   r  r    s!        SS 	S 	S	
 	S 	C 	C 	C 	
2 	
3 	
3 	
3 	C 	C 	C  	C!" 	C#L* CH- - - - -< < < < < <rn   r  r   r   r   r!  rf   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     rl   set_eng_float_formatr6  N  s&    n %|Hn'M'MNNNNNrn   ri   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)rs   r  r   )	r  r7  controlr   r  
last_indexr  r   keys	            rl   get_level_lengthsr>    s    $ 6{{a	fs6!9~~%GF  
&& 	 	FAsqz cXoo"
&'*n
#

!%jj:5
gMrn   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   rc   r  s     rl   r   z#buffer_put_lines.<locals>.<genexpr>  s,      
-
-!:a
-
-
-
-
-
-rn   c                ,    g | ]}t          |          S r   r  r  s     rl   r   z$buffer_put_lines.<locals>.<listcomp>  s    '''AQ'''rn   rr   N)r   r  r   )r^   r@  s     rl   buffer_put_linesrD    sZ     
-
-u
-
-
--- ('''''IIdiirn   )re   r   )re   r  ry  )r  rc   r^   r  r   r   re   r   r   )r^   r  r   r   re   r  )	Nr\   NNrQ   r   TNN)r   r   r  r  ry   r)  rb   rc   r  r   r   r  rS   rc   r-  rc   r   r+  rj   r   r  r  re   rw   )r  r  re   rw   )r   r  re   ra   )r   )r  r  r  rc   re   rc   r  )r  r  r  rc   r  r   re   rc   )r  ra   r  rc   r  r   re   r   )r   r  r  r   re   r   r  )r   r  r  r  r  ra   re   r   )rQ   NN)
r  rw   rS   rc   r  r   r   r  re   rw   )r   )r  rT  r-  rc   re   rw   )r  rc   re   rc   )r  r  r-  rc   re   rw   )r   rC   re   ra   )r   F)r   r   r!  ra   re   rf   )ri   )r  r   r7  r8  re   r9  )r^   r?  r@  rw   re   rf   )r  
__future__r   
contextlibr   csvr   r   r-  r   	functoolsr   ior	   r-  r  shutilr
   typingr   r   r   r   r   r   r   r   r   r   r   r   unicodedatar   numpyr4  pandas._config.configr   r   pandas._libsr   pandas._libs.missingr   pandas._libs.tslibsr   r   r   r   r    r!   pandas._libs.tslibs.nattyper"   pandas._typingr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   pandas.core.dtypes.commonr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   pandas.core.dtypes.dtypesr:   pandas.core.dtypes.missingr;   r<   pandas.core.arraysr=   r>   r?   pandas.core.arrays.string_r@   pandas.core.baserA   pandas.core.commoncorecommonr
  pandas.core.constructionrB   pandas.core.indexes.apirC   rD   rE   rF   pandas.core.indexes.datetimesrG   pandas.core.indexes.timedeltasrH   pandas.core.reshape.concatrI   pandas.io.commonrJ   rK   r  rL   pandasrM   rN   rO   __annotations___VALID_JUSTIFY_PARAMETERSrY   r[   r   r   r   r   r  r  r  r  r  r  rz   r"  r   r!  r  r  r  r  r  r  r  r  r  r  r  r  rc  r/  rd  rL  r  r6  r>  rD  r   rn   rl   <module>rf     s	     # " " " " " % % % % % %                           				 $ $ $ $ $ $                            ) ( ( ( ( (           
       # # # # # #                0 / / / / /                                                     6 5 5 5 5 5       
         
 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       D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`i0 i0 i0 i0 i0/ i0 i0 i0X    -   # # # # #/ # # #8    3   >C" C" C" C"L   2     "      KO@ @ @ @ @    
 
 
 
 
/ 
 
 
3 3 3 3 30 3 3 3* !, , , , ,b !%	    D    2	 	 	 	 8;! ! ! ! !H& & & &^ ^ ^ ^ ^ ^ ^ ^B7O 7O 7O 7O 7Ov 24( ( ( ( (V           rn   