
    .iF                      U d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
 ddlmZ 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 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, ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z: ddl;m<Z<m=Z=m>Z>m?Z? ddl@mAZA dd	lBmCc mDZE ddlFmGZGmHZHmIZImJZJ ddlKmLZL ddlMmNZN ddlOmPZPmQZQ ddlRmSZS er$ddlTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z` ddlambZbmcZc dZddeed <   d!Zfd"Zgdeed#<    G d$ d%      ZhdNd&ZidNd'Zj G d( d)      Zk G d* d+      Zl	 	 dO	 	 	 	 	 	 	 dPd,Zme
	 dQ	 	 	 	 	 dRd-       Zn	 	 	 	 	 	 	 	 	 dS	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dTd.Zo G d/ d0      Zp G d1 d2ep      Zq G d3 d4ep      Zr G d5 d6ep      Zs G d7 d8ep      Zt	 	 	 	 dUd9ZudVd:ZvdWdXd;Zw	 	 dY	 	 	 	 	 	 	 dZd<Zx	 dY	 	 	 	 	 	 	 d[d=Zy G d> d?es      Zz G d@ dAep      Z{	 	 d\	 	 	 	 	 	 	 d]dBZ|	 	 	 d^	 	 	 	 	 	 	 	 	 d_dCZ}d`dadDZ~dbdEZ	 d`	 	 	 	 	 dcdFZdddGZ G dH dI      Z e,dJ      dedfdK       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)Callable	GeneratorHashableMappingSequence)contextmanager)
QUOTE_NONE)Decimal)partial)StringION)get_terminal_size)TYPE_CHECKINGAnyFinalcast)
get_option
set_option)lib)NA)NaT	Timedelta	Timestamp)NaTType)
set_module)is_complex_dtypeis_float
is_integeris_list_likeis_numeric_dtype	is_scalar)CategoricalDtypeDatetimeTZDtypeExtensionDtype)isnanotna)CategoricalDatetimeArrayExtensionArrayTimedeltaArray)PandasObject)Index
MultiIndexPeriodIndexensure_index)DatetimeIndex)TimedeltaIndex)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   bufrU   rT   rR   rQ   rS   rX   rY   r   rV   rW   r4   get_adjustmentadj_chk_truncate)selfr\   rQ   rR   rS   rT   rU   rV   rW   rX   rY   s              V/var/www/app/trading-bot/venv/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                  }|rt	        t
        |      }|rt        ||      }|dk(  r|}|j                  d | }n`|dz  }t        |      }t        j                  t        j                  |      t        j                  ||z
  |      g      }|j                  |   }|| _        nd | _        || _        || _        y )N      )rY   rX   lenr\   r   intminilocnphstackarange
tr_row_num	tr_seriesis_truncated_vertically)ra   rY   rX   rq   r\   row_num_len_slices           rb   r`   zSeriesFormatter._chk_truncate   s    ==== #+"LDKK0@80K"C*H x21}"Yh/"a-6{YYw'4'>4)HI  V,%DO"DO'>$rd   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: rU   zdtype: rz   )r\   rU   rS   
isinstancer0   r.   r1   freqfreqstrr4   pprint_thingrQ   rq   rh   rW   getattrrp   r"   _values_get_repr_footerstr)ra   rU   footerrS   series_name
dtype_name
level_infos          rb   _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{rd   c                    t        | j                  j                  d | j                  | j                  | j
                        S )N)rV   rT   leading_space)format_arrayrp   r   rV   rT   rS   ra   s    rb   _get_formatted_valuesz%SeriesFormatter._get_formatted_values,  s6    NN""**;;**
 	
rd   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sparsifyrg   rz   include_namerf      ...z..rF   moderv   )rp   r   rh   typer\   __name__rS   
_has_namesr}   r-   _format_multir4   r^   adjoinsplit_format_flatr   rq   ro   r   ri   r_   rG   insertrR   r   join)ra   r\   r   rS   have_header	fmt_indexr_   
fmt_valuesn_header_rowsrr   widthdot_strresults                rb   	to_stringzSeriesFormatter.to_string5  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?##rd   )r\   rB   rQ   
bool | strrR   boolrS   r   rT   r   rU   r   rV   
str | NonerW   r   rX   
int | NonerY   r   returnNoner   r   r   r   r   	list[str])	r   
__module____qualname____doc__rc   r`   r   r   r    rd   rb   rO   rO      s     "#'## 	
     !    
@?>(T
+$rd   rO   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.

    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)rX   rY   max_colsmax_colwidthshow_dimensions
line_width)pandas.io.formatsr   r   get_console_size)r   r   _s      rb   get_dataframe_repr_paramsr   c  sa     *-.002
A
121245"#9:%&?@  rd   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.

    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   )rU   rW   rY   rX   rQ   )r   r   )r   heightmax_rows_optrX   rY   s        rb   get_series_repr_paramsr     s^     &'ME601L%*vH%*v
;M0NH 67 rd   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d0dZd1dZd1dZd2dZd)dZd)dZd)dZd+dZd3dZd3dZ d3dZ!d(dZ"d4d Z#d5d!Z$d6d"Z%d7d#Z&d8d$Z'	 	 	 	 d9d%Z(y):DataFrameFormatterz
    Class for processing dataframe formatting options and data.

    Used by DataFrame.to_string, which backs DataFrame.__repr__.
    rv   Nc                |   || _         | j                  |      | _        | j                  |      | _        || _        || _        || _        | j                  |      | _	        | j                  |      | _        | j                  |	      | _        | j                  |
      | _        || _        || _        || _        || _        || _        || _        || _        || _        | j1                         | _        | j5                         | _        | j                   | _        | j;                          t=        j>                         | _         y N)!frame_initialize_columnscolumns_initialize_colspace	col_spacerR   rS   rT   _initialize_formatters
formatters_initialize_justifyrG   _validate_float_formatrV   _initialize_sparsifyr   show_index_namesdecimal	bold_rowsescaperX   rY   r   r   _calc_max_cols_fittedmax_cols_fitted_calc_max_rows_fittedmax_rows_fittedtr_framer|   r4   r^   r_   )ra   r   r   r   rR   rS   rT   r   rG   rV   r   index_namesrX   rY   r   r   r   r   r   s                      rb   rc   zDataFrameFormatter.__init__  s   * 
//8229=
55jA//8 77E11(; +"   .#99;#99;

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

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

OS_EErd   c                     |t        d      S |S )Nzdisplay.multi_sparser   )ra   r   s     rb   r   z'DataFrameFormatter._initialize_sparsify  s    455rd   c                    |i S t        | j                  j                        t        |      k(  st        |t              r|S t        dt        |       dt        | j                  j                         d      )NzFormatters length(+) should match DataFrame number of columns(r   )rh   r   r   r}   dict
ValueError)ra   r   s     rb   r   z)DataFrameFormatter._initialize_formatters  su     I##$J7:jRV;W$S_$5 6//24::3E3E/F.GqJ rd   c                     |t        d      S |S )Nzdisplay.colheader_justifyr   )ra   rG   s     rb   r   z&DataFrameFormatter._initialize_justify   s    ?9::Nrd   c                t    |!t        |      }| j                  |   | _        |S | j                  j                  S r   )r/   r   r   )ra   r   colss      rb   r   z&DataFrameFormatter._initialize_columns&  s7    (DD)DJK::%%%rd   c                   |i }|S t        |t        t        f      r?d|i}|j                  t        j                  | j                  j                  |             |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                  |d            }|S )Nrv   z,Col_space is defined for an unknown column: zCol_space length(r   r   Tstrict)r}   ri   r   updater   fromkeysr   r   r   keysr  rh   zip)ra   r   r   columns       rb   r   z'DataFrameFormatter._initialize_colspace.  s2    F$ # 	C:.)_FMM$--

(:(:IFG  	7+#..* !3!33"$FvhO 
 F  4::%%&#i.8 'I'7 8336tzz7I7I3J2K1N  #djj00)DIJFrd   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)ra   r   r   s      rb   r   z(DataFrameFormatter._calc_max_cols_fittedF  sA    ##%== $&q!!%(L== rd   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   rX   _get_number_of_auxiliary_rows_is_screen_short_adjust_max_rows)ra   r   r   rX   s       rb   r   z(DataFrameFormatter._calc_max_rows_fittedQ  sr     !)+IAv}}! B B DDD$$V,!==}}H$$X..rd   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
        )rh   r   rY   rj   )ra   rX   s     rb   r  z#DataFrameFormatter._adjust_max_rowsd  s2     DJJ(*t}}h7rd   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   rX   r   s    rb   r  z"DataFrameFormatter._is_in_terminalr  s$    DMMQ&<$--1*<==rd   c                z    t        | j                  dk(  xr" t        | j                  j                        |kD        S Nr   )r   r   rh   r   r   )ra   	max_widths     rb   r  z$DataFrameFormatter._is_screen_narrowv  s/    DMMQ&N3tzz/A/A+BY+NOOrd   c                f    t        | j                  dk(  xr t        | j                        |kD        S r  )r   rX   rh   r   )ra   
max_heights     rb   r  z#DataFrameFormatter._is_screen_shorty  s(    DMMQ&G3tzz?Z+GHHrd   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.rf   )r   rh   r   
splitlinesrR   )ra   dot_row
prompt_rownum_rowss       rb   r  z0DataFrameFormatter._get_number_of_auxiliary_rows|  sR    
Z'D00;;=>>H;;MHrd   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_horizontallyrq   _truncate_verticallyr   s    rb   r|   zDataFrameFormatter.truncate  s3     ))'')''%%' (rd   c                r   | j                   J | j                   dz  }|dk\  rt        | j                  j                        }t	        j
                  t	        j                  |      t	        j                  ||z
  |      g      }| j                  j                  dd|f   | _        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
        Nrg   rf   )r   rh   r   r   rl   rm   rn   rk   r}   r   listtupler   ri   r   
tr_col_num)ra   col_numrs   rt   s       rb   r!  z)DataFrameFormatter._truncate_horizontally  s    ##///&&!+a<t}},,-DYY		' 2BIIdWnd4STUF MM..q&y9DM $//D%=9#__Xg.#__gXY/#  ' 3.G MM..q(7({;DM&rd   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
        Nrg   rf   )r   rh   r   rl   rm   rn   rk   r   ri   rX   ro   )ra   rr   rs   rt   s       rb   r"  z'DataFrameFormatter._truncate_vertically  s     ##///&&!+a<t}}%DYY		' 2BIIdWnd4STUF MM..v6DM " 3.G MM..xx{;DM!rd   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   )stringsrG   minimumr_   zWriting z cols but got z aliasesrv   c              3  T   K   | ]  }j                   j                  |       ! y wr   r_   rh   .0xra   s     rb   	<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     rb   r1  z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>  s     @DHHLLO@r2  r   )r   rR   	enumerater   
format_col_make_fixed_widthrG   ri   r   getr_   appendr   r$  r   rh   r   r  _get_formatted_column_labelsr   max)ra   r   icr   labelstr_columnsr0  cheaderheader_colwidthmax_lens   `          rb   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)rV   rT   spacer   r   )r   _get_formatterr   rk   r   rV   rT   r   r7  r   r   rS   )ra   r;  r   	formatters       rb   r5  zDataFrameFormatter.format_col  sz    ''*	JJq!t$$**;;..$$U]]1%56LL**
 	
rd   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   )	r}   r   r$  r%  r   r   ri   r   r7  )ra   r;  s     rb   rD  z!DataFrameFormatter._get_formatter  sn    dooe}5!}aLq))!}$,,!6LLO??&&q$//rd   c                   ddl m} |j                  }t        |t              rU|j                  dd      }| j                  rt        |      r ||      }t        |ddiD cg c]  }t        |       }}|S |j                  d      }t        t        || j                  j                  d            D cg c],  \  }\  }}| j                  |      st        |      rd	|z   n|g. }}}}|S c c}w c c}}}w )
Nr   )sparsify_labelsF)r   r   r  Tr   r   )pandas.core.indexes.multirH  r   r}   r-   r   r   rh   r  r$  r   r4  r   dtypesrD  r    )	ra   r   rH  r   fmt_columnsr0  r>  r;  rW   s	            rb   r9  z/DataFrameFormatter._get_formatted_column_labels  s   =--gz*!//e/TK}}[!1-k:,/,JT,JKq47KKK  "..E.BK &/TZZ%6%6uE&	 	 "Az5  ..q16Fu6M !G	K 	  L	s   "C091C5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   rE  )r   rE  rD   rv   r   )rG   r+  r_   rf   rz   )r   itemsr   ri   rS   r   rD  r}   r-   r   r   r   r   r%  r6  r$  r7  r_   r   r   r   _get_column_name_listr   nlevelsrR   )ra   r   kvr   rS   r   fmtr   r0  adjoined
col_headers               rb   r   z'DataFrameFormatter._get_formatted_index!  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)Nrv   r   )r/  rU   s     rb   r1  z;DataFrameFormatter._get_column_name_list.<locals>.<genexpr>N  s     P$t|5Ps   rv   )r   r   r}   r-   extendnamesr8  rU   )ra   rZ  r   s      rb   rP  z(DataFrameFormatter._get_column_name_listJ  s_     "**$$gz*LLP'--PP  LLw||3Frd   c                    |t        |      r|S t        |t              r$d|v r|S 	 |j                  d      }|j                  S t	        d      # t        t
        t        f$ r}t	        d|      |d}~ww xY w)z|
        Validates and processes the float_format argument.
        Converts new-style format strings to callables.
        N%g      ?z Invalid new-style format string z)float_format must be a string or callable)callabler}   r   formatr  KeyError
IndexError)ra   rT  r   es       rb   r   z)DataFrameFormatter._validate_float_formatS  s     ;(3-Jc3cz
X

3A::% DEE #Hj9 X$'Gw%OPVWWXs   A A7#A22A7)NNTTrP   NNNNTNNNF.FT)&r   rA   r   Axes | Noner   ColspaceArgType | NonerR   zbool | SequenceNotStr[str]rS   r   rT   r   r   FormattersType | NonerG   r   rV   FloatFormatType | Noner   bool | Noner   r   rX   r   rY   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   list[list[str]]r   r   r   )r   ri   )r   rg  r   r   )r   re  r   r<   )rG   r   r   r   )r   rc  r   r,   )r   rd  r   r8   )r   r   )rX   r   r   r   r   )r;  ri   r   r   )r;  	str | intr   Callable | None)r   rA   r   rh  )r   rA   r   r   )r   zlist[Hashable])rT  rf  r   rf  ))r   r   r   r   rC   rM   rc   r   propertyr   r   r   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r|   r!  r"  r   r5  rD  r9  r   rP  r   r   rd   rb   r   r     s    !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2'RF)F	Frd   r   c                      e Zd ZdZddZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	dZ	 	 	 d
	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)DataFrameRenderera?  Class for creating dataframe output in multiple formats.

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

    Called in pandas.DataFrame:
        - to_html
        - to_string

    Parameters
    ----------
    fmt : DataFrameFormatter
        Formatter with the formatting options.
    c                    || _         y r   )rT  )ra   rT  s     rb   rc   zDataFrameRenderer.__init__|  s	    rd   Nc                    ddl m}m}	 |r|	n|}
 |
| j                  ||||      }|j	                         }t        |||      S )uC  
        Render a DataFrame to an 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 or bool
            When an integer value is provided, it sets the border attribute in
            the opening tag, specifying the thickness of the border.
            If ``False`` or ``0`` is passed, the border attribute will not
            be present in the ``<table>`` tag.
            The default value for this parameter is governed by
            ``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.htmlrq  rr  rT  r   save_to_buffer)ra   r]   rx  rs  notebookrt  ru  rv  rq  rr  Klasshtml_formatterstrings                rb   to_htmlzDataFrameRenderer.to_html  sP    L	

 &.!=HH%
  ))+f#AArd   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   rw  )pandas.io.formats.stringr  rT  r   rz  )ra   r]   rx  r   r  string_formatterr~  s          rb   r   zDataFrameRenderer.to_string  s5    ( 	=*488
K!++-f#AArd   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seprx  errorscompressionquotingr  index_labelr   	chunksize	quotechardate_formatdoublequote
escapecharstorage_optionsrE  r   )pandas.io.formats.csvsr  r   rT  saver}   getvalueclose)ra   r  rx  r  r   r  r   r  r  r  r  r  r  r  r  r  r  r  created_buffercsv_formattercontents                        rb   to_csvzDataFrameRenderer.to_csv  s   , 	8!N"*K"N$ 
#
)
 
 	

 
 $
 
 
 $
 
  
  
 $
 $
 "
  ,!
" hh#
& 	k8444!**,GNrd   )rT  r   r   r   )NNNFNNF)r]   "FilePath | WriteBuffer[str] | Nonerx  r   rs  zstr | list | tuple | Noner{  r   rt  zint | bool | Noneru  r   rv  r   r   r   )NNN)r]   r  rx  r   r   r   r   r   )NN,NNwinferN"NNNTNr  N)"r  z7FilePath | WriteBuffer[bytes] | WriteBuffer[str] | Nonerx  r   r  r   r   zSequence[Hashable] | Noner  zIndexLabel | Noner   r   r  r9   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   rc   r  r   r  r   rd   rb   rn  rn  k  s    
 37#-1$(#"5B/5B 5B +	5B
 5B "5B 5B 5B 
5Br 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rd   rn  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.
    )rx  N)_get_bufferwriter  )r~  r]   rx  fds       rb   rz  rz    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  rv   )rx  newlinez1buf is not a file name and it has no write method)	r3   r   r}   r   r  hasattrr2   open	TypeError)r]   rx  fs      rb   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)
digitsrT   rV   rE  rC  rG   r   r   r  fallback_formatter)r   is_np_dtyperW   _Datetime64Formatterr   r(   r}   r#   _Datetime64TZFormatter_Timedelta64Formatterr*   r$   _ExtensionArrayFormatterFloatArrayFormatter_IntArrayFormatter_GenericArrayFormatterr   
get_result)valuesrE  rV   rT   r  rC  rG   r   r   r  r  	fmt_klassfmt_objs                rb   r   r   B  s   R v||S)(	mV,	FLL/	2*	mV,	s	+)	nf-	FLL.	1,		t	,'		t	,&	*	}!"89~/0!#-G rd   c                  n    e Zd Z	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZy)r  Nc                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        y r   )r  r  rT   rC  rE  rV   rG   r   r  fixed_widthr   r  )ra   r  r  rE  rT   rC  rV   rG   r   r  r  r   r  s                rb   rc   z_GenericArrayFormatter.__init__  s\     
"(&*"4rd   c                N    | j                         }t        || j                        S r   )_format_stringsr6  rG   )ra   r   s     rb   r  z!_GenericArrayFormatter.get_result  s!    ))+
 T\\::rd   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)r0  	precisions    rb   <lambda>z8_GenericArrayFormatter._format_strings.<locals>.<lambda>  s     )AIa=)** rd   rw   )r{   quote_stringsc                R   j                   ot        |       rdt        |       rY| y| t        u rt	        t              S | t
        u s*t        | t        j                  t        j                  f      ryj                   S t        | t              rt	        |       S t	         |             S )Nr   r   )rT   r!   r%   r   r   r   r}   rl   
datetime64timedelta64r+   )r0  rE  ra   s    rb   _formatz7_GenericArrayFormatter._format_strings.<locals>._format  s    {{&9Q<DG9!"Wr7N#XAr~~/N!O {{"A|,1v 9Q<((rd   z=ExtensionArray formatting should use _ExtensionArrayFormatterrf   )axisrI  Fz{v}z {v})rS  )rV   r   rE  r  r  r
   r   r4   r   r  r}   rl   ndarrayr  r   	map_inferr   r   r&   r%  rangerh   shaper   anyr4  r8  r^  )ra   rV   r  r  valsinferredis_float_typer   r   r;  rS  tplrE  r  s   `           @@rb   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*":;	< rd   )   NrP   r  NrE   rb  NTTN)r  r5   r  ri   rE  rk  rT   r   rC  rj  rV   rf  rG   r   r   r   r  r   r  r   r   rg  r  rk  r   r   r   )r   r   r   rc   r  r  r   rd   rb   r  r    s     %)/3" %).255 5 #	5
 5 5 -5 5 5 5 5 #5 ,5 
58;Drd   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)superrc   rV   rE  r  r]  )ra   argskwargs	__class__s      rb   rc   zFloatArrayFormatter.__init__   se    $)&) (T^^-C$D))*!%!2!2$(! + .D(rd   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&   rT   )rS  rV   ra   s    rb   base_formatterz<FloatArrayFormatter._value_formatter.<locals>.base_formatter  s5    #/// Qx !q) rd   c                H    t        |       rt        |       S j                  S r   )r&   r   rT   )rS  ra   s    rb   r  z<FloatArrayFormatter._value_formatter.<locals>.base_formatter+  s    !&qs1v:t{{:rd   rb  c                J     |       j                  dj                  d      S )Nrb  rf   )replacer   )rS  r  ra   s    rb   decimal_formatterz?FloatArrayFormatter._value_formatter.<locals>.decimal_formatter0  s!    %a(00dllAFFrd   c                n    t        |       rt        |       kD  r |       S  d      S j                  S )Ng        )r&   absrT   )r  r  ra   	thresholds    rb   rE  z7FloatArrayFormatter._value_formatter.<locals>.formatter9  s6    U|u:	),U33,S11{{"rd   )rV   r   )ra   rV   r  rE  r  r  s   ``` @@rb   _value_formatterz$FloatArrayFormatter._value_formatter  sZ     ,,L 	; <<3G !/$$	# rd   c                t   
 	 	 	 	 	 	 	 	 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      D cg c]  \  }}|s ||      n| c}}      j                  | j                        }|S c c}}w )NTr  )r%   rl   arrayr  ravelreshaper  )r  rE  rT   maskvalr  	formatteds          rb   format_with_na_repzCFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_repJ  sw     <D #&fllndjjl4"PQ +,IcN7
 gfll#  s   B
c                   t        j                  |       j                         }t        j                  |       j                         }t	        |      t	        |      }}g }t        | j                         ||||d      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 )NTr  +j-)rl   realr  imagr%   r  r8  strip
startswithr  r  r  )r  rE  rT   real_valuesimag_values	real_mask	imag_maskformatted_lstr  real_valimag_valre_isnaim_isnaimag_formatteds                 rb   format_complex_with_na_repzKFloatArrayFormatter.get_result_as_array.<locals>.format_complex_with_na_repV  sS    ''&///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<<@@rd   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 )NrD   rI  objectrW   )r  rG   rT   r  r   r  _trim_zeros_complexr   _trim_zeros_floatrl   asarray)
rV   rE  rT   r  
is_complexr   r  r  ra   r  s
         rb   format_values_withzCFloatArrayFormatter.get_result_as_array.<locals>.format_values_with}  s    --lIFI +/,,&*@S4;;&dkkF [[F)&1J 3FIvN+FIvF0FF.vt||DFzz&99Mrd   Tz{value: .{digits:d}f}z{value:.{digits:d}f})r  c                "    j                   | z  S r   )rV   )r  ra   s    rb   r  z9FloatArrayFormatter.get_result_as_array.<locals>.<lambda>  s    ):):U)B rd   r   c              3  2   K   | ]  }t        |        y wr   rh   r/  r0  s     rb   r1  z:FloatArrayFormatter.get_result_as_array.<locals>.<genexpr>  s     :AQ:      Fg    .A
   z{value: .{digits:d}e}z{value:.{digits:d}e})r  r5   rE  r   rT   r   r   
np.ndarray)rE  r  rT   r  r   rV   r   r   r^  r  rh   r:  rl   r  r  )ra   r  fmt_strrV   formatted_valuesmaxlentoo_longabs_valshas_large_valueshas_small_valuesr  r  r  s   `         @@@rb   get_result_as_arrayz'FloatArrayFormatter.get_result_as_arrayD  s   
	
	*2
	<?
	
		A	A*2	A<?	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,?rd   c                4    t        | j                               S r   )r$  r   r   s    rb   r  z#FloatArrayFormatter._format_strings  s    D,,.//rd   r   NN)rV   rf  r  zfloat | Noner   r   )r   r  r   )r   r   r   rc   r  r   r  __classcell__r  s   @rb   r  r    s>    
) 04"&6,6  6 
	6pA F0rd   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  r0  r^  r(  s    rb   r  z4_IntArrayFormatter._format_strings.<locals>.<lambda>  s    1ooo&: rd   c                *    | dj                  |       S )Nz dr(  r)  r(  s    rb   r  z4_IntArrayFormatter._format_strings.<locals>.<lambda>  s    2&6&6&6&; rd   )r   rE  r  )ra   formatter_strrE  r0  r   s        rb   r  z"_IntArrayFormatter._format_strings  sN    &:M;MNN3m	,0KK8qil8
8 9s   ANr   )r   r   r   r  r   rd   rb   r  r    s    rd   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  rc   nat_repr  )ra   r  r.  r  r  r  s        rb   rc   z_Datetime64Formatter.__init__  s&     	*6*&rd   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)rT   r  )r  rE  _format_native_typesr.  r  tolist)ra   r  r0  r   s       rb   r  z$_Datetime64Formatter._format_strings  si    >>%/56!DNN1%6600<<T-=-= 1 

   "" 7s   A/r   N)r  r(   r.  r   r  r   r   r   r   r   r   r   __annotations__rc   r  r#  r$  s   @rb   r  r    sA    
  		'	' 	' 		' 
	'
#rd   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  )	rV   rT   r  rC  rG   r   r   r  r  )r  rE  
_formatterr}   r'   _internal_get_valuesrl   r  r
  r   rV   rT   r  rC  rG   r   r   r  )ra   r  rE  r  r  r   s         rb   r  z(_ExtensionArrayFormatter._format_strings  s    NN	!!'!2!2!2!>fk*//1EJJvV4E!**;;;;**LLLL,,LL1

 rd   Nr   r   r   r   r4  r  r   rd   rb   r  r    s    rd   r  c                f   t        |       dk(  rg S 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   rf   z/percentiles should all be in the interval [0,1]d   r\  r  )rh   rl   r  r    r   r  get_precisionroundastyperi   iscloser   unique
empty_liker
  )percentilesprecpercentiles_round_typeint_idxoutr;  unique_pctss          rb   format_percentilesrI    sj   D ;1	**[)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   r<  )to_beginto_endrf   )	rl   ediff1dr  floorlog10rj   r?  ri   r:  )r  rL  rM  diffrD  s        rb   r=  r=  T  s     8a<uQxTH %b	CS59_TF::ehv>Dt9DHHRXXbffTl+,33C88Dq$<DKrd   c                ,    | t         u r|S t        |       S r   )r   r   r0  r.  s     rb   _format_datetime64rT  ^  s    Cx q6Mrd   c                d    t        | t              r|S |r| j                  |      S | j                  S r   )r}   r   strftime
_date_repr)r0  r.  r  s      rb   _format_datetime64_dateonlyrX  g  s1    
 !Wzz+&& ||rd   c                     | rfdS fdS )z]Return a formatter callable taking a datetime64 as input and providing
    a string as outputc                     t        |       S )N)r.  r  )rX  )r0  r  r.  s    rb   r  z'get_format_datetime64.<locals>.<lambda>}  s    4wK
 rd   c                    t        |       S )N)r.  )rT  rS  s    rb   r  z'get_format_datetime64.<locals>.<lambda>  s    +Aw? rd   r   )is_dates_onlyr.  r  s    ``rb   get_format_datetime64r]  v  s     
 	
 @?rd   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_onlyr?  r
  rE  r]  r  )ra   idor  rE  r0  r   s         rb   r  z&_Datetime64TZFormatter._format_strings  sj    kk((##F+NN 
&;T--'
	 -33qil3
3 4s   A2Nr   r:  r   rd   rb   r  r    s    	rd   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  rc   r.  )ra   r  r.  r  r  s       rb   rc   z_Timedelta64Formatter.__init__  s     	*6*rd   c                    | j                   xs" t        | j                  | j                  d      }| j                  D cg c]
  } ||       c}S c c}w )NF)r.  box)rE  get_format_timedelta64r  r.  )ra   rE  r0  s      rb   r  z%_Timedelta64Formatter._format_strings  sE    NN 
&<KK5'
	 '+kk2	!222s   Ar   )r  r*   r.  r   r   r   r   r3  r$  s   @rb   r  r    s4    
  
 
3rd   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 )Nr)  ')r!   r%   r}   r   
_repr_base)r0  r   re  r^  r.  s     rb   r8  z*get_format_timedelta64.<locals>._formatter  sS    91$q'N!Y'!A V,]Frd   )r`  )r  r.  re  	even_daysr8  r^  s    ``  @rb   rf  rf    s*     %%I rd   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/  r0  
adjustments     rb   r1  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  )r0  rp  conf_maxrA  s    rb   justz_make_fixed_width.<locals>.just  s=    1!2W!<=m!$u,rd   r   )r0  r   r   r   )rh   r4   r^   r:  r   rG   )
r*  rG   r+  r_   rs  r0  r   rp  rr  rA  s
          @@@rb   r6  r6    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	
      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(?<!e)([j+-])rv   Nr   c              3  2   K   | ]  }t        |        y wr   r  )r/  parts     rb   r1  z&_trim_zeros_complex.<locals>.<genexpr>  s     ;dD	;r  rf   Tr  >r  )rer   r8  r   rh   r  r:  r  )str_complexesr   	real_part	imag_partr0  trimmednpadded_partspadded_lengthreal_ptimag_ptpaddeds               rb   r  r    s'   
 ryI 2
 ((+Q/"./B012 	MA$Y%:GDL
<A	;l;;a?M !$L!$4l126Ft T
 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.
    0rb  )rstripendswith)	str_floats    rb   r  r    s2    
   %I#S	rd   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   )rz  match)r0  number_regexs    rb   is_number_with_decimalz1_trim_zeros_float.<locals>.is_number_with_decimal#  s    xxa(44rd   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     rb   r1  z9_trim_zeros_float.<locals>.should_trim.<locals>.<genexpr>/  s     'IA

3'Is   )rh   r   )r  r0  numbersr  s      rb   should_trimz&_trim_zeros_float.<locals>.should_trim&  sE     %B(>q(A1BB7|aIC'I'I$II Cs   <<NrK  r  ri  )r  ArrayLike | list[str]r   r   )rz  compiler  )
str_floatsr   r~  r  r0  r   r  r  s         @@rb   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   )r}   r-   comany_not_nonerZ  rU   )rS   s    rb   r   r   <  s0    %$--zz%%rd   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
    iyiziair  ipir  iur  r   rv   r   rR  r  r  	   Gr  T   P   E   Z   YNc                     || _         || _        y r   accuracyuse_eng_prefix)ra   r  r  s      rb   rc   zEngFormatter.__init___  s     !,rd   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
        rP   infrf   r   rK  r   zE-02dzE+r  z{mant: g}{prefix}z{mant: .r  z
f}{prefix})mantprefix)r   r   is_nanis_infiniteri   mathrO  rP  rj   r:  ENG_PREFIXESr
  r  r  r^  )
ra   numdnumsignpow10	int_pow10r  r  
format_strr  s
             rb   __call__zEngFormatter.__call__e  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%?	rd   r  )r  r   r  r   r   r   )r  floatr   r   )r   r   r   r   r  rc   r  r   rd   rb   r  r  C  s    SS 	S 	S	
 	S 	C 	C 	C 	
2 	
3 	
3 	
3 	C 	C 	C  	C!" 	C#L* CH-"-;?-	-;rd   r  pandasc                0    t        dt        | |             y)a  
    Format float representation in DataFrame with SI notation.

    Sets the floating-point display format for ``DataFrame`` objects using engineering
    notation (SI units), allowing easier readability of values across wide ranges.

    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
        This method does not return a value. it updates the global display format
        for floats in DataFrames.

    See Also
    --------
    set_option : Set the value of the specified option or options.
    reset_option : Reset one or more options to their default value.

    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     rb   set_eng_float_formatr    s    D %|Hn'MNrd   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)rh   r4  r8  )	levelssentinelcontrolr   level
last_indexlengthsr;  keys	            rb   get_level_lengthsr    s    $ 6{a	fs6!9~%GF 
& 	FAsqzcXo"
&'*n
#
	 "%j:5
g  Mrd   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   )r}   r   r  s     rb   r1  z#buffer_put_lines.<locals>.<genexpr>  s     
-!:a
-s   rz   N)r  r   r  r   )r]   linesr0  s      rb   buffer_put_linesr    sC     
-u
--!&'AQ''IIdii (s   A)r   zdict[str, Any]r"  )r~  r   r]   r  rx  r   r   r   r   )r]   r  rx  r   r   z1Generator[WriteBuffer[str]] | Generator[StringIO])	NrP   NNrE   rb  TNN)r  r5   rE  rk  rV   rf  rT   r   r  r   rC  zstr | int | NonerG   r   r   r   r   rg  r  r   r  rk  r   r   )rC  np.ndarray | Sequence[float]r   r   )r  r  r   ri   rg  )r0  NaTType | Timestampr.  r   r   r   r2  )r0  r  r.  r   r  r   r   r   )r\  r   r.  r   r  r   r   r   )r   F)r  r*   r.  zstr | floatre  r   r   r   )rE   NN)
r*  r   rG   r   r+  r   r_   zprinting._TextAdjustment | Noner   r   )rb  )r{  r5   r   r   r   r   )r  r   r   r   )r  r  r   r   r   r   )rS   r,   r   r   )r   F)r  ri   r  r   r   r   )rv   )r  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   r   
contextlibr	   csvr
   r   r   	functoolsr   ior   r  rz  shutilr   typingr   r   r   r   numpyrl   pandas._config.configr   r   pandas._libsr   pandas._libs.missingr   pandas._libs.tslibsr   r   r   pandas._libs.tslibs.nattyper   pandas.util._decoratorsr   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.baser+   pandas.core.commoncorecommonr  pandas.core.indexes.apir,   r-   r.   r/   pandas.core.indexes.datetimesr0   pandas.core.indexes.timedeltasr1   pandas.io.commonr2   r3   r   r4   pandas._typingr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   r  rA   rB   rC   r4  VALID_JUSTIFY_PARAMETERSrM   rO   r   r   r   rn  rz  r  r   r  r  r  r  r  rI  r=  rT  rX  r]  r  r  rf  r6  r  r  r  r   r  r  r  r  r   rd   rb   <module>r     s  
 #  &      	 $  
  # 
 0 .  

  *      8 9 '   6 % 6p  % c$ c$L>:IF IFX^ ^F /3	+  	  DHM	+M7AM6M MP ,0"!%*.R R R  )R  	R 
 R  R  R  R  R  R  (R  R je ePI00 I0X/ #1 #65 B?"-?"?"D "  		  JN@@"%@<F@@1 32 3, ! 
 	H +/	  
)	
 DB	 7:!%!03!!H&] ]@ HAO AOJ 24((.((V rd   