
    OwgO                      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&      ZjdNd'ZkdNd(Zl G d) d*      Zm G d+ d,      Zn	 	 dO	 	 	 	 	 	 	 dPd-Zoe		 dQ	 	 	 	 	 dRd.       Zp	 	 	 	 	 	 	 	 	 dS	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dTd/Zq G d0 d1      Zr G d2 d3er      Zs G d4 d5er      Zt G d6 d7er      Zu G d8 d9er      Zv	 	 	 	 dUd:ZwdVd;ZxdWdXd<Zy	 	 dY	 	 	 	 	 	 	 dZd=Zz	 dY	 	 	 	 	 	 	 d[d>Z{ G d? d@eu      Z| G dA dBer      Z}	 	 d\	 	 	 	 	 	 	 d]dCZ~	 	 	 d^	 	 	 	 	 	 	 	 	 d_dDZd`dadEZdbdFZ	 d`	 	 	 	 	 dcdGZdddHZ G dI dJ      ZdedfdKZ	 dg	 	 	 	 	 dhdLZdidMZy	)jz
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            
      x    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y)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_rowsc       	           || _         t               | _        || _        || _        || _        || _        || _        |	| _        |
| _	        |t        d      }|| _        || _        t        j                         | _        | j!                          y )Ndisplay.float_format)seriesr   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              O/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/io/formats/format.py__init__zSeriesFormatter.__init__   s     :	
  %&<=L(
**,    c                   |  | j                   }| j                  }|xr t        | j                        |kD  }| j                  }|rjt	        t
        |      }|rt        ||      }|dk(  r|}|j                  d | }n-|dz  }t        |j                  d | |j                  | d  f      }|| _	        nd | _	        || _
        || _        y )N      )rZ   rY   lenr]   r   intminilocr2   
tr_row_num	tr_seriesis_truncated_vertically)rb   rZ   rY   ro   r]   row_nums         rc   ra   zSeriesFormatter._chk_truncate   s    ==== #+"LDKK0@80K"C*H x21}"Yh/"a-Xg!6WHI8N OP%DO"DO'>$re   c                N   | 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rQ| j                  Et        | j                   j                  dd       }|r"|r|dz  }|dt        j                  |       z  }t        | j                   j                  t"              r0| j                   j$                  j'                         }|r|dz  }||z  }t)        |      S )N zFreq: Fz, 	
)escape_charszName: TtruncatezLength: rV   zdtype: rv   )r]   rV   rT   
isinstancer0   r.   r1   freqfreqstrr5   pprint_thingrR   ro   ri   rX   getattrrn   r!   _values_get_repr_footerstr)rb   rV   footerrT   series_name
dtype_name
level_infos          rc   _get_footerzSeriesFormatter._get_footer   s   {{!!u}k>JK

&u}}o..F99E!d&6$"//CUVK{m,,F;;$KK:%$*F*F$T[[!1 233F::U"tzz'= !5!5vtDJdNFGH$9$9*$E#FGG dnn**,<=//@@BJ$j F6{re   c                    t        | j                  j                  d | j                  | j                  | j
                        S )N)rW   rU   leading_space)format_arrayrn   r~   rW   rU   rT   rb   s    rc   _get_formatted_valuesz%SeriesFormatter._get_formatted_values(  s6    NN""**;;**
 	
re   c                   | j                   }| j                         }t        |      dk(  r%t        | j                        j
                   d| dS |j                  }t        |      }t        |t              rJ|j                  dd       }t        j                         } |j                  dg| j                  d      }n|j                  d      }| j!                         }| j"                  rd}| j$                  }	t'        t(        |	      }	| j*                  j                  ||	d	z
           }
|
d
kD  rd}nd}| j*                  j-                  |g|
d      d   }|j/                  |	|z   |       |j/                  |	d	z   d       | j                  r# | j*                  j                  d
g|d	d  |g }n| j*                  j                  d
|      }| j0                  r|r|d   dz   |z   }|r|d|z   z  }t3        dj5                  |            S )Nr   z([], )T)include_namessparsifyrh   rv   include_namerg      ...z..rG   moderr   )rn   r   ri   typer]   __name__rT   
_has_namesry   r-   _format_multir5   r_   adjoinsplit_format_flatr   ro   rm   r   rj   r`   rH   insertrS   r   join)rb   r]   r   rT   have_header	fmt_indexr`   
fmt_valuesn_header_rowsrp   widthdot_strresults                rc   	to_stringzSeriesFormatter.to_string1  s   !!#v;!4;;'001vha@@ 'eZ(++$+NI))+C"

11y177=I***=I//1
''MooG3(GHHLLGaK!89Eqy hh&&y%h&GJGg5w?Wq["-::$TXX__QE)AB-)DEFXX__Q
3F;;;q\D(61FdVm#F2776?##re   )r]   rC   rR   
bool | strrS   boolrT   r   rU   r   rV   r   rW   
str | NonerX   r   rY   
int | NonerZ   r   returnNoner   r   r   r   r   	list[str])	r   
__module____qualname____doc__rd   ra   r   r   r    re   rc   rP   rP      s     "#'## 	
     !    
@?6(T
+$re   rP   c                     ddl m}  t        d      r| j                         \  }}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      rc   get_dataframe_repr_paramsr   _  sa    " *-.002
A
121245"#9:%&?@  re   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        rc   get_series_repr_paramsr     s^    " &'ME601L%*vH%*v
;M0NH 67 re   c                     e Zd ZdZerendZeeez   z  Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d%	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d&dZd'dZed(d       Z	ed(d       Z
ed(d       Zed(d	       Zed)d
       Zed(d       Zed(d       Zed(d       Zed(d       Zed*d       Zd+dZ	 	 	 	 d,dZd-dZd.dZd/dZd0dZd0dZd1dZd(dZd(dZd(dZd*dZd2dZd2dZ d2dZ!d'dZ"d3d Z#d4d!Z$d5d"Z%d6d#Z&d7d$Z'y)8DataFrameFormatterz
    Class for processing dataframe formatting options and data.

    Used by DataFrame.to_string, which backs DataFrame.__repr__.
    rr   Nc                ^   || _         | j                  |      | _        | j                  |      | _        || _        || _        || _        | j                  |      | _	        | j                  |      | _        |	| _        | j                  |
      | _        || _        || _        || _        || _        || _        || _        || _        || _        | j/                         | _        | j3                         | _        | j                   | _        | j9                          t;        j<                         | _        y N) frame_initialize_columnscolumns_initialize_colspace	col_spacerS   rT   rU   _initialize_formatters
formatters_initialize_justifyrH   rW   _initialize_sparsifyr   show_index_namesdecimal	bold_rowsescaperY   rZ   r   r   _calc_max_cols_fittedmax_cols_fitted_calc_max_rows_fittedmax_rows_fittedtr_framerx   r5   r_   r`   )rb   r   r   r   rS   rT   rU   r   rH   rW   r   index_namesrY   rZ   r   r   r   r   r   s                      rc   rd   zDataFrameFormatter.__init__  s   * 
//8229=
55jA//8(11(; +"   .#99;#99;

**,re   c                    | j                         }| j                  r-| j                  | j                        }|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   )rb   strcols	str_indexs      rc   get_strcolszDataFrameFormatter.get_strcols  s@     113::11$--@INN1i(re   c                \    | j                   du xs | j                   dk(  xr | j                  S )NTrx   )r   is_truncatedr   s    rc   should_show_dimensionsz)DataFrameFormatter.should_show_dimensions  s3    ##t+ 
  J.D43D3D	
re   c                H    t        | j                  xs | j                        S r   )r   is_truncated_horizontallyro   r   s    rc   r   zDataFrameFormatter.is_truncated  s    D22Rd6R6RSSre   c                t    t        | j                  xr" t        | j                        | j                  kD        S r   )r   r   ri   r   r   s    rc   r   z,DataFrameFormatter.is_truncated_horizontally  s,    D((Wc$,,.?$BVBV.VXXre   c                t    t        | j                  xr" t        | j                        | j                  kD        S r   )r   r   ri   r   r   s    rc   ro   z*DataFrameFormatter.is_truncated_vertically  s+    D((Uc$**o@T@T.TVVre   c                t    dt        | j                         dt        | j                  j                         dS )Nz

[z rows x z	 columns])ri   r   r   r   s    rc   dimensions_infoz"DataFrameFormatter.dimensions_info  s0    s4::'xDJJ4F4F0G/H	RRre   c                @    t        | j                  j                        S r   )r   r   rT   r   s    rc   has_index_namesz"DataFrameFormatter.has_index_names  s    $****++re   c                @    t        | j                  j                        S r   )r   r   r   r   s    rc   has_column_namesz#DataFrameFormatter.has_column_names  s    $**,,--re   c                Z    t        | j                  | j                  | j                  f      S r   )allr   rT   r   r   s    rc   show_row_idx_namesz%DataFrameFormatter.show_row_idx_names  s$    D(($**d6K6KLMMre   c                Z    t        | j                  | j                  | j                  f      S r   )r   r   r   rS   r   s    rc   show_col_idx_namesz%DataFrameFormatter.show_col_idx_names  s$    D))4+@+@$++NOOre   c                    t        | j                  xs t        | j                        t        | j                              S r   )rk   rY   ri   r   r   s    rc   max_rows_displayedz%DataFrameFormatter.max_rows_displayed
  s(    4==3C

OS_EEre   c                     |t        d      S |S )Nzdisplay.multi_sparser   )rb   r   s     rc   r   z'DataFrameFormatter._initialize_sparsify  s    455re   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   )ri   r   r   ry   dict
ValueError)rb   r   s     rc   r   z)DataFrameFormatter._initialize_formatters  su     I##$J7:jRV;W$S_$5 6//24::3E3E/F.GqJ re   c                     |t        d      S |S )Nzdisplay.colheader_justifyr   )rb   rH   s     rc   r   z&DataFrameFormatter._initialize_justify   s    ?9::Nre   c                t    |!t        |      }| j                  |   | _        |S | j                  j                  S r   )r/   r   r   )rb   r   colss      rc   r   z&DataFrameFormatter._initialize_columns&  s7    (DD)DJK::%%%re   c                ~   |i }|S t        |t        t        f      r:d|i}|j                  | j                  j
                  D ci c]  }|| c}       |S t        |t              rE|j                         D ].  }|| j                  j
                  vs|dk7  s"t        d|        |}|S t        | j                  j
                        t        |      k7  r8t        dt        |       dt        | j                  j
                         d      t        t        | j                  j
                  |            }|S c c}w )Nrr   z,Col_space is defined for an unknown column: zCol_space length(r   r   )ry   rj   r   updater   r   r   keysr   ri   r   zip)rb   r   r   columns       rc   r   z'DataFrameFormatter._initialize_colspace.  s;    F$ # 	C:.)_FMM4::;M;MN69,NO  	7+#..* !3!33"$FvhO 
 F  4::%%&#i.8 'I'7 8336tzz7I7I3J2K1N  #djj00)<=F Os   
D:c                    | j                         s| j                  S t               \  }}| j                  |      r|S | j                  S )z%Number of columns fitting the screen.)_is_in_terminalr   r   _is_screen_narrow)rb   r   r   s      rc   r   z(DataFrameFormatter._calc_max_cols_fittedF  sA    ##%== $&q!!%(L== re   c                    | j                         rPt               \  }}| j                  dk(  r|| j                         z
  S | j	                  |      r|}n| j                  }n| j                  }| 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)rb   r   r   rY   s       rc   r   z(DataFrameFormatter._calc_max_rows_fittedQ  sr     !)+IAv}}! B B DDD$$V,!==}}H$$X..re   c                ~    |r:t        | j                        |kD  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
        )ri   r   rZ   rk   )rb   rY   s     rc   r  z#DataFrameFormatter._adjust_max_rowsd  s2     DJJ(*t}}h7re   c                T    t        | j                  dk(  xs | j                  dk(        S )z/Check if the output is to be shown in terminal.r   )r   r   rY   r   s    rc   r  z"DataFrameFormatter._is_in_terminalr  s$    DMMQ&<$--1*<==re   c                z    t        | j                  dk(  xr" t        | j                  j                        |kD        S Nr   )r   r   ri   r   r   )rb   	max_widths     rc   r  z$DataFrameFormatter._is_screen_narrowv  s/    DMMQ&N3tzz/A/A+BY+NOOre   c                f    t        | j                  dk(  xr t        | j                        |kD        S r  )r   rY   ri   r   )rb   
max_heights     rc   r
  z#DataFrameFormatter._is_screen_shorty  s(    DMMQ&G3tzz?Z+GHHre   c                    d}d}||z   }| j                   r&|t        | j                  j                               z  }| j                  r|dz  }|S )z?Get number of rows occupied by prompt, dots and dimension info.rg   )r   ri   r   
splitlinesrS   )rb   dot_row
prompt_rownum_rowss       rc   r	  z0DataFrameFormatter._get_number_of_auxiliary_rows|  sR    
Z'D00;;=>>H;;MHre   c                v    | j                   r| j                          | j                  r| j                          yy)zY
        Check whether the frame should be truncated. If so, slice the frame up.
        N)r   _truncate_horizontallyro   _truncate_verticallyr   s    rc   rx   zDataFrameFormatter.truncate  s3     ))'')''%%' (re   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      rlg | j
                  d| | j
                  | d | _        || _        yt        t        | j                        }| j                  j                  ddd|f   | _        || _        y)zRemove columns, which are not to be displayed and adjust formatters.

        Attributes affected:
            - tr_frame
            - formatters
            - tr_col_num
        Nrh   rg   axis)r   r   rl   r2   ry   r   listtupler   rj   r   
tr_col_num)rb   col_numrE   rF   s       rc   r  z)DataFrameFormatter._truncate_horizontally  s     ##///&&!+a<==%%a'k2DMM&&q7()|4E"D%=q9DM $//D%=9#__Xg.#__gXY/# " 3.G MM..q(7({;DM!re   c                   | j                   J | j                   dz  }|dk\  r|t        | j                        }t        j                  t        j
                  |      t        j
                  ||z
  |      g      }| j                  j                  |   | _        || _
        yt        t        | j                        }| j                  j                  d|ddf   | _        || _
        y)zRemove rows, which are not to be displayed.

        Attributes affected:
            - tr_frame
            - tr_row_num
        Nrh   rg   )r   ri   r   nphstackarangerl   r   rj   rY   rm   )rb   rp   _len_slices       rc   r  z'DataFrameFormatter._truncate_vertically  s     ##///&&!+a<t}}%DYY		' 2BIIdWnd4STUF MM..v6DM " 3.G MM..xx{;DM!re   c                    g }t         j                        s j                  st         j                        D ]m  \  }} j	                  |      }t        | j                  t         j                  j                  |d             j                        }|j                  |       o |S t         j                        rt        t        t            j                         _        t         j                        t         j                         k7  r8t#        dt         j                          dt         j                         d       j                  D cg c]  }|g }}n j%                   j                        } j&                  r|D ]  }|j                  d        t         j                        D ]  \  }}||   }t)        t         j                  j                  |d            g fd|D         }	 j	                  |      }t        | j                  |	 j                        }t)        g  fd	|D        |	 }
 j                  j                  ||
 j                  
      }|j                  ||z           |S c c}w )Nr   )stringsrH   minimumr`   zWriting z cols but got z aliasesrr   c              3  T   K   | ]  }j                   j                  |       ! y wr   r`   ri   .0xrb   s     rc   	<genexpr>z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>  s     0RQa0R   %()r*  r`   c              3  T   K   | ]  }j                   j                  |       ! y wr   r,  r-  s     rc   r0  z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>  s     @DHHLLO@r1  r   )r   rS   	enumerater   
format_col_make_fixed_widthrH   rj   r   getr`   appendr   r  r   ri   r   r   _get_formatted_column_labelsr   max)rb   r   icr   labelstr_columnsr/  cheaderheader_colwidthmax_lens   `          rc   r   z-DataFrameFormatter._get_strcols_without_index  s,   #%DKK(!$--0 +1!__Q/
.& LL 2 21a 89	
 z*+ N$tCy$++6DK4;;3t||#44 s4<<01 2"4;;/0:  15<uE7<K<;;DMMJK""   dmm, 	1DAq!!nG!DNN&&q!,-0R'0RO +J*DLL/txxJ R@Z@R/RGhh&&wdll&KGNN7Z/0	1 - =s   
Jc           
     2   | j                   }| j                  |      }t        |j                  d d |f   j                  || j
                  | j                  | j                  j                  |j                  |         | j                  | j                        S )N)rW   rU   spacer   r   )r   _get_formatterr   rl   r~   rW   rU   r   r6  r   r   rT   )rb   r:  r   	formatters       rc   r4  zDataFrameFormatter.format_col  sz    ''*	JJq!t$$**;;..$$U]]1%56LL**
 	
re   c                    t        | j                  t        t        f      r+t	        |      rt        t        |      }| j                  |   S y t	        |      r|| j                  vr| j                  |   }| j                  j                  |d       S r   )	ry   r   r  r  r   r   rj   r   r6  )rb   r:  s     rc   rC  z!DataFrameFormatter._get_formatter  sn    dooe}5!}aLq))!}$,,!6LLO??&&q$//re   c           	     6   
 ddl m} |j                  }t        |t              r|j                  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 ||      }t        | D cg c]  }t        |       }}|S |j%                  d      } j                  j                  }t        t        |t        t        |                  
t'        |      D 	cg c]#  \  }	} j)                  |	      s

|   rd	|z   n|g% }}	}|S c c}w c c}}	w )
Nr   )sparsify_labelsF)r   r   c              3  4   K   | ]  }|j                     y wr   )is_floating)r.  levels     rc   r0  zBDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>  s     %TEe&7&7%Ts   c                <    |j                   vr|    rsd|z   S |S )N )r   )r/  yneed_leadsprestrict_formattingrb   s     rc   space_formatzEDataFrameFormatter._get_formatted_column_labels.<locals>.space_format  s'    T__,#A/7Nre   c              3  V   K   | ]  }|D cg c]  } ||       c}  y c c}w wr   r   )r.  r/  rM  rP  s      rc   r0  zBDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>   s&     K!15a|Aq)5K5s   	)$)r   rL  )pandas.core.indexes.multirG  r   ry   r-   r   r  r  r   dtypesr~   anylevelsr   mapr   r   ri   r   r3  rC  )rb   r   rG  r   fmt_columnsrS  str_columns_tupler/  r=  r:  rN  rO  rP  s   `         @@@rc   r8  z/DataFrameFormatter._get_formatted_column_labels  sx   =--gz*!//e/TKsK01KZZ&&..F #&%TW^^%T"Ts;4Df0MNOK !%K{KL! }}%6!7$34E$F!,/1B,CDq47DKD  "..E.BKZZ&&Fs;4Df0MNOK &k2Aq !% 3 3A 6;q>qqQK 
  E
s   4F#(Fc                ,   | j                   j                         D ci c]  \  }}|t        t        |       }}}|j                  }|j
                  }| j                  d      }t        |t              r)|j                  | j                  | j                  |      }n|j                  | j                  |      g}|D 	cg c]=  }	t        t        t        |	      d|j!                  dd      | j"                              ? }}	 | j"                  j$                  dg| j'                  d	      }
| j(                  r'| j+                         D 	cg c]  }	t-        |	       }}	ndg|j.                  z  }| j0                  r||
z   S |
S c c}}w c c}	w c c}	w )
N	__index__)r   r   rD  )r   rD  rE   rr   r   )rH   r*  r`   rg   rv   )r   itemsr   rj   rT   r   rC  ry   r-   r   r   r   r   r  r5  r  r6  r`   r   r   r   _get_column_name_listr   nlevelsrS   )rb   r   kvr   rT   r   fmtr   r/  adjoined
col_headers               rc   r   z'DataFrameFormatter._get_formatted_index1  s}    261E1E1GHAQS!_H	H--!!+.eZ(++"55 , I ""0G0GSV"WI 
  !GVY]]2q5Itxx
	 
 #488??11y177= ""*.*D*D*FGQ#a&GJG/J;;((OI I 
 Hs   F AFFc                    g }| j                   j                  }t        |t              r$|j	                  d |j
                  D               |S |j                  |j                  dn|j                         |S )Nc              3  (   K   | ]
  }|dn|  y w)Nrr   r   )r.  rV   s     rc   r0  z;DataFrameFormatter._get_column_name_list.<locals>.<genexpr>^  s     P$t|5Ps   rr   )r   r   ry   r-   extendnamesr7  rV   )rb   rf  r   s      rc   r\  z(DataFrameFormatter._get_column_name_listZ  s_     "**$$gz*LLP'--PP  LLw||3Fre   )NNTTrQ   NNNNTNNNF.FT)&r   rB   r   Axes | Noner   ColspaceArgType | NonerS   zbool | SequenceNotStr[str]rT   r   rU   r   r   FormattersType | NonerH   r   rW   FloatFormatType | Noner   bool | Noner   r   rY   r   rZ   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   list[list[str]]r   r   r   )r   rj   )r   rl  r   r   )r   rj  r   r=   )rH   r   r   r   )r   rh  r   r,   )r   ri  r   r9   )r   r   )rY   r   r   r   r   )r:  rj   r   r   )r:  	str | intr   Callable | None)r   rB   r   rm  )r   rB   r   r   )r   zlist[Hashable])(r   r   r   r   rD   rN   rd   r   propertyr   r   r   ro   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r
  r	  rx   r  r  r   r4  rC  r8  r   r\  r   re   rc   r   r     ss    !gbG"222G
  $,0-1,0"/3 $ ###&+'---- -- *	--
 +-- -- -- *-- -- --- -- -- -- -- --  $!--" #--$ %--& '--( 
)--^
 
 

 T T Y Y W W S S , , . . N N P P F F
/	&0	!/&>PI("4"$-^

0'R'Rre   r   c                      e Zd ZdZddZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	dZ	 	 	 d
	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)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.
    c                    || _         y r   )r`  )rb   r`  s     rc   rd   zDataFrameRenderer.__init__u  s	    re   Nc                    ddl m}m}	 |r|	n|}
 |
| j                  ||||      }|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)classesbordertable_idrender_linksr^   encoding)pandas.io.formats.htmlrv  rw  r`  r   save_to_buffer)rb   r^   r}  rx  notebookry  rz  r{  rv  rw  Klasshtml_formatterstrings                rc   to_htmlzDataFrameRenderer.to_htmlx  sP    D	

 &.!=HH%
  ))+f#AAre   c                r    ddl m}  || j                  |      }|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  )rb   r^   r}  r   r  string_formatterr  s          rc   r   zDataFrameRenderer.to_string  s5    ( 	=*488
K!++-f#AAre   c                D   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                  }|j	                          |r4t        |t              sJ |j                         }|j                          |S y)z;
        Render dataframe as comma-separated file.
        r   )CSVFormatterNTFpath_or_buflineterminatorsepr}  errorscompressionquotingr   index_labelr   	chunksize	quotechardate_formatdoublequote
escapecharstorage_optionsrD  r   )pandas.io.formats.csvsr  r   r`  savery   getvalueclose)rb   r  r}  r  r   r  r   r  r  r  r  r  r  r  r  r  r  r  created_buffercsv_formattercontents                        rc   to_csvzDataFrameRenderer.to_csv  s   , 	8!N"*K"N$ 
#
)
 
 	

 
 $
 
 
 $
 
  
  
 $
 $
 "
  ,!
" hh#
& 	k8444!**,GNre   )r`  r   r   r   )NNNFNNF)r^   "FilePath | WriteBuffer[str] | Noner}  r   rx  zstr | list | tuple | Noner  r   ry  zint | bool | Nonerz  r   r{  r   r   r   )NNN)r^   r  r}  r   r   r   r   r   )NN,NNwinferN"NNNTNstrictN)"r  z7FilePath | WriteBuffer[bytes] | WriteBuffer[str] | Noner}  r   r  r   r   zSequence[Hashable] | Noner  zIndexLabel | Noner   r   r  r:   r  r   r  r   r  r   r  r   r  r   r  r   r  r   r  r   r  zStorageOptions | Noner   r   )r   r   r   r   rd   r  r   r  r   re   rc   rs  rs  d  s    
 37#-1$(#"1B/1B 1B +	1B
 1B "1B 1B 1B 
1Bj 37#!%	B/B B 	B
 
B8 PT#-1)-*1"%) $"& !%15#9L9 9 	9
 +9 '9 9 (9 9 9 #9 9  9 9 9  !9" /#9$ 
%9re   rs  c                    t        ||      5 }|j                  |        ||j                         cddd       S 	 ddd       y# 1 sw Y   yxY w)zQ
    Perform serialization. Write to buf or return as string if buf is None.
    )r}  N)_get_bufferwriter  )r  r^   r}  fds       rc   r  r    sN     
S8	, 
;;;=	 
   s   #AAAc              #  L  K   | t        |       } n
t               } |d}nt        | t              st	        d      t        | d      r|  yt        | t              r1t        t        |              t        | d|d      5 }| ddd       yt        d      # 1 sw Y   yxY ww)	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  rr   )r}  newlinez1buf is not a file name and it has no write method)	r4   r   ry   r   r   hasattrr3   open	TypeError)r^   r}  fs      rc   r  r    s      S!jS!LMMsG 		C	s3x(#sXr: 	a
 G	 	 KLL	 	s   A=B$?BB$B!B$c                   t        j                  | j                  d      rt        }t	        t
        |       } nt        | j                  t              rt        }t	        t
        |       } nt        j                  | j                  d      rt        }t	        t        |       } nut        | j                  t              rt        }nTt        j                  | j                  d      rt        }n-t        j                  | j                  d      rt        }nt        }|d}|t!        d      }|t!        d      } || |||||||||	|
      }|j#                         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iu   r\   display.precision)
digitsrU   rW   rD  rB  rH   r   r   r  fallback_formatter)r   is_np_dtyperX   _Datetime64Formatterr   r'   ry   r"   _Datetime64TZFormatter_Timedelta64Formatterr)   r#   _ExtensionArrayFormatterFloatArrayFormatter_IntArrayFormatter_GenericArrayFormatterr   
get_result)valuesrD  rW   rU   r  rB  rH   r   r   r  r  	fmt_klassfmt_objs                rc   r   r   7  s   R v||S)(	mV,	FLL/	2*	mV,	s	+)	nf-	FLL.	1,		t	,'		t	,&	*	}!"89~/0!#-G re   c                  n    e Zd Z	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZy)r  Nc                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        y r   )r  r  rU   rB  rD  rW   rH   r   r  fixed_widthr   r  )rb   r  r  rD  rU   rB  rW   rH   r   r  r  r   r  s                rc   rd   z_GenericArrayFormatter.__init__  s\     
"(&*"4re   c                N    | j                         }t        || j                        S r   )_format_stringsr5  rH   )rb   r   s     rc   r  z!_GenericArrayFormatter.get_result  s!    ))+
 T\\::re   c                     j                   t        d      }|t        d      fd}n j                   } j                   j                  nX j                   j                  n? j                  d uxr  j                  t
        k7  }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.                  }||j1                         }g }t3        |      D ]  \  }	}
||	   r j                  |r|j5                  d
 ||
              4||	   r|j5                   ||
             Q|du rd}nd}|j5                  |j7                   ||
                    |S )Nr\   r  c                (    t        | ddd      S )Nz .dr  )_trim_zeros_single_float)r/  	precisions    rc   <lambda>z8_GenericArrayFormatter._format_strings.<locals>.<lambda>  s     )AIa=)** re   rs   )rw   quote_stringsc                   j                   t        |       rt        |       r| y| t        u rt	        t              S t        j                  |       r t        j                  |       rt	        |       S | t        u s*t        | t        j                  t        j                  f      ryj                   S t        | t              rt	        |       S t        | t              rt        |       S t	         |             S )Nr   r   )rU   r    r$   r   r   r   r   r#  isinfr   ry   
datetime64timedelta64r+   r*   repr)r/  rD  rb   s    rc   _formatz7_GenericArrayFormatter._format_strings.<locals>._format  s    {{&9Q<DG9!"Wr7N\\!_! q6M#XAr~~/N!O {{"A|,1vA{+Aw 9Q<((re   z=ExtensionArray formatting should use _ExtensionArrayFormatterrg   r  rL  Fz{v}z {v})r_  )rW   r   rD  r  r  r	   r   r5   r|   r  ry   r#  ndarrayr  r   	map_inferr   r   r%   r  rangeri   shaper   rT  r3  r7  format)rb   rW   r  r  valsinferredis_float_typer   r   r:  r_  tplrD  r  s   `           @@rc   r  z&_GenericArrayFormatter._format_strings  s   $%&<=L#&':;	   ,,L>>%I$$0//I LL4S9SM%%/+I	)* {{$

+O  ==x0ffU4[uU1c$**o-F'GHI 	
 ** )--/M
dO 	<DAq!!$(B!!Agaj\"23q!!!,q/2 E)  C C!!#**wqz*":;	< re   )   NrQ   r  NrF   rg  NTTN)r  r6   r  rj   rD  rp  rU   r   rB  ro  rW   rk  rH   r   r   r   r  r   r  r   r   rl  r  rp  r   r   r   )r   r   r   rd   r  r  r   re   rc   r  r    s     %)/3" %).255 5 #	5
 5 5 -5 5 5 5 5 #5 ,5 
58;Jre   r  c                  H     e Zd Zd fdZ	 	 d	 	 	 	 	 ddZddZd	dZ xZS )
r  c                    t        |   |i | | j                  C| j                  6d| _        t        | j                        r| j                  | _        d | _        y y y y NF)superrd   rW   rD  r  callable)rb   argskwargs	__class__s      rc   rd   zFloatArrayFormatter.__init__  se    $)&) (T^^-C$D))*!%!2!2$(! + .D(re   c                      j                   r fdn fd j                  dk7  r fdnS  fd}|S )z;Returns a function to be applied on each value to format itc                L    J t        |       r	 |       S j                  S )N)value)r%   rU   )r_  rW   rb   s    rc   base_formatterz<FloatArrayFormatter._value_formatter.<locals>.base_formatter  s5    #/// Qx !q) re   c                H    t        |       rt        |       S j                  S r   )r%   r   rU   )r_  rb   s    rc   r  z<FloatArrayFormatter._value_formatter.<locals>.base_formatter&  s    !&qs1v:t{{:re   rg  c                J     |       j                  dj                  d      S )Nrg  rg   )replacer   )r_  r  rb   s    rc   decimal_formatterz?FloatArrayFormatter._value_formatter.<locals>.decimal_formatter+  s!    %a(00dllAFFre   c                n    t        |       rt        |       kD  r |       S  d      S j                  S )Ng        )r%   absrU   )r  r  rb   	thresholds    rc   rD  z7FloatArrayFormatter._value_formatter.<locals>.formatter4  s6    U|u:	),U33,S11{{"re   )rW   r   )rb   rW   r  rD  r  r  s   ``` @@rc   _value_formatterz$FloatArrayFormatter._value_formatter  sZ     ,,L 	; <<3G !/$$	# re   c                `   
 dd	 	 	 	 	 	 dd
 j                   (  j                   j                    j                        S  j                  rt	        d      nd
 fd} j
                  N j                  r5 j                  du rd}nd}t        |j                   j                  	      }n j
                  }n fd
} ||      } j                  s|S t        |      dkD  r%t        d |D              }| j                  dz   kD  }nd}t        j                   j                        }|dkD  j                         }|d j                   z  k  |dkD  z  j                         }	|	s|r>|r< 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
        c           	     
   t        |       }t        j                  t        | j	                         |j	                               D cg c]  \  }}|s ||      n| c}}      j                  | j                        }|S c c}}w r   )r$   r#  arrayr  ravelreshaper  )r  rD  rU   maskvalr  	formatteds          rc   format_with_na_repzCFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_repE  ss    <D #&fllndjjl"CQ +,IcN7
 gfll#  s   A?
c                   t        j                  |       j                         }t        j                  |       j                         }t	        |      t	        |      }}g }t        | j                         ||||      D ]  \  }}	}
}}|s|s|j                   ||             %|s|j                   ||	       d| d       E|sV ||
      j                         }|j                  d      r|j                  | | d       |j                  | d| d       |j                  | d| d        t        j                  |      j                  | j                        S )N+j-)r#  realr  imagr$   r  r7  strip
startswithr  r  r  )r  rD  rU   real_valuesimag_values	real_mask	imag_maskformatted_lstr  real_valimag_valre_isnaim_isnaimag_formatteds                 rc   format_complex_with_na_repzKFloatArrayFormatter.get_result_as_array.<locals>.format_complex_with_na_repO  sP    ''&///1K''&///1K#'#4d;6GyIM=@> @9Xx' w!((38 !((Ih,?+@&)KL %.x%8%>%>%@N%005%,,x7Gq-IJ%,,xq8H-JK!((F81VHA)>?'@( 88M*226<<@@re   Nzdisplay.chop_thresholdc                   j                  | 	      }j                  dk(  rdj                  z   nj                  }j                  }t	        |      }|r |||      }n
 |||      }j
                  rF|rt        |j                        }nt        |j                        }t        j                  |d      S |S )NrE   rL  objectrX   )r  rH   rU   r  r   r  _trim_zeros_complexr   _trim_zeros_floatr#  asarray)
rW   rD  rU   r  
is_complexr   r  r  rb   r  s
         rc   format_values_withzCFloatArrayFormatter.get_result_as_array.<locals>.format_values_withu  s    --lIFI +/,,&*@S4;;&dkkF [[F)&1J 3FIvN+FIvF0FF.vt||DFzz&99Mre   Tz{value: .{digits:d}f}z{value:.{digits:d}f})r  c                "    j                   | z  S r   )rW   )r  rb   s    rc   r  z9FloatArrayFormatter.get_result_as_array.<locals>.<lambda>  s    ):):U)B re   r   c              3  2   K   | ]  }t        |        y wr   ri   r.  r/  s     rc   r0  z:FloatArrayFormatter.get_result_as_array.<locals>.<genexpr>  s     :AQ:      Fg    .A
   z{value: .{digits:d}e}z{value:.{digits:d}e})r  r6   rD  r   rU   r   )rD  r  rU   r  r   rW   r   r   r  r  ri   r9  r#  r  rT  )rb   r  fmt_strrW   formatted_valuesmaxlentoo_longabs_valshas_large_valueshas_small_valuesr  r  r  s   `         @@@rc   get_result_as_arrayz'FloatArrayFormatter.get_result_as_array?  s   		A	A*2	A<?	A: >>%%dkk4>>4;;OO"#;<II	< $%%-5G4G&w~~dkkJ#00BL-l;##  1$:)9::Fa/HH66$++& %sN//1%|(<<ANSSU-=!!T)10"7>>$++FL1,?re   c                4    t        | j                               S r   )r  r'  r   s    rc   r  z#FloatArrayFormatter._format_strings  s    D,,.//re   r   NN)rW   rk  r  zfloat | Noner   r   )r   z
np.ndarrayr   )r   r   r   rd   r  r'  r  __classcell__r  s   @rc   r  r    s>    
) 04"&6,6  6 
	6p~ @0re   r  c                      e Zd ZddZy)r  c                    | j                   du rd }nd }| j                  xs |}| j                  D cg c]
  } ||       }}|S c c}w )NFc                *    | dj                  |       S )Nr  r/  r  r/  s    rc   r  z4_IntArrayFormatter._format_strings.<locals>.<lambda>  s    1ooo&: re   c                *    | dj                  |       S )Nz dr/  r0  r/  s    rc   r  z4_IntArrayFormatter._format_strings.<locals>.<lambda>  s    2&6&6&6&; re   )r   rD  r  )rb   formatter_strrD  r/  r   s        rc   r  z"_IntArrayFormatter._format_strings  sN    &:M;MNN3m	,0KK8qil8
8 9s   ANr   )r   r   r   r  r   re   rc   r  r    s    re   r  c                  H     e Zd ZU ded<   	 	 d	 	 	 	 	 	 	 d fdZddZ xZS )r  r'   r  c                B    t        |   |fi | || _        || _        y r   )r  rd   nat_repr  )rb   r  r5  r  r  r  s        rc   rd   z_Datetime64Formatter.__init__  s&     	*6*&re   c                    | j                   }| j                  |D cg c]  }| j                  |       c}S |j                  | j                  | j                        }|j                         S c c}w )z&we by definition have DO NOT have a TZ)rU   r  )r  rD  _format_native_typesr5  r  tolist)rb   r  r/  r   s       rc   r  z$_Datetime64Formatter._format_strings  si    >>%/56!DNN1%6600<<T-=-= 1 

   "" 7s   A/r   N)r  r'   r5  r   r  r   r   r   r   r   r   r   __annotations__rd   r  r*  r+  s   @rc   r  r    sA    
  		'	' 	' 		' 
	'
#re   r  c                       e Zd ZU ded<   ddZy)r  r(   r  c                   | j                   }| j                  }d }||j                  d      }t        |t              r|j                         }nt        j                  |t              }t        ||| j                  | j                  | j                  | j                  | j                  | j                  | j                   | j"                  |      }|S )NT)boxedr  )	rW   rU   r  rB  rH   r   r   r  r  )r  rD  
_formatterry   r&   _internal_get_valuesr#  r  r  r   rW   rU   r  rB  rH   r   r   r  )rb   r  rD  r  r  r   s         rc   r  z(_ExtensionArrayFormatter._format_strings  s    NN	!!'!2!2!2!>fk*//1EJJvV4E!**;;;;**LLLL,,LL1

 re   Nr   r   r   r   r;  r  r   re   rc   r  r    s    re   r  c                F   t        j                  |       } t        |       r0t        j                  | dk\        rt        j                  | dk        st	        d      d| z  } t        |       }| j                  |      j                  t              }t        j                  ||       }t        j                  |      r(|j                  t              }|D cg c]  }|dz   	 c}S t        j                  |       }t        |      }t        j                  | t              }| |   j                         j                  t              j                  t              ||<   | |    j                  |      j                  t              || <   |D cg c]  }|dz   	 c}S c c}w c c}w )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   rg   z/percentiles should all be in the interval [0,1]d   %r  )r#  r  r   r   r   get_precisionroundastyperj   iscloser   unique
empty_liker  )percentilesprecpercentiles_round_typeint_idxoutr:  unique_pctss          rc   format_percentilesrQ  
  sX   D **[)K [)vvkQ&'vvkQ&'JKK#K%D(..t4;;C@jj/=G	vvg$++C0!$%AC%%))K(K%D
--6
2Cw'--/66s;BB3GCL)//5<<SACM !AG!! & "s   F
Fc                D   | d   dkD  r| d   nd }| d   dk  rd| d   z
  nd }t        j                  | ||      }t        |      }t        j                  t        j                  t        j
                  |                  j                  t               }t        d|      }|S )Nr   rC  )to_beginto_endrg   )	r#  ediff1dr  floorlog10rk   rG  rj   r9  )r  rT  rU  diffrL  s        rc   rE  rE  I  s     8a<uQxTH %b	CS59_TF::ehv>Dt9DHHRXXbffTl+,33C88Dq$<DKre   c                ,    | t         u r|S t        |       S r   )r   r   r/  r5  s     rc   _format_datetime64r\  S  s    Cx q6Mre   c                d    t        | t              r|S |r| j                  |      S | j                  S r   )ry   r   strftime
_date_repr)r/  r5  r  s      rc   _format_datetime64_dateonlyr`  \  s1    
 !Wzz+&& ||re   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)r5  r  )r`  )r/  r  r5  s    rc   r  z'get_format_datetime64.<locals>.<lambda>r  s    4wK
 re   c                    t        |       S )N)r5  )r\  r[  s    rc   r  z'get_format_datetime64.<locals>.<lambda>v  s    +Aw? re   r   )is_dates_onlyr5  r  s    ``rc   get_format_datetime64re  k  s     
 	
 @?re   c                       e Zd ZU ded<   ddZy)r  r'   r  c                    | j                   j                  }| j                   j                  t              }| j                  xs t        || j                        }|D cg c]
  } ||       }}|S c c}w )zwe by definition have a TZ)r  )r  _is_dates_onlyrG  r  rD  re  r  )rb   idor  rD  r/  r   s         rc   r  z&_Datetime64TZFormatter._format_strings|  sj    kk((##F+NN 
&;T--'
	 -33qil3
3 4s   A2Nr   rA  r   re   rc   r  r  y  s    	re   r  c                  B     e Zd ZU ded<   	 d	 	 	 	 	 d fdZddZ xZS )r  r)   r  c                4    t        |   |fi | || _        y r   )r  rd   r5  )rb   r  r5  r  r  s       rc   rd   z_Timedelta64Formatter.__init__  s     	*6*re   c                    | j                   xs" t        | j                  | j                  d      }| j                  D cg c]
  } ||       c}S c c}w )NF)r5  box)rD  get_format_timedelta64r  r5  )rb   rD  r/  s      rc   r  z%_Timedelta64Formatter._format_strings  sE    NN 
&<KK5'
	 '+kk2	!222s   Ar   )r  r)   r5  r   r   r   r   r:  r+  s   @rc   r  r    s4    
  
 
3re   r  c                @    | 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        |       } | j	                        }rd| d}|S )Nr0  ')r    r$   ry   r   
_repr_base)r/  r   rm  r  r5  s     rc   r?  z*get_format_timedelta64.<locals>._formatter  sS    91$q'N!Y'!A V,]Fre   )rh  )r  r5  rm  	even_daysr?  r  s    ``  @rc   rn  rn    s*     %%I re   c                @  	 t        |       dk(  s|dk(  r| S |t        j                         n|t        fd| D              	|t        |	      	t	        d      	kD  r	d	fd}| D cg c]
  } ||       } }j                  | 	|      }|S c c}w )Nr   r   c              3  @   K   | ]  }j                  |        y wr   r  )r.  r/  
adjustments     rc   r0  z$_make_fixed_width.<locals>.<genexpr>  s     5*..#5s   r   c                V    %dkD  j                  |       kD  z  r| d dz
   dz   } | S )Nr   r   r  )r/  rx  conf_maxr@  s    rc   justz_make_fixed_width.<locals>.just  s=    1!2W!<=m!$u,re   r   )r/  r   r   r   )ri   r5   r_   r9  r   rH   )
r)  rH   r*  r`   r{  r/  r   rx  rz  r@  s
          @@@rc   r5  r5    s     7|qGu,
{,,.

5W55Ggw'01H( 2 !((1tAw(G(w?FM )s   4Bc           	        g g }}| D ]^  }t        j                  d|      }|j                  dj                  |dd              |j                  dj                  |dd              ` t	        |       }t        ||z   |      }t	        |      dk(  rg S t        d |D              dz
  }t        |d| ||d       D 	
cg c]  \  }	}
|	|
d   z   |
dd d	| dz   d
z    }}	}
|S c c}
}	w )z
    Separates the real and imaginary parts from the complex number, and
    executes the _trim_zeros_float method on each of those.
    z([j+-])rr   Nr   c              3  2   K   | ]  }t        |        y wr   r  )r.  parts     rc   r0  z&_trim_zeros_complex.<locals>.<genexpr>  s     ;dD	;r  rg   >r   )rer   r7  r   ri   r  r9  r  )str_complexesr   	real_part	imag_partr/  trimmednpadded_partspadded_lengthreal_ptimag_ptpaddeds               rc   r  r    s$   
 ryI 2
 ((:q)"./B012 	MA$Y%:GDL
<A	;l;;a?M !$L!$4l126F G
 GW	 	
!*	QR[=/)*	, 	F  Ms   <!C"c                T    | j                  d      } | j                  d      r| dz  } | S )zX
    Trims trailing zeros after a decimal point,
    leaving just one if necessary.
    0rg  )rstripendswith)	str_floats    rc   r  r    s2    
   %I#S	re   c                    | }t        j                  d| d      dfdd	fd} ||      r%|D cg c]  } |      r|dd n| }} ||      r%|D cg c]"  } |      r|j                  |      r|dz   n|$ }}|S c c}w c c}w )
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]*$c                4    t        j                  |       d uS r   )r  match)r/  number_regexs    rc   is_number_with_decimalz1_trim_zeros_float.<locals>.is_number_with_decimal  s    xxa(44re   c                    | D cg c]  } |      s| }}t        |      dkD  xr t        d |D              S c c}w )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.
        r   c              3  >   K   | ]  }|j                  d         yw)r  N)r  r  s     rc   r0  z9_trim_zeros_float.<locals>.should_trim.<locals>.<genexpr>$  s     'IA

3'Is   )ri   r   )r  r/  numbersr  s      rc   should_trimz&_trim_zeros_float.<locals>.should_trim  sE     %B(>q(A1BB7|aIC'I'I$II Cs   <<NrS  r  rn  )r  ArrayLike | list[str]r   r   )r  compiler  )
str_floatsr   r  r  r/  r   r  r  s         @@rc   r  r    s     G::!27)7CDL5	J g
GNO!3A61Sb6A=OO g
  *!,G1DC!KF  M Ps   B'Bc                v    t        | t              rt        j                  | j                   S | j
                  d uS r   )ry   r-   comany_not_nonerf  rV   )rT   s    rc   r   r   1  s0    %$--zz%%re   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	 d'	 	 	 	 	 d(d%Zd)d&Zy$)*EngFormatterzl
    Formats float values according to engineering format.

    Based on matplotlib.ticker.EngFormatter
    irM  iziair  ipir  iur  r   rr   r   r^  r  r  	   Gr  T   P   E   Z   YNc                     || _         || _        y r   accuracyuse_eng_prefix)rb   r  r  s      rc   rd   zEngFormatter.__init__T  s     !,re   c                   t        t        |            }t        j                  |      ryt        j                  |      ryd}|dk  rd}| }|dk7  r<t        t	        t        j                  |j                         dz        dz              }nt        d      }|j                  t        | j                  j                                     }|j                  t        | j                  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}|j                  ||      }	|	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   infrg   r   rS  r   zE-02dzE+r  z{mant: g}{prefix}z{mant: .r  z
f}{prefix})mantprefix)r
   r   is_nanis_infiniterj   mathrW  rX  rk   r9  ENG_PREFIXESr  r  r  r  )
rb   numdnumsignpow10	int_pow10r  r  
format_strr  s
             rc   __call__zEngFormatter.__call__Z  s_   ( s3x >>$t$!8D5D19C

4::<!+; <q @ABEAJE		#d//44678		#d//44678J	&&y1F]9*S)*F)C)Fd{b%i(== ,J$T]]1$5]CJ%%4%?	re   r  )r  r   r  r   r   r   )r  floatr   r   )r   r   r   r   r  rd   r  r   re   rc   r  r  8  s    SS 	S 	S	
 	S 	C 	C 	C 	
2 	
3 	
3 	
3 	C 	C 	C  	C!" 	C#L* CH-"-;?-	-;re   r  c                0    t        dt        | |             y)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     rc   set_eng_float_formatr    s    n %|Hn'MNre   c                   t        |       dk(  rg S dgt        | d         z  }g }| D ]U  }d}i }t        |      D ]  \  }}||   r||k(  rd||<   ||z
  ||<   |}! t        |      |z
  ||<   |j                  |       W |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)ri   r3  r7  )	rU  sentinelcontrolr   rJ  
last_indexlengthsr:  keys	            rc   get_level_lengthsr    s    $ 6{a	fs6!9~%GF 
& 	FAsqzcXo"
&'*n
#
	 "%j:5
g  Mre   c                    t        d |D              r|D cg c]  }t        |       }}| j                  dj                  |             yc c}w )z
    Appends lines to a buffer.

    Parameters
    ----------
    buf
        The buffer to write to
    lines
        The lines to append.
    c              3  <   K   | ]  }t        |t                y wr   )ry   r   r  s     rc   r0  z#buffer_put_lines.<locals>.<genexpr>  s     
-!:a
-s   rv   N)rT  r   r  r   )r^   linesr/  s      rc   buffer_put_linesr    sC     
-u
--!&'AQ''IIdii (s   A)r   zdict[str, Any]r)  )r  r   r^   r  r}  r   r   r   r   )r^   r  r}  r   r   zIGenerator[WriteBuffer[str], None, None] | Generator[StringIO, None, None])	NrQ   NNrF   rg  TNN)r  r6   rD  rp  rW   rk  rU   r   r  r   rB  zstr | int | NonerH   r   r   r   r   rl  r  r   r  rp  r   r   )rK  np.ndarray | Sequence[float]r   r   )r  r  r   rj   ro  )r/  NaTType | Timestampr5  r   r   r   r9  )r/  r  r5  r   r  r   r   r   )rd  r   r5  r   r  r   r   r   )r   F)r  r)   r5  zstr | floatrm  r   r   r   )rF   NN)
r)  r   rH   r   r*  r   r`   zprinting._TextAdjustment | Noner   r   )rg  )r  r6   r   r   r   r   )r  r   r   r   )r  r  r   r   r   r   )rT   r,   r   r   )r   F)r  rj   r  r   r   r   )rr   )rU  r   r  zbool | object | strr   zlist[dict[int, int]])r^   zWriteBuffer[str]r  r   r   r   )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   r;  VALID_JUSTIFY_PARAMETERSrN   rP   r   r   r   rs  r  r  r   r  r  r  r  r  rQ  rE  r\  r`  re  r  r  rn  r5  r  r  r  r   r  r  r  r  r   re   rc   <module>r     s   #  &      	 $  
  # 
 0  

  3 )      8 9 - '   6 % 6p  % _$ _$DB>B BJZ Z~ /3	+  	  DHM	+M7AMNM MP ,0"!%*.R R R  )R  	R 
 R  R  R  R  R  R  (R  R jk k\F00 F0R/ #1 #65 B<".<"<"~ "  		  JN@@"%@<F@@1 32 3, ! 
 	H +/	  
)	
 DB	 7:!%!03!!H&] ]@7Ov 24((.((V re   