
    cMhO                   T   U d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lZdd	lZdd
lmZ ddlmZmZmZmZmZ dd	lZddlmZm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZA dd	lBmCc mDZE ddlFmGZGmHZHmIZImJZJ ddlKmLZL ddlMmNZN ddlOmPZP ddlQmRZRmSZS ddlTmUZU er$ddlVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZb ddlcmdZdmeZe dZfd egd!<   d"Zhd#Zid egd$<    G d% d&          Zjdd)Zkdd*Zl G d+ d,          Zm G d- d.          Zn	 	 ddd5Zoe		 ddd7            Zp	 	 	 	 	 	 	 	 	 dddNZq G dO dP          Zr G dQ dRer          Zs G dS dTer          Zt G dU dVer          Zu G dW dXer          Zvdd[Zwdd^ZxdddcZy	 	 dddeZz	 dddiZ{ G dj dkeu          Z| G dl dmer          Z}	 	 dddrZ~	 	 	 dddwZdddy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MappingSequence)contextmanager)
QUOTE_NONE)Decimal)partial)StringION)get_terminal_size)TYPE_CHECKINGAnyCallableFinalcast)
get_option
set_option)lib)NA)NaT	Timedelta	Timestamp)NaTType)is_complex_dtypeis_float
is_integeris_list_likeis_numeric_dtype	is_scalar)CategoricalDtypeDatetimeTZDtypeExtensionDtype)isnanotna)CategoricalDatetimeArrayExtensionArrayTimedeltaArray)StringDtype)PandasObject)Index
MultiIndexPeriodIndexensure_index)DatetimeIndex)TimedeltaIndex)concat)check_parent_directorystringify_path)printing)	ArrayLikeAxesColspaceArgTypeColspaceTypeCompressionOptionsFilePathFloatFormatTypeFormattersType
IndexLabelSequenceNotStrStorageOptionsWriteBuffer)	DataFrameSeriesa	  
        Parameters
        ----------
        buf : str, Path or StringIO-like, optional, default None
            Buffer to write to. If None, the output is returned as a string.
        columns : array-like, optional, default None
            The subset of columns to write. Writes all columns by default.
        col_space : %(col_space_type)s, optional
            %(col_space)s.
        header : %(header_type)s, optional
            %(header)s.
        index : bool, optional, default True
            Whether to print index (row) labels.
        na_rep : str, optional, default 'NaN'
            String representation of ``NaN`` to use.
        formatters : list, tuple or dict of one-param. functions, optional
            Formatter functions to apply to columns' elements by position or
            name.
            The result of each function must be a unicode string.
            List/tuple must be of length equal to the number of columns.
        float_format : one-parameter function, optional, default None
            Formatter function to apply to columns' elements if they are
            floats. This function must return a unicode string and will be
            applied only to the non-``NaN`` elements, with ``NaN`` being
            handled by ``na_rep``.
        sparsify : bool, optional, default True
            Set to False for a DataFrame with a hierarchical index to print
            every multiindex key at each row.
        index_names : bool, optional, default True
            Prints the names of the indexes.
        justify : str, default None
            How to justify the column labels. If None uses the option from
            the print configuration (controlled by set_option), 'right' out
            of the box. Valid values are

            * left
            * right
            * center
            * justify
            * justify-all
            * start
            * end
            * inherit
            * match-parent
            * initial
            * unset.
        max_rows : int, optional
            Maximum number of rows to display in the console.
        max_cols : int, optional
            Maximum number of columns to display in the console.
        show_dimensions : bool, default False
            Display DataFrame dimensions (number of rows by number of columns).
        decimal : str, default '.'
            Character recognized as decimal separator, e.g. ',' in Europe.
    r   common_docstring)leftrightcenterjustifyzjustify-allstartendinheritzmatch-parentinitialunsetz
        Returns
        -------
        str or None
            If buf is None, returns the result as a string. Otherwise returns
            None.
    return_docstringc            
      P    e Zd ZdZdddddddddd	ddZd dZd!dZd"dZd!dZdS )#SeriesFormatterz\
    Implement the main logic of Series.to_string, which underlies
    Series.__repr__.
    TNaNFN)	lengthheaderindexna_repnamefloat_formatdtypemax_rowsmin_rowsseriesrC   rR   
bool | strrS   boolrT   rU   strrV   rW   
str | NonerX   rY   
int | NonerZ   returnNonec       	        2   || _         t                      | _        || _        || _        || _        || _        || _        |	| _        |
| _	        |t          d          }|| _        || _        t          j                    | _        |                                  d S )Ndisplay.float_format)r[   r   bufrV   rU   rS   rR   rT   rY   rZ   r   rW   rX   r5   get_adjustmentadj_chk_truncate)selfr[   rR   rS   rT   rU   rV   rW   rX   rY   rZ   s              X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pandas/io/formats/format.py__init__zSeriesFormatter.__init__   s     ::	
  %&<==L(
*,,    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      )rZ   rY   lenr[   r   intminilocr2   
tr_row_num	tr_seriesis_truncated_vertically)ri   rZ   rY   rv   r[   row_nums         rj   rh   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'>$$$rl   c                   | j         j        }d}| j         j        }t          |t          t
          t          f          r|j        |d|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 )N zFreq: Fz, 	
)escape_charszName: TtruncatezLength: rV   zdtype: r}   )r[   rV   rT   
isinstancer0   r.   r1   freqfreqstrr5   pprint_thingrR   rv   rp   rX   getattrru   r!   _values_get_repr_footerr^   )ri   rV   footerrT   series_name
dtype_name
level_infos          rj   _get_footerzSeriesFormatter._get_footer   s   {!u}k>JKK	/
&.u}...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*,<== 	!/@@BBJ $j F6{{rl   	list[str]c                \    t          | j        j        d | j        | j        | j                  S )N)rW   rU   leading_space)format_arrayru   r   rW   rU   rT   ri   s    rj   _get_formatted_valuesz%SeriesFormatter._get_formatted_values(  s4    N"*;*
 
 
 	
rl   c                6   | j         }|                                 }t          |          dk    rt          | j                  j         d| dS |j        }t          |          }t          |t                    rL|
                    dd           }t          j                    } |j        dg|R                      d          }n|                    d          }|                                 }| 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  }t3          d                    |                    S )Nr   z([], )T)include_namessparsifyro   r}   include_namern      ...z..rG   modery   )ru   r   rp   typer[   __name__rT   
_has_namesr   r-   _format_multir5   rf   adjoinsplit_format_flatr   rv   rt   r   rq   rg   rH   insertrS   r^   join)ri   r[   r   rT   have_header	fmt_indexrg   
fmt_valuesn_header_rowsrw   widthdot_strresults                rj   	to_stringzSeriesFormatter.to_string1  s7   !!##v;;!4;''0@@v@@@@ ''eZ(( 	>++$+NNI)++C"
11y11177==II***==I//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??###rl   )r[   rC   rR   r\   rS   r]   rT   r]   rU   r^   rV   r]   rW   r_   rX   r]   rY   r`   rZ   r`   ra   rb   ra   rb   ra   r^   ra   r   )	r   
__module____qualname____doc__rk   rh   r   r   r    rl   rj   rP   rP      s          "#'##     @? ? ? ?6( ( ( (T
 
 
 
+$ +$ +$ +$ +$ +$rl   rP   ra   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)rY   rZ   max_colsmax_colwidthshow_dimensions
line_width)pandas.io.formatsr   r   get_console_size)r   r   _s      rj   get_dataframe_repr_paramsr   _  s    " *)))))-.. 0022
AA
122122455"#9::%&?@@   rl   c                     t                      \  } }t          d          }|dk    r|n|}|dk    r|nt          d          }dd||t          d          dS )a  Get the parameters used to repr(Series) calls using Series.to_string.

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

    .. versionadded:: 1.4.0

    Example
    -------
    >>> import pandas as pd
    >>>
    >>> ser = pd.Series([1, 2, 3, 4])
    >>> repr_params = pd.io.formats.format.get_series_repr_params()
    >>> repr(ser) == ser.to_string(**repr_params)
    True
    r   r   r   Tr   )rV   rX   rZ   rY   rR   )r   r   )r   heightmax_rows_optrY   rZ   s        rj   get_series_repr_paramsr     sy    " &''ME6011L%**vvH%**vv
;M0N0NH 677  rl   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.

    Used by DataFrame.to_string, which backs DataFrame.__repr__.
    ry   NTrQ   F.framerB   columnsAxes | None	col_spaceColspaceArgType | NonerS   bool | SequenceNotStr[str]rT   r]   rU   r^   
formattersFormattersType | NonerH   r_   rW   FloatFormatType | Noner   bool | Noneindex_namesrY   r`   rZ   r   r   r\   decimal	bold_rowsescapera   rb   c                   || _         |                     |          | _        |                     |          | _        || _        || _        || _        |                     |          | _	        | 
                    |          | _        |	| _        |                     |
          | _        || _        || _        || _        || _        || _        || _        || _        || _        |                                 | _        |                                 | _        | j         | _        |                                  t;          j                    | _        d S N) r   _initialize_columnsr   _initialize_colspacer   rS   rT   rU   _initialize_formattersr   _initialize_justifyrH   rW   _initialize_sparsifyr   show_index_namesr   r   r   rY   rZ   r   r   _calc_max_cols_fittedmax_cols_fitted_calc_max_rows_fittedmax_rows_fittedtr_framer   r5   rf   rg   )ri   r   r   r   rS   rT   rU   r   rH   rW   r   r   rY   rZ   r   r   r   r   r   s                      rj   rk   zDataFrameFormatter.__init__  s   * 
//88229==
55jAA//88(11(;; +"   .#99;;#99;;
*,,rl   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_indexrT   _get_formatted_indexr   r   )ri   strcols	str_indexs      rj   get_strcolszDataFrameFormatter.get_strcols  sM     1133: 	)11$-@@INN1i(((rl   c                8    | j         du p| j         dk    o| j        S )NTr   )r   is_truncatedr   s    rj   should_show_dimensionsz)DataFrameFormatter.should_show_dimensions  s*    #t+ 
 J.D43D	
rl   c                8    t          | j        p| j                  S r   )r]   is_truncated_horizontallyrv   r   s    rj   r   zDataFrameFormatter.is_truncated  s    D2Rd6RSSSrl   c                d    t          | j        ot          | j                  | j        k              S r   )r]   r   rp   r   r   s    rj   r   z,DataFrameFormatter.is_truncated_horizontally  s*    D(Wc$,.?.?$BV.VXXXrl   c                d    t          | j        ot          | j                  | j        k              S r   )r]   r   rp   r   r   s    rj   rv   z*DataFrameFormatter.is_truncated_vertically  s(    D(Uc$*oo@T.TVVVrl   c                f    dt          | j                   dt          | j        j                   dS )Nz

[z rows x z	 columns])rp   r   r   r   s    rj   dimensions_infoz"DataFrameFormatter.dimensions_info  s0    Rs4:RRDJ4F0G0GRRRRrl   c                4    t          | j        j                  S r   )r   r   rT   r   s    rj   has_index_namesz"DataFrameFormatter.has_index_names  s    $**+++rl   c                4    t          | j        j                  S r   )r   r   r   r   s    rj   has_column_namesz#DataFrameFormatter.has_column_names  s    $*,---rl   c                D    t          | j        | j        | j        f          S r   )allr   rT   r   r   s    rj   show_row_idx_namesz%DataFrameFormatter.show_row_idx_names  s    D($*d6KLMMMrl   c                D    t          | j        | j        | j        f          S r   )r   r   r   rS   r   s    rj   show_col_idx_namesz%DataFrameFormatter.show_col_idx_names  s    D)4+@$+NOOOrl   rq   c                x    t          | j        pt          | j                  t          | j                            S r   )rr   rY   rp   r   r   s    rj   max_rows_displayedz%DataFrameFormatter.max_rows_displayed
  s)    4=3C
OOS__EEErl   c                (    |t          d          S |S )Nzdisplay.multi_sparser   )ri   r   s     rj   r   z'DataFrameFormatter._initialize_sparsify  s    4555rl   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   )rp   r   r   r   dict
ValueError)ri   r   s     rj   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  rl   c                (    |t          d          S |S )Nzdisplay.colheader_justifyr  )ri   rH   s     rj   r   z&DataFrameFormatter._initialize_justify   s    ?9:::Nrl   r,   c                d    |#t          |          }| j        |         | _        |S | j        j        S r   )r/   r   r   )ri   r   colss      rj   r   z&DataFrameFormatter._initialize_columns&  s3    ((DD)DJK:%%rl   r9   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 )Nry   c                    i | ]}|S r   r   ).0columnr   s     rj   
<dictcomp>z;DataFrameFormatter._initialize_colspace.<locals>.<dictcomp>5  s    NNN69NNNrl   z,Col_space is defined for an unknown column: zCol_space length(r  r   )r   rq   r^   updater   r   r   keysr  rp   r  zip)ri   r   r   r  s    `  rj   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rl   c                    |                                  s| j        S t                      \  }}|                     |          r|S | j        S )z%Number of columns fitting the screen.)_is_in_terminalr   r   _is_screen_narrow)ri   r   r   s      rj   r   z(DataFrameFormatter._calc_max_cols_fittedF  sP    ##%% 	!= $&&q!!%(( 	!L= rl   c                   |                                  rSt                      \  }}| j        dk    r||                                 z
  S |                     |          r|}n| j        }n| j        }|                     |          S )z,Number of rows with data fitting the screen.r   )r  r   rY   _get_number_of_auxiliary_rows_is_screen_short_adjust_max_rows)ri   r   r   rY   s       rj   r   z(DataFrameFormatter._calc_max_rows_fittedQ  s     !! 	%)++IAv}!! B B D DDD$$V,, )!=}H$$X...rl   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
        )rp   r   rZ   rr   )ri   rY   s     rj   r  z#DataFrameFormatter._adjust_max_rowsd  s<      	8DJ(***t}h77rl   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   rY   r   s    rj   r  z"DataFrameFormatter._is_in_terminalr  s#    DMQ&<$-1*<===rl   c                l    t          | j        dk    ot          | j        j                  |k              S Nr   )r]   r   rp   r   r   )ri   	max_widths     rj   r  z$DataFrameFormatter._is_screen_narrowv  s.    DMQ&N3tz/A+B+BY+NOOOrl   c                b    t          | j        dk    ot          | j                  |k              S r  )r]   rY   rp   r   )ri   
max_heights     rj   r  z#DataFrameFormatter._is_screen_shorty  s)    DMQ&G3tz??Z+GHHHrl   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.rn   )r   rp   r   
splitlinesrS   )ri   dot_row
prompt_rownum_rowss       rj   r  z0DataFrameFormatter._get_number_of_auxiliary_rows|  sZ    
Z' 	?D0;;==>>>H; 	MHrl   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)r   _truncate_horizontallyrv   _truncate_verticallyr   s    rj   r   zDataFrameFormatter.truncate  sN     ) 	*'')))' 	(%%'''''	( 	(rl   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
        Nro   rn   axis)r   r   rs   r2   r   r   listtupler   rq   r   
tr_col_num)ri   col_numrE   rF   s       rj   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!rl   c                   | j         J | j         dz  }|dk    rjt          | j                  }t          j        t          j        |          t          j        ||z
  |          g          }| j        j        |         | _        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
        Nro   rn   )r   rp   r   nphstackarangers   r   rq   rY   rt   )ri   rw   _len_slices       rj   r&  z'DataFrameFormatter._truncate_vertically  s     #///&!+a<<t}%%DY	' 2 2BIdWnd4S4STUUF M.v6DMM3..G M.xx{;DM!rl   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   )stringsrH   minimumrg   zWriting z cols but got z aliasesc                    g | ]}|gS r   r   )r  labels     rj   
<listcomp>zADataFrameFormatter._get_strcols_without_index.<locals>.<listcomp>  s    <<<uE7<<<rl   ry   c              3  L   K   | ]}j                             |          V  d S r   rg   rp   r  xri   s     rj   	<genexpr>z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>  s/      0R0RQa0R0R0R0R0R0Rrl   )r6  rg   c              3  L   K   | ]}j                             |          V  d S r   r;  r<  s     rj   r>  z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>  s/      @@DHLLOO@@@@@@rl   r   )r   rS   	enumerater   
format_col_make_fixed_widthrH   rq   r   getrg   appendr   r*  r^   rp   r   r  _get_formatted_column_labelsr   max)
ri   r   icr   str_columnsr=  cheaderheader_colwidthmax_lens
   `         rj   r   z-DataFrameFormatter._get_strcols_without_index  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rl   rG  r   c           
         | j         }|                     |          }t          |j        d d |f         j        || j        | j        | j                            |j	        |                   | j
        | j                  S )N)rW   rU   spacer   r   )r   _get_formatterr   rs   r   rW   rU   r   rC  r   r   rT   )ri   rG  r   	formatters       rj   rA  zDataFrameFormatter.format_col  sz    ''**	Jqqq!t$*;.$$U]1%566L*
 
 
 	
rl   	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   rq   r   rC  )ri   rG  s     rj   rO  z!DataFrameFormatter._get_formatter  s    doe}55 		0!}} aLLq))t!}} $$,!6!6LO?&&q$///rl   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             }nn|                    d	          } 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     rj   r>  zBDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>  s%      %T%TEe&7%T%T%T%T%T%Trl   c                8    |j         vr|          rsd|z   S |S )N )r   )r=  yneed_leadsprestrict_formattingri   s     rj   space_formatzEDataFrameFormatter._get_formatted_column_labels.<locals>.space_format  s4    T_,,#A -/ - 7Nrl   c              3  8   K   | ]fd D             V  dS )c                (    g | ]} |          S r   r   )r  r[  r^  r=  s     rj   r9  zMDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>.<listcomp>   s%    555a||Aq))555rl   Nr   )r  r=  r^  s    @rj   r>  zBDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>   s<      KK!555551555KKKKKKrl   c                ,    g | ]}t          |          S r   )r*  r  r=  s     rj   r9  zCDataFrameFormatter._get_formatted_column_labels.<locals>.<listcomp>%  s    DDDq477DDDrl   r   c                `    g | ]*\  }}                     |          s|         rd |z   n|g+S )rZ  )rO  )r  rG  r=  r\  ri   s      rj   r9  zCDataFrameFormatter._get_formatted_column_labels.<locals>.<listcomp>*  sT       Aq !% 3 3A 6 6P;q>PqqQ  rl   )pandas.core.indexes.multirU  r   r   r-   r   r*  r  r   dtypesr   anylevelsr  mapr   r   rp   r   r@  )ri   r   rU  r   fmt_columnsre  str_columns_tuplerI  r\  r]  r^  s   `       @@@rj   rE  z/DataFrameFormatter._get_formatted_column_labels  s   ======-gz**  	!//e/TTK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! ! } G%6!7!7 G$3O4E$F$F!DDC1B,CDDDKK!..E.BBKZ&Fs;4Df0M0MNNOOK    %k22  K
 rl   c                $    d  j                                         D             |j        }|j        }                     d          }t          |t                    r#|                     j         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   rq   )r  kvs      rj   r  z;DataFrameFormatter._get_formatted_index.<locals>.<dictcomp>4  s&    HHHAQS!HHHrl   	__index__)r   r   rP  )r   rP  c                    g | ]H}t          t          t          |          d                     dd          j                            IS )rE   ry   r   )rH   r6  rg   )r+  rB  r*  rC  rg   )r  r=  r   ri   s     rj   r9  z;DataFrameFormatter._get_formatted_index.<locals>.<listcomp>D  sf     
 
 
  !GGVY]]2q5I5Itx   
 
 
rl   rn   r}   c                ,    g | ]}t          |          S r   r^   rb  s     rj   r9  z;DataFrameFormatter._get_formatted_index.<locals>.<listcomp>Q  s    GGGQ#a&&GGGrl   ry   )r   itemsrT   r   rO  r   r-   r   r   r   r   rg   r   r   r   _get_column_name_listnlevelsrS   )	ri   r   rT   r   fmtr   adjoined
col_headerr   s	   `       @rj   r   z'DataFrameFormatter._get_formatted_index1  sX    IH1E1E1G1GHHH	-!!+..eZ(( 		++"5 ,  II ""0GSV"WWI
 
 
 
 
 
 
 
	 #48?11y11177== " 	0GG$*D*D*F*FGGGJJ/J; 	((Orl   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 )Nry   r   )r  rV   s     rj   r>  z;DataFrameFormatter._get_column_name_list.<locals>.<genexpr>^  s*      PP$t|PPPPPPrl   ry   )r   r   r   r-   extendnamesrD  rV   )ri   r}  r   s      rj   rt  z(DataFrameFormatter._get_column_name_listZ  sn     "*$gz** 	GLLPP'-PPPPPPPLLw|3FFFrl   )NNTTrQ   NNNNTNNNFr   FT)&r   rB   r   r   r   r   rS   r   rT   r]   rU   r^   r   r   rH   r_   rW   r   r   r   r   r]   rY   r`   rZ   r`   r   r`   r   r\   r   r^   r   r]   r   r]   ra   rb   )ra   r   ra   r]   r   )ra   rq   )r   r   ra   r]   )r   r   ra   r=   )rH   r_   ra   r^   )r   r   ra   r,   )r   r   ra   r9   )ra   r`   )rY   r`   ra   r`   r   )rG  rq   ra   r   )rG  rQ  ra   rR  )r   rB   ra   r   )r   rB   ra   r   )ra   ry  )(r   r   r   r   rD   rN   rk   r   propertyr   r   r   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r   r%  r&  r   rA  rO  rE  r   rt  r   rl   rj   r   r     s         !(ggbG"222G
  $,0-1,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' ' ' 'R     rl   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.
    rv  r   ra   rb   c                    || _         d S r   )rv  )ri   rv  s     rj   rk   zDataFrameRenderer.__init__u  s    rl   NFre   "FilePath | WriteBuffer[str] | Noneencodingr_   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  re   r  )pandas.io.formats.htmlr  r  rv  r   save_to_buffer)ri   re   r  r  r  r  r  r  r  r  Klasshtml_formatterstrings                rj   to_htmlzDataFrameRenderer.to_htmlx  s    D	
 	
 	
 	
 	
 	
 	
 	

 &.@!!=H%
 
 
  ))++f#AAAArl   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  rv  r   r  )ri   re   r  r   r  string_formatterr  s          rj   r   zDataFrameRenderer.to_string  sS    ( 	=<<<<<*?48
KKK!++--f#AAAArl   ,winfer"Tstrictpath_or_buf7FilePath | WriteBuffer[bytes] | WriteBuffer[str] | Nonesepr^   r   Sequence[Hashable] | Noneindex_labelIndexLabel | Noner   compressionr:   quoting	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  r  r  r  r   r  r  r  r  r  r  rP  r   )pandas.io.formats.csvsr  r   rv  saver   getvalueclose)ri   r  r  r  r   r  r   r  r  r  r  r  r  r  r  r  r  r  created_buffercsv_formattercontents                        rj   to_csvzDataFrameRenderer.to_csv  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trl   )rv  r   ra   rb   )NNNFNNF)re   r  r  r_   r  r  r  r]   r  r  r  r_   r  r]   ra   r_   )NNN)re   r  r  r_   r   r`   ra   r_   )NNr  NNr  r  Nr  NNNTNr  N)"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  ra   r_   )r   r   r   r   rk   r  r   r  r   rl   rj   r  r  d  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rl   r  r  r^   re   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  re   r  fds       rj   r  r    s     
S8	,	,	, 
;;;==	       
                  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  ry   )r  newlinez1buf is not a file name and it has no write method)	r4   r   r   r^   r  hasattrr3   open	TypeError)re   r  fs      rj   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<rQ   rF   r   Tvaluesr6   rP  rR  rW   r   rU   digitsr`   rN  str | int | NonerH   r   r   r   r  fallback_formatterr   c                   t          j        | j        d          rt          }t	          t
          |           } nt          | j        t                    rt          }t	          t
          |           } nt          j        | j        d          rt          }t	          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 : np.ndarray or ExtensionArray
    formatter
    float_format
    na_rep
    digits
    space
    justify
    decimal
    leading_space : bool, optional, default True
        Whether the array should be formatted with a leading space.
        When an array as a column of a Series or DataFrame, we do want
        the leading space to pad between columns.

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

    Returns
    -------
    List[str]
    MmfciuN   rd   display.precision)
r  rU   rW   rP  rN  rH   r   r   r  r  )r   is_np_dtyperX   _Datetime64Formatterr   r'   r   r"   _Datetime64TZFormatter_Timedelta64Formatterr)   r#   _ExtensionArrayFormatterFloatArrayFormatter_IntArrayFormatter_GenericArrayFormatterr   
get_result)r  rP  rW   rU   r  rN  rH   r   r   r  r  	fmt_klassfmt_objs                rj   r   r   7  s]   R v|S)) +(	mV,,	FL/	2	2 +*	mV,,	s	+	+ 
+)	nf--	FL.	1	1 +,			t	,	, +'			t	,	, +&		*	}!"899~/00i!#-  G rl   c                  >    e Zd Z	 	 	 	 	 	 	 	 	 	 	 d#d$dZd%d!Zd%d"ZdS )&r     NrQ   r  rF   r   Tr  r6   r  rq   rP  rR  rU   r^   rN  rQ  rW   r   rH   r   r  r`   fixed_widthr]   r   r   r  ra   rb   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        d S r   )r  r  rU   rN  rP  rW   rH   r   r  r  r   r  )ri   r  r  rP  rU   rN  rW   rH   r   r  r  r   r  s                rj   rk   z_GenericArrayFormatter.__init__  sb     
"(&*"4rl   r   c                T    |                                  }t          || j                  S r   )_format_stringsrB  rH   )ri   r   s     rj   r  z!_GenericArrayFormatter.get_result  s%    ))++
 T\:::rl   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} j	        }t          |t          j                  st          d          t          j        |t                     }|t          j        t%          |          t'          t)          dt+          |j                                      	          z  } j        }||                                }g }t3          |          D ]\  }	}
||	         r j        $|r"|                    d
 ||
                      8||	         r|                     ||
                     _|du rd}nd}|                    |                     ||
                               |S )Nrd   r  c                0    t          | ddd          S )Nz .dr  )_trim_zeros_single_float)r=  	precisions    rj   <lambda>z8_GenericArrayFormatter._format_strings.<locals>.<lambda>  s)    )A+I+++++* * rl   rz   )r~   quote_stringsc                .   j         t          |           rt          |           r| dS | t          u rt	          t                    S t          j        |           r#t          j        |           rt	          |           S | t          u s&t          | t          j        t          j        f          rdS j         S t          | t                    rt	          |           S t          | t                    rt          |           S t	           |                     S )Nrb   r   )rU   r    r$   r   r^   r   r   r/  isinfr   r   
datetime64timedelta64r+   r*   repr)r=  rP  ri   s    rj   _formatz7_GenericArrayFormatter._format_strings.<locals>._format  s    {&9Q<<&DGG&9!6"WWr77N\!__ !! ! q66M#XXAr~/N!O!OX 5{"A|,, )1vvA{++ )Aww 99Q<<(((rl   z=ExtensionArray formatting should use _ExtensionArrayFormatterrn   r(  rZ  Fz{v}z {v})rn  )rW   r   rP  r  r  r	   r   r5   r   r  r   r/  ndarrayr  r   	map_inferr   r   r%   r+  rangerp   shaper   rf  r@  rD  format)ri   rW   r  r  valsinferredis_float_typer   r   rG  rn  tplrP  r  s   `           @@rj   r  z&_GenericArrayFormatter._format_strings  sH   $%&<==L#&':;;	         ,L>%II$0/II L4S9SM%/+  I	) 	) 	) 	) 	) 	)* {$
++ 	O   =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*":":;;;;rl   )r  NrQ   r  NrF   r   NTTN)r  r6   r  rq   rP  rR  rU   r^   rN  rQ  rW   r   rH   r^   r   r^   r  r`   r  r]   r   r   r  rR  ra   rb   r   )r   r   r   rk   r  r  r   rl   rj   r  r    s~         %)/3" %).25 5 5 5 58; ; ; ;J J J J J Jrl   r  c                  >     e Zd Zd fdZ	 	 ddd
ZddZddZ xZS )r  ra   rb   c                     t                      j        |i | | j        7| j        2d| _        t          | j                  r| j        | _        d | _        d S d S d S d S NF)superrk   rW   rP  r  callable)ri   argskwargs	__class__s      rj   rk   zFloatArrayFormatter.__init__  s|    $)&))) (T^-C$D)** )!%!2$(!!! )(-C-C) )rl   NrW   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%   rU   )rn  rW   ri   s    rj   base_formatterz<FloatArrayFormatter._value_formatter.<locals>.base_formatter  s;    #/// Qxx%LLq))))rl   c                N    t          |           rt          |           nj        S r   )r%   r^   rU   )rn  ri   s    rj   r  z<FloatArrayFormatter._value_formatter.<locals>.base_formatter&  s     !&q:s1vvvt{:rl   r   c                N     |                                dj        d          S )Nr   rn   )replacer   )rn  r  ri   s    rj   decimal_formatterz?FloatArrayFormatter._value_formatter.<locals>.decimal_formatter+  s'    %~a((00dlAFFFrl   c                    t          |           r)t          |           k    r |           S  d          S j        S )Ng        )r%   absrU   )r  r  ri   r  s    rj   rP  z7FloatArrayFormatter._value_formatter.<locals>.formatter4  sL    U|| #u::	)),,U333,,S111{"rl   )rW   r   )ri   rW   r  rP  r  r  s   ``` @@rj   _value_formatterz$FloatArrayFormatter._value_formatter  s     ,L  	;	 	 	 	 	 	 	; ; ; ; ; <3G G G G G G G !/$$	# 	# 	# 	# 	# 	# 	# rl   
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  r6   rP  r   rU   r^   c                    t          |           }t          j        fdt          |                                 |                                          D                                           | j                  }|S )Nc                4    g | ]\  }}|s |          nS r   r   )r  valr  rP  rU   s      rj   r9  zWFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_rep.<locals>.<listcomp>H  s>       Q +,7IIcNNN  rl   )r$   r/  arrayr  ravelreshaper  )r  rP  rU   mask	formatteds    ``  rj   format_with_na_repzCFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_repE  s    <<D    "%fllnndjjll"C"C   
 gfl##  rl   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/  realr  imagr$   r  rD  strip
startswithr  r  r  )r  rP  rU   real_valuesimag_values	real_mask	imag_maskformatted_lstr  real_valimag_valre_isnaim_isnaimag_formatteds                 rj   format_complex_with_na_repzKFloatArrayFormatter.get_result_as_array.<locals>.format_complex_with_na_repO  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<@@@rl   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 )NrE   rZ  objectrX   )r  rH   rU   r  r   r  _trim_zeros_complexr   _trim_zeros_floatr/  asarray)
rW   rP  rU   r  
is_complexr   r)  r  ri   r  s
         rj   format_values_withzCFloatArrayFormatter.get_result_as_array.<locals>.format_values_withu  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Mrl   Tz{value: .{digits:d}f}z{value:.{digits:d}f})r  c                    j         | z  S r   )rW   )r  ri   s    rj   r  z9FloatArrayFormatter.get_result_as_array.<locals>.<lambda>  s    ):U)B rl   r   c              3  4   K   | ]}t          |          V  d S r   rp   rb  s     rj   r>  z:FloatArrayFormatter.get_result_as_array.<locals>.<genexpr>  s(      ::AQ::::::rl      Fg    .A
   z{value: .{digits:d}e}z{value:.{digits:d}e})r  r6   rP  r   rU   r^   )rP  r  rU   r  r   rW   r   r   r  r  rp   rF  r/  r
  rf  )ri   r1  fmt_strrW   formatted_valuesmaxlentoo_longabs_valshas_large_valueshas_small_valuesr)  r  r  s   `         @@@rj   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,??rl   r   c                D    t          |                                           S r   )r*  r>  r   s    rj   r  z#FloatArrayFormatter._format_strings  s    D,,..///rl   r   NN)rW   r   r  r   ra   r   )ra   r  r   )r   r   r   rk   r  r>  r  __classcell__r  s   @rj   r  r    s        
) 
) 
) 
) 
) 
) 04"&6 6 6 6 6p~  ~  ~  ~ @0 0 0 0 0 0 0 0rl   r  c                      e Zd ZddZdS )r  ra   r   c                `    | j         du rd }nd }| j        p|fd| j        D             }|S )NFc                2    | d                     |           S )Nr  r=  r  rF  s    rj   r  z4_IntArrayFormatter._format_strings.<locals>.<lambda>  s    hhooo&:&: rl   c                2    | d                     |           S )Nz drF  rG  rF  s    rj   r  z4_IntArrayFormatter._format_strings.<locals>.<lambda>  s    ii&6&6&6&;&; rl   c                &    g | ]} |          S r   r   r  r=  rP  s     rj   r9  z6_IntArrayFormatter._format_strings.<locals>.<listcomp>  s!    888qiill888rl   )r   rP  r  )ri   formatter_strr   rP  s      @rj   r  z"_IntArrayFormatter._format_strings  sP    &&::MM;;MN3m	8888DK888
rl   Nr   )r   r   r   r  r   rl   rj   r  r    s(             rl   r  c                  :     e Zd ZU ded<   	 	 dd fd
ZddZ xZS )r  r'   r  r   Nnat_repr^   r  rb   ra   c                X     t                      j        |fi | || _        || _        d S r   )r  rk   rM  r  )ri   r  rM  r  r  r  s        rj   rk   z_Datetime64Formatter.__init__  s9     	**6***&rl   r   c                      j         } j         fd|D             S |                     j         j                  }|                                S )z&we by definition have DO NOT have a TZNc                :    g | ]}                     |          S r   )rP  r<  s     rj   r9  z8_Datetime64Formatter._format_strings.<locals>.<listcomp>  s%    666!DNN1%%666rl   )rU   r  )r  rP  _format_native_typesrM  r  tolist)ri   r  r   s   `  rj   r  z$_Datetime64Formatter._format_strings  sd    >%6666v666600<T-= 1 
 

   """rl   r   N)r  r'   rM  r^   r  rb   ra   rb   r   r   r   r   __annotations__rk   r  rA  rB  s   @rj   r  r    sl         
  		' 	' 	' 	' 	' 	' 	'
# 
# 
# 
# 
# 
# 
# 
#rl   r  c                  "    e Zd ZU ded<   ddZdS )r  r(   r  ra   r   c                d   | j         }| j        }d }||                    d          }t          |t                    r|                                }nt          j        |t                    }t          ||| j
        | j        | j        | j        | j        | j        | j        | j        |          }|S )NT)boxedr,  )	rW   rU   r  rN  rH   r   r   r  r  )r  rP  
_formatterr   r&   _internal_get_valuesr/  r/  r+  r   rW   rU   r  rN  rH   r   r   r  )ri   r  rP  r  r  r   s         rj   r  z(_ExtensionArrayFormatter._format_strings  s    N	!!'!2!2!2!>!>fk** 	5//11EEJvV444E!*;;*LL,L1
 
 

 rl   Nr   r   r   r   rU  r  r   rl   rj   r  r    s6              rl   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                    }t          j	        ||           }t          j        |          r&|                    t                    }d |D             S t          j        |           }t          |          }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   rn   z/percentiles should all be in the interval [0,1]d   c                    g | ]}|d z   S %r   r  rG  s     rj   r9  z&format_percentiles.<locals>.<listcomp>>  s    %%%AC%%%rl   r,  c                    g | ]}|d z   S ra  r   rc  s     rj   r9  z&format_percentiles.<locals>.<listcomp>F  s    !!!AG!!!rl   )r/  r/  r   r   r  get_precisionroundastyperq   iscloser^   unique
empty_liker+  )r\  precpercentiles_round_typeint_idxoutunique_pctss         rj   format_percentilesrp  
  s   D *[))K [))LvkQ&''L vkQ&''L
 JKKK#K%%D(..t44;;C@@j/==G	vg &$++C00%%%%%%)K((K%%D
-6
2
2
2Cw'--//66s;;BB3GGCL)//55<<SAACM!!S!!!!rl   r  rq   c                r   | d         dk    r| d         nd }| d         dk     rd| d         z
  nd }t          j        | ||          }t          |          }t          j        t          j        t          j        |                                                  t                     }t          d|          }|S )Nr   r_  )to_beginto_endrn   )	r/  ediff1dr
  floorlog10rr   rg  rq   rF  )r  rs  rt  diffrk  s        rj   re  re  I  s     8a<<uQxxTH %b	CS59__TF:ehv>>>Dt99DHRXbfTll++,,33C888Dq$<<DKrl   r   r=  NaTType | TimestamprM  c                6    | t           u r|S t          |           S r   )r   r^   r=  rM  s     rj   _format_datetime64r|  S  s    Cxx q66Mrl   r  c                l    t          | t                    r|S |r|                     |          S | j        S r   )r   r   strftime
_date_repr)r=  rM  r  s      rj   _format_datetime64_dateonlyr  \  s?    
 !W  zz+&&& |rl   is_dates_onlyr]   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)rM  r  )r  )r=  r  rM  s    rj   r  z'get_format_datetime64.<locals>.<lambda>r  s    4wK
 
 
 rl   c                &    t          |           S )N)rM  )r|  r{  s    rj   r  z'get_format_datetime64.<locals>.<lambda>v  s    +Aw??? rl   r   )r  rM  r  s    ``rj   get_format_datetime64r  k  s?      @
 
 
 
 
 	
 @????rl   c                  "    e Zd ZU ded<   ddZdS )r  r'   r  ra   r   c                    | j         j        }| j                             t                    }| j        pt          || j                  fd|D             }|S )zwe by definition have a TZ)r  c                &    g | ]} |          S r   r   rJ  s     rj   r9  z:_Datetime64TZFormatter._format_strings.<locals>.<listcomp>  s!    333qiill333rl   )r  _is_dates_onlyrg  r+  rP  r  r  )ri   idor  r   rP  s       @rj   r  z&_Datetime64TZFormatter._format_strings|  si    k(##F++N 
&;T-'
 '
 '
	 4333F333
rl   Nr   r[  r   rl   rj   r  r  y  s6         	 	 	 	 	 	rl   r  c                  8     e Zd ZU ded<   	 dd fdZdd
Z xZS )r  r)   r  r   rM  r^   ra   rb   c                J     t                      j        |fi | || _        d S r   )r  rk   rM  )ri   r  rM  r  r  s       rj   rk   z_Timedelta64Formatter.__init__  s/     	**6***rl   r   c                p    | j         pt          | j        | j        d          fd| j        D             S )NF)rM  boxc                &    g | ]} |          S r   r   rJ  s     rj   r9  z9_Timedelta64Formatter._format_strings.<locals>.<listcomp>  s!    222		!222rl   )rP  get_format_timedelta64r  rM  )ri   rP  s    @rj   r  z%_Timedelta64Formatter._format_strings  sJ    N 
&<K5'
 '
 '
	 3222dk2222rl   r   )r  r)   rM  r^   ra   rb   r   rT  rB  s   @rj   r  r    si         
       3 3 3 3 3 3 3 3rl   r  Fr)   str | floatr  c                6    | j         }|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
    Nlongc                    | t          |           rt          |           rS t          | t                    st          |           } |                               }rd| d}|S )NrG  ')r    r$   r   r   
_repr_base)r=  r   r  r  rM  s     rj   rY  z*get_format_timedelta64.<locals>._formatter  sm    919$q''9N!Y'' 	!A V,, 	#"]]]Frl   )r  )r  rM  r  	even_daysrY  r  s    ``  @rj   r  r    sN     %I        rl   r5  r6  rg   printing._TextAdjustment | Nonec                \   t          |           dk    s|dk    r| S |t          j                    n|t          fd| D                       |t          |          t	          d          k    rdfdfd	| D             }                     | |
          }|S )Nr   r   c              3  B   K   | ]}                     |          V  d S r   r4  )r  r=  
adjustments     rj   r>  z$_make_fixed_width.<locals>.<genexpr>  s/      55*..##555555rl   r   r=  r^   ra   c                l    0dk                         |           k    z  r| d dz
           dz   } | S )Nr   r   r4  )r=  r  conf_maxrL  s    rj   justz_make_fixed_width.<locals>.just  sG    1!2!2W!<= -m!m$u,rl   c                &    g | ]} |          S r   r   )r  r=  r  s     rj   r9  z%_make_fixed_width.<locals>.<listcomp>  s!    (((1ttAww(((rl   r   )r=  r^   ra   r^   )rp   r5   rf   rF  r   rH   )	r5  rH   r6  rg   r   r  r  r  rL  s	        @@@@rj   rB  rB    s     7||qGu,,
{,..


5555W55555Ggw''011H( 2 2        )((((((Gw??FMrl   str_complexesc                  	 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+-])ry   Nr   c              3  4   K   | ]}t          |          V  d S r   r4  )r  parts     rj   r>  z&_trim_zeros_complex.<locals>.<genexpr>  s(      ;;dD		;;;;;;rl   rn   c                R    g | ]#\  }}||d          z   |dd         d z   dz   $S )r   rn   N>r  r   )r  real_ptimag_ptpadded_lengths      rj   r9  z'_trim_zeros_complex.<locals>.<listcomp>  sc       
 GW	 	
!*	QRR[
+=
+
+
+	, 	  rl   )rer   rD  r   rp   r.  rF  r  )
r  r   	real_part	imag_partr=  trimmednpadded_partspaddedr  s
            @rj   r-  r-    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 Mrl   	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    rj   r  r    s=    
   %%I# S	rl   
str_floatsArrayLike | 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]*$ra   r]   c                2    t          j        |           d uS r   )r  match)r=  number_regexs    rj   is_number_with_decimalz1_trim_zeros_float.<locals>.is_number_with_decimal  s    xa((44rl   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     rj   r9  z:_trim_zeros_float.<locals>.should_trim.<locals>.<listcomp>#  s*    BBB(>(>q(A(AB1BBBrl   r   c              3  @   K   | ]}|                     d           V  dS )r  Nr  rb  s     rj   r>  z9_trim_zeros_float.<locals>.should_trim.<locals>.<genexpr>$  s,      'I'IA

3'I'I'I'I'I'Irl   )rp   r   )r  numbersr  s     rj   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Irl   c                >    g | ]} |          r
|d d         n|S )Nrr  r   r  s     rj   r9  z%_trim_zeros_float.<locals>.<listcomp>'  s6    OOO!33A66=1SbS66AOOOrl   c                ^    g | ])} |          r|                               r|d z   n|*S )r  r  )r  r=  r   r  s     rj   r9  z%_trim_zeros_float.<locals>.<listcomp>*  sR        *)!,,KG1D1DKC!  rl   r~  )r  r  ra   r]   )r  compile)r  r   r  r  r   r  r  s    `   @@rj   r.  r.    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 Mrl   rT   r,   c                d    t          | t                    rt          j        | j         S | j        d uS r   )r   r-   comany_not_noner}  rV   )rT   s    rj   r   r   1  s1    %$$ &--z%%rl   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   ry   r   rm  r5  r  	   Gr  T   P   E   Z   YNFaccuracyr`   use_eng_prefixr]   ra   rb   c                "    || _         || _        d S r   r  r  )ri   r  r  s      rj   rk   zEngFormatter.__init__T  s     !,rl   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
        rQ   infrn   r   rr  r   zE-02dzE+r6  Nz{mant: g}{prefix}z{mant: .r  z
f}{prefix})mantprefix)r
   r^   is_nanis_infiniterq   mathrv  rw  rr   rF  ENG_PREFIXESr  r  r  r  )
ri   r  dnumsignpow10	int_pow10r  r  
format_strr  s
             rj   __call__zEngFormatter.__call__Z  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%??	rl   r  )r  r`   r  r]   ra   rb   )r  r  ra   r^   )r   r   r   r   r  rk   r  r   rl   rj   r  r  8  s!        SS 	S 	S	
 	S 	C 	C 	C 	
2 	
3 	
3 	
3 	C 	C 	C  	C!" 	C#L* CH- - - - -; ; ; ; ; ;rl   r  r   r  r  rb   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
    rd   N)r   r  r  s     rj   set_eng_float_formatr    s&    n %|Hn'M'MNNNNNrl   ry   rg  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)rp   r@  rD  )	rg  r  controlr   rX  
last_indexlengthsrG  keys	            rj   get_level_lengthsr    s    $ 6{{a	fs6!9~~%GF  
&& 	 	FAsqz cXoo"
&'*n
#

!%jj:5
gMrl   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^   rb  s     rj   r>  z#buffer_put_lines.<locals>.<genexpr>  s,      
-
-!:a
-
-
-
-
-
-rl   c                ,    g | ]}t          |          S r   rr  rb  s     rj   r9  z$buffer_put_lines.<locals>.<listcomp>	  s    '''AQ'''rl   r}   N)rf  r  r   )re   r  s     rj   buffer_put_linesr    sZ     
-
-u
-
-
--- ('''''IIdiirl   )ra   r   r@  )r  r^   re   r  r  r_   ra   r_   r   )re   r  r  r_   ra   r  )	NrQ   NNrF   r   TNN)r  r6   rP  rR  rW   r   rU   r^   r  r`   rN  r  rH   r^   r   r^   r   r   r  r`   r  rR  ra   r   )r\  r]  ra   r   )r  r]  ra   rq   r  )r=  ry  rM  r^   ra   r^   rS  )r=  ry  rM  r^   r  r_   ra   r^   )r  r]   rM  r^   r  r_   ra   r   )r   F)r  r)   rM  r  r  r]   ra   r   )rF   NN)
r5  r   rH   r^   r6  r`   rg   r  ra   r   )r   )r  r6   r   r^   ra   r   )r  r^   ra   r^   )r  r  r   r^   ra   r   )rT   r,   ra   r]   )r   F)r  rq   r  r]   ra   rb   )ry   )rg  r   r  r  ra   r  )re   r  r  r   ra   rb   )r   
__future__r   collections.abcr   r   r   r   
contextlibr   csvr	   r   r
   	functoolsr   ior   r  r  shutilr   typingr   r   r   r   r   numpyr/  pandas._config.configr   r   pandas._libsr   pandas._libs.missingr   pandas._libs.tslibsr   r   r   pandas._libs.tslibs.nattyper   pandas.core.dtypes.commonr   r   r   r   r   r    pandas.core.dtypes.dtypesr!   r"   r#   pandas.core.dtypes.missingr$   r%   pandas.core.arraysr&   r'   r(   r)   pandas.core.arrays.string_r*   pandas.core.baser+   pandas.core.commoncorecommonr  pandas.core.indexes.apir,   r-   r.   r/   pandas.core.indexes.datetimesr0   pandas.core.indexes.timedeltasr1   pandas.core.reshape.concatr2   pandas.io.commonr3   r4   r   r5   pandas._typingr6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   pandasrB   rC   rD   rU  VALID_JUSTIFY_PARAMETERSrN   rP   r   r   r   r  r  r  r   r  r  r  r  r  rp  re  r|  r  r  r  r  r  rB  r-  r  r.  r   r  r  r  r  r   rl   rj   <module>r#     s     # " " " " "            & % % % % %                          				 $ $ $ $ $ $                        
       # # # # # #         
 0 / / / / /                        
       
            3 2 2 2 2 2 ) ) ) ) ) )                              8 7 7 7 7 7 9 9 9 9 9 9 - - - - - -        ' & & & & &                                   6  6 6 6 6p      _$ _$ _$ _$ _$ _$ _$ _$D   B   >B B B B B B B BJZ Z Z Z Z Z Z Z~ /3      DHM M M M MP ,0"!%*.R  R  R  R  R jk k k k k k k k\F0 F0 F0 F0 F00 F0 F0 F0R    /   # # # # #1 # # #6    5   B<" <" <" <"~        "      JN@ @ @ @ @    1   3 3 3 3 32 3 3 3, !    H +/	    D    B	 	 	 	 7:! ! ! ! !H& & & &] ] ] ] ] ] ] ]@7O 7O 7O 7O 7Ov 24( ( ( ( (V           rl   