o
    Ti)                    @  sN  U d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
 ddlmZmZ ddlmZ ddlmZ ddlmZ dd	lZdd	lZdd
lmZ ddlmZmZmZmZmZmZ ddlm Z  dd	l!Z"ddl#m$Z$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@ ddlAmBZBmCZCmDZD ddlEmFZF ddlGmHZH dd	lImJ  mKZL ddlMmNZN ddlOmPZPmQZQmRZRmSZS ddlTmUZU ddlVmWZW ddlXmYZY ddlZm[Z[m\Z\ ddl]m^Z^ er!ddl_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZj dd lkmlZlmmZm d!Znd"eod#< d$Zpd%Zqd"eod&< G d'd( d(ZrG d)d* d*ZsG d+d, d,ZtG d-d. d.etZudd0d1Zvdd3d4Zwdd5d6ZxG d7d8 d8ZyG d9d: d:Zz				dddAdBZ{e
		dddDdEZ|			F					G	H	I				ddd\d]Z}G d^d_ d_Z~G d`da dae~ZG dbdc dce~ZG ddde dee~ZG dfdg dge~ZddjdkZddndoZdddtduZ	p		dddwdxZ		ddd{d|Zdd~dZG dd deZG dd de~Z	p	ddddZ	G				ddddZddddZdddZ	HddddZdddZG dd dZddddZ	ddddZdddZd	S )z
Internal module for formatting output data in csv, html, xml,
and latex files. This module also applies to display formatting.
    )annotations)	GeneratorHashableIterableMappingSequence)contextmanager)
QUOTE_NONEQUOTE_NONNUMERIC)Decimal)partial)StringION)get_terminal_size)IOTYPE_CHECKINGAnyCallableFinalcast)east_asian_width)
get_option
set_option)lib)NA)NaT	Timedelta	Timestampget_unit_from_dtypeiNaTperiods_per_day)NaTType)is_complex_dtypeis_float
is_integeris_list_likeis_numeric_dtype	is_scalar)CategoricalDtypeDatetimeTZDtypeExtensionDtype)isnanotna)CategoricalDatetimeArrayTimedeltaArray)StringDtype)PandasObject)extract_array)Index
MultiIndexPeriodIndexensure_index)DatetimeIndex)TimedeltaIndex)concat)check_parent_directorystringify_path)printing)	ArrayLikeAxesColspaceArgTypeColspaceTypeCompressionOptionsFilePathFloatFormatTypeFormattersType
IndexLabelStorageOptionsWriteBuffer)	DataFrameSeriesa	  
        Parameters
        ----------
        buf : str, Path or StringIO-like, optional, default None
            Buffer to write to. If None, the output is returned as a string.
        columns : array-like, optional, default None
            The subset of columns to write. Writes all columns by default.
        col_space : %(col_space_type)s, optional
            %(col_space)s.
        header : %(header_type)s, optional
            %(header)s.
        index : bool, optional, default True
            Whether to print index (row) labels.
        na_rep : str, optional, default 'NaN'
            String representation of ``NaN`` to use.
        formatters : list, tuple or dict of one-param. functions, optional
            Formatter functions to apply to columns' elements by position or
            name.
            The result of each function must be a unicode string.
            List/tuple must be of length equal to the number of columns.
        float_format : one-parameter function, optional, default None
            Formatter function to apply to columns' elements if they are
            floats. This function must return a unicode string and will be
            applied only to the non-``NaN`` elements, with ``NaN`` being
            handled by ``na_rep``.

            .. versionchanged:: 1.2.0

        sparsify : bool, optional, default True
            Set to False for a DataFrame with a hierarchical index to print
            every multiindex key at each row.
        index_names : bool, optional, default True
            Prints the names of the indexes.
        justify : str, default None
            How to justify the column labels. If None uses the option from
            the print configuration (controlled by set_option), 'right' out
            of the box. Valid values are

            * left
            * right
            * center
            * justify
            * justify-all
            * start
            * end
            * inherit
            * match-parent
            * initial
            * unset.
        max_rows : int, optional
            Maximum number of rows to display in the console.
        max_cols : int, optional
            Maximum number of columns to display in the console.
        show_dimensions : bool, default False
            Display DataFrame dimensions (number of rows by number of columns).
        decimal : str, default '.'
            Character recognized as decimal separator, e.g. ',' in Europe.
    r   common_docstring)leftrightcenterjustifyzjustify-allstartendinheritzmatch-parentinitialZunsetz
        Returns
        -------
        str or None
            If buf is None, returns the result as a string. Otherwise returns
            None.
    return_docstringc                   @  s>   e Zd Z				ddddZdddZdddZdddZdS )CategoricalFormatterNTNaNcategoricalr,   bufIO[str] | Nonelengthboolna_repstrfooterreturnNonec                 C  s8   || _ |d ur	|ntd| _|| _|| _|| _t| _d S N )rU   r   rV   rZ   rX   r\   r
   quoting)selfrU   rV   rX   rZ   r\    rc   X/var/www/html/evchargy.com/venv/lib/python3.10/site-packages/pandas/io/formats/format.py__init__   s   
zCategoricalFormatter.__init__c                 C  sP   d}| j r|r|d7 }|dt| j 7 }| j }|r |d7 }||7 }t|S )Nr`   , Length: 
)rX   lenrU   _repr_categories_infor[   )rb   r\   
level_inforc   rc   rd   _get_footer   s   
z CategoricalFormatter._get_footer	list[str]c                 C  s   t | j d d | j| jdS )N)float_formatrZ   ra   )format_arrayrU   _internal_get_valuesrZ   ra   rb   rc   rc   rd   _get_formatted_values   s   z*CategoricalFormatter._get_formatted_valuesc                 C  s|   | j }t|dkr| jr|  S dS |  }dd |D }d|}d| d g}| jr7|  }|r7|| td|S )	Nr   r`   c                 S  s   g | ]}|  qS rc   )strip.0irc   rc   rd   
<listcomp>       z2CategoricalFormatter.to_string.<locals>.<listcomp>rf   []rh   )rU   ri   r\   rl   rr   joinappendr[   )rb   rU   
fmt_valuesvaluesresultr\   rc   rc   rd   	to_string   s   

zCategoricalFormatter.to_string)NTrT   T)rU   r,   rV   rW   rX   rY   rZ   r[   r\   rY   r]   r^   r]   r[   r]   rm   )__name__
__module____qualname__re   rl   rr   r   rc   rc   rc   rd   rS      s    

	rS   c                   @  s^   e Zd Z										d'd(ddZd)ddZd*ddZd+d d!Zd,d#d$Zd*d%d&ZdS )-SeriesFormatterNTrT   FseriesrH   rV   rW   rX   
bool | strheaderrY   indexrZ   r[   namern   
str | Nonedtypemax_rows
int | Nonemin_rowsr]   r^   c                 C  st   || _ |d ur	|nt | _|| _|| _|| _|| _|| _|
| _|| _	|d u r*t
d}|| _|	| _t | _|   d S )Ndisplay.float_format)r   r   rV   r   rZ   r   rX   r   r   r   r   rn   r   get_adjustmentadj_chk_truncate)rb   r   rV   rX   r   r   rZ   r   rn   r   r   r   rc   rc   rd   re   	  s   zSeriesFormatter.__init__c                 C  s   |  | j }| j}|ot| j|k}| j}|rItt|}|r"t||}|dkr0|}|jd | }n|d }t|jd | |j| d  f}|| _	nd | _	|| _
|| _d S )N      )r   r   ri   r   r   intminilocr8   
tr_row_num	tr_seriesis_truncated_vertically)rb   r   r   r   r   row_numrc   rc   rd   r   )  s$   

"
zSeriesFormatter._chk_truncatec                 C  s>  | j j}d}t| j jdd d ur&t| j jtttfsJ |d| j jj 7 }| jdurC|d urC|r5|d7 }t	j
|dd}|d| 7 }| jd	u sP| jd
kr`| jr`|rV|d7 }|dt| j  7 }| jdur| jd urt| jjdd }|r|rz|d7 }|dt	
| 7 }t| jjtr| jj }|r|d7 }||7 }t|S )Nr`   freqzFreq: Frf   	rh   )escape_charszName: Ttruncaterg   r   zdtype: rh   )r   r   getattrr   
isinstancer6   r4   r7   Zfreqstrr;   pprint_thingrX   r   ri   r   r   r'   _valuesrj   r[   )rb   r   r\   Zseries_nameZ
dtype_namerk   rc   rc   rd   rl   D  s:   
zSeriesFormatter._get_footertuple[list[str], bool]c                 C  sX   | j j}t|trtdd |jD }|jdd}||fS |jd u}|jdd}||fS )Nc                 s  s    | ]}|V  qd S Nrc   ru   r   rc   rc   rd   	<genexpr>q  s    z7SeriesFormatter._get_formatted_index.<locals>.<genexpr>T)names)r   )r   r   r   r3   anyr   formatr   )rb   r   have_header	fmt_indexrc   rc   rd   _get_formatted_indexm  s   

z$SeriesFormatter._get_formatted_indexrm   c                 C  s   t | jjd | j| j| jdS )N)rn   rZ   leading_space)ro   r   r   rn   rZ   r   rq   rc   rc   rd   rr   x  s   z%SeriesFormatter._get_formatted_valuesc                 C  s,  | j }|  }t|dkrt| jj d| dS |  \}}|  }| jr_d}| j	}t
t|}| j||d  }|dkrAd}	nd}	| jj|	g|dd	d }	||| |	 ||d d
 | jrs| jjdg|dd  |gR  }
n| jd|}
| jr|r|d d |
 }
|r|
d| 7 }
td
|
S )Nr   z([], )r      ...z..rL   moder`   rh   )r   rl   ri   typer   r   r   rr   r   r   r   r   r   rM   insertr   adjoinr   r[   r{   )rb   r   r\   r   r   r}   Zn_header_rowsr   widthZdot_strr   rc   rc   rd   r     s2   
"
zSeriesFormatter.to_string)
NTTTrT   FNTNN)r   rH   rV   rW   rX   r   r   rY   r   rY   rZ   r[   r   rY   rn   r   r   rY   r   r   r   r   r]   r^   r]   r^   r   )r]   r   r   )	r   r   r   re   r   rl   r   rr   r   rc   rc   rc   rd   r     s"    
 

)
	r   c                   @  s6   e Zd ZdddZddd	ZddddZdddZdS )TextAdjustmentr]   r^   c                 C  s   t d| _d S )Nzdisplay.encoding)r   encodingrq   rc   rc   rd   re     s   zTextAdjustment.__init__textr[   r   c                 C  s   t |S r   ri   rb   r   rc   rc   rd   ri     s   zTextAdjustment.lenrK   textsr   max_lenr   rm   c                 C  s   t j|||dS )Nr   )r;   rM   rb   r   r   r   rc   rc   rd   rM        zTextAdjustment.justifyspacec                 O  s"   t j|g|R | j| jd|S )N)ZstrlenZjustfunc)r;   r   ri   rM   )rb   r   listskwargsrc   rc   rd   r     s   zTextAdjustment.adjoinNr   r   r[   r]   r   rK   )r   r   r   r   r   r[   r]   rm   )r   r   r]   r[   )r   r   r   re   ri   rM   r   rc   rc   rc   rd   r     s
    

r   c                      s6   e Zd Zd fddZddd	Z	
ddddZ  ZS )EastAsianTextAdjustmentr]   r^   c                   s6   t    tdrd| _nd| _dddddd| _d S )Nz!display.unicode.ambiguous_as_wider   r   )ZNaNWFH)superre   r   ambiguous_width_EAW_MAPrq   	__class__rc   rd   re     s
   
z EastAsianTextAdjustment.__init__r   r[   r   c                   s(   t |ts	t|S t fdd|D S )zN
        Calculate display width considering unicode East Asian Width
        c                 3  s$    | ]} j t| jV  qd S r   )r   getr   r   )ru   crq   rc   rd   r     s    
z.EastAsianTextAdjustment.len.<locals>.<genexpr>)r   r[   ri   sumr   rc   rq   rd   ri     s
   
zEastAsianTextAdjustment.lenrK   r   Iterable[str]r   r   rm   c                   sT   fdd |dkr fdd|D S |dkr! fdd|D S  fdd|D S )	Nc                   s     |  t |  S r   r   )t)r   rb   rc   rd   _get_pad     z1EastAsianTextAdjustment.justify.<locals>._get_padrJ   c                      g | ]	}|  |qS rc   )ljustru   xr   rc   rd   rw         z3EastAsianTextAdjustment.justify.<locals>.<listcomp>rL   c                   r   rc   )rL   r   r   rc   rd   rw     r   c                   r   rc   )rjustr   r   rc   rd   rw     r   rc   r   rc   )r   r   rb   rd   rM     s   zEastAsianTextAdjustment.justifyr   r   r   )r   r   r   r   r   r[   r]   rm   )r   r   r   re   ri   rM   __classcell__rc   rc   r   rd   r     s
    
r   r]   c                  C  s   t d} | r	t S t S )Nz display.unicode.east_asian_width)r   r   r   )Zuse_east_asian_widthrc   rc   rd   r     s   r   dict[str, Any]c                  C  sL   ddl m}  tdr|  \}}nd}tdtdtdtdtd	|d
S )a  Get the parameters used to repr(dataFrame) calls using DataFrame.to_string.

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

    .. versionadded:: 1.4.0

    Example
    -------
    >>> import pandas as pd
    >>>
    >>> df = pd.DataFrame([[1, 2], [3, 4]])
    >>> repr_params = pd.io.formats.format.get_dataframe_repr_params()
    >>> repr(df) == df.to_string(**repr_params)
    True
    r   )consolezdisplay.expand_frame_reprNdisplay.max_rowsdisplay.min_rowszdisplay.max_columnsdisplay.max_colwidthdisplay.show_dimensions)r   r   max_colsZmax_colwidthshow_dimensions
line_width)pandas.io.formatsr   r   Zget_console_size)r   r   _rc   rc   rd   get_dataframe_repr_params  s   r   c                  C  sN   t  \} }tddkr|ntd}tddkr|ntd}dd||tddS )a  Get the parameters used to repr(Series) calls using Series.to_string.

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

    .. versionadded:: 1.4.0

    Example
    -------
    >>> import pandas as pd
    >>>
    >>> ser = pd.Series([1, 2, 3, 4])
    >>> repr_params = pd.io.formats.format.get_series_repr_params()
    >>> repr(ser) == ser.to_string(**repr_params)
    True
    r   r   r   Tr   )r   r   r   r   rX   )r   r   )r   heightr   r   rc   rc   rd   get_series_repr_params  s   
r   c                   @  s  e Zd ZdZer
endZeee 7 Z																	dtdud(d)Zdvd+d,Zedwd-d.Z	edwd/d0Z
edwd1d2Zedwd3d4Zedxd5d6Zedwd7d8Zedwd9d:Zedwd;d<Zedwd=d>Zedyd@dAZdzdBdCZd{dEdFZd|dGdHZd}dJdKZd~dMdNZddOdPZddQdRZddSdTZdwdUdVZdwdWdXZdwdYdZZdyd[d\Zdd]d^Zdd_d`Z ddadbZ!dvdcddZ"ddgdhZ#ddkdlZ$ddmdnZ%ddodpZ&ddrdsZ'dS )DataFrameFormatterz;Class for processing dataframe formatting options and data.r`   NTrT   F.framerG   columnsAxes | None	col_spaceColspaceArgType | Noner   bool | list[str]r   rY   rZ   r[   
formattersFormattersType | NonerM   r   rn   FloatFormatType | Nonesparsifybool | Noneindex_namesr   r   r   r   r   r   decimal	bold_rowsescaper]   r^   c                 C  s   || _ | || _| || _|| _|| _|| _| || _	| 
|| _|	| _| |
| _|| _|| _|| _|| _|| _|| _|| _|| _|  | _|  | _| j | _|   t | _d S r   )r   _initialize_columnsr   _initialize_colspacer   r   r   rZ   _initialize_formattersr   _initialize_justifyrM   rn   _initialize_sparsifyr   show_index_namesr   r  r  r   r   r   r   _calc_max_cols_fittedmax_cols_fitted_calc_max_rows_fittedmax_rows_fittedtr_framer   r   r   )rb   r   r   r   r   r   rZ   r   rM   rn   r   r   r   r   r   r   r   r  r  rc   rc   rd   re   4  s.   

zDataFrameFormatter.__init__list[list[str]]c                 C  s*   |   }| jr| | j}|d| |S )zP
        Render a DataFrame to a list of columns (as lists of strings).
        r   )_get_strcols_without_indexr   r   r  r   )rb   strcolsZ	str_indexrc   rc   rd   get_strcolsc  s
   zDataFrameFormatter.get_strcolsc                 C  s   | j du p| j dko| jS )NTr   )r   is_truncatedrq   rc   rc   rd   should_show_dimensionso  s   
z)DataFrameFormatter.should_show_dimensionsc                 C  s   t | jp| jS r   )rY   is_truncated_horizontallyr   rq   rc   rc   rd   r  u  s   zDataFrameFormatter.is_truncatedc                 C     t | jot| j| jkS r   )rY   r
  ri   r   rq   rc   rc   rd   r  y     z,DataFrameFormatter.is_truncated_horizontallyc                 C  r  r   )rY   r  ri   r   rq   rc   rc   rd   r   }  r  z*DataFrameFormatter.is_truncated_verticallyc                 C  s    dt | j dt | jj dS )Nz

[z rows x z	 columns])ri   r   r   rq   rc   rc   rd   dimensions_info  s    z"DataFrameFormatter.dimensions_infoc                 C     t | jjS r   )
_has_namesr   r   rq   rc   rc   rd   has_index_names     z"DataFrameFormatter.has_index_namesc                 C  r  r   )r  r   r   rq   rc   rc   rd   has_column_names  r  z#DataFrameFormatter.has_column_namesc                 C     t | j| j| jfS r   )allr  r   r  rq   rc   rc   rd   show_row_idx_names     z%DataFrameFormatter.show_row_idx_namesc                 C  r  r   )r  r  r  r   rq   rc   rc   rd   show_col_idx_names  r   z%DataFrameFormatter.show_col_idx_namesr   c                 C  s   t | jpt| jt| jS r   )r   r   ri   r   rq   rc   rc   rd   max_rows_displayed  s   z%DataFrameFormatter.max_rows_displayedc                 C     |d u rt dS |S )Nzdisplay.multi_sparser   )rb   r   rc   rc   rd   r    s   z'DataFrameFormatter._initialize_sparsifyrC   c                 C  sP   |d u r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   r   dict
ValueError)rb   r   rc   rc   rd   r    s   
z)DataFrameFormatter._initialize_formattersc                 C  r#  )Nzdisplay.colheader_justifyr$  )rb   rM   rc   rc   rd   r    s   z&DataFrameFormatter._initialize_justifyr2   c                 C  s(   |d urt |}| j| | _|S | jjS r   )r5   r   r   )rb   r   colsrc   rc   rd   r    s
   z&DataFrameFormatter._initialize_columnsr?   c                   s    d u ri }|S t  ttfr#d i}| fdd| jjD  |S t  trD  D ]}|| jjvr?|dkr?td| q, }|S t	| jjt	 kr_tdt	  dt	| jj dt
t| jj }|S )Nr`   c                   s   i | ]}| qS rc   rc   )ru   columnr   rc   rd   
<dictcomp>      z;DataFrameFormatter._initialize_colspace.<locals>.<dictcomp>z,Col_space is defined for an unknown column: zCol_space length(r%  r   )r   r   r[   updater   r   r   keysr'  ri   r&  zip)rb   r   r   r)  rc   r*  rd   r    s0   

z'DataFrameFormatter._initialize_colspacec                 C  s,   |   s| jS t \}}| |r|S | jS )z%Number of columns fitting the screen.)_is_in_terminalr   r   _is_screen_narrow)rb   r   r   rc   rc   rd   r	    s   

z(DataFrameFormatter._calc_max_cols_fittedc                 C  sP   |   r t \}}| jdkr||   S | |r|}n| j}n| j}| |S )z,Number of rows with data fitting the screen.r   )r0  r   r   _get_number_of_auxiliary_rows_is_screen_short_adjust_max_rows)rb   r   r   r   rc   rc   rd   r    s   



z(DataFrameFormatter._calc_max_rows_fittedc                 C  s(   |rt | j|kr| jrt| j|}|S )zAdjust max_rows using display logic.

        See description here:
        https://pandas.pydata.org/docs/dev/user_guide/options.html#frequently-used-options

        GH #37359
        )ri   r   r   r   )rb   r   rc   rc   rd   r4    s   z#DataFrameFormatter._adjust_max_rowsc                 C  s   t | jdkp
| jdkS )z/Check if the output is to be shown in terminal.r   )rY   r   r   rq   rc   rc   rd   r0    s   z"DataFrameFormatter._is_in_terminalc                 C  s   t | jdkot| jj|kS Nr   )rY   r   ri   r   r   )rb   	max_widthrc   rc   rd   r1    s   z$DataFrameFormatter._is_screen_narrowc                 C  s   t | jdkot| j|kS r5  )rY   r   ri   r   )rb   
max_heightrc   rc   rd   r3    s   z#DataFrameFormatter._is_screen_shortc                 C  s:   d}d}|| }| j r|t| j 7 }| jr|d7 }|S )z?Get number of rows occupied by prompt, dots and dimension info.r   )r   ri   r  
splitlinesr   )rb   Zdot_rowZ
prompt_rowZnum_rowsrc   rc   rd   r2    s   z0DataFrameFormatter._get_number_of_auxiliary_rowsc                 C  s$   | j r|   | jr|   dS dS )zY
        Check whether the frame should be truncated. If so, slice the frame up.
        N)r  _truncate_horizontallyr   _truncate_verticallyrq   rc   rc   rd   r     s
   zDataFrameFormatter.truncatec                 C  s   | j dusJ | j d }|dkrM| jjddd|f }| jjdd| df }t||fdd| _t| jttfrLg | jd| | j| d | _ntt	| j
}| jjddd|f | _|| _dS )zRemove columns, which are not to be displayed and adjust formatters.

        Attributes affected:
            - tr_frame
            - formatters
            - tr_col_num
        Nr   r   Zaxis)r
  r  r   r8   r   r   listtupler   r   r   Z
tr_col_num)rb   Zcol_numrJ   rK   rc   rc   rd   r9    s    

z)DataFrameFormatter._truncate_horizontallyc                 C  s   | j dusJ | j d }|dkr1| jjd|ddf }| jj| dddf }t||f| _ntt| j}| jjd|ddf | _|| _dS )zRemove rows, which are not to be displayed.

        Attributes affected:
            - tr_frame
            - tr_row_num
        Nr   r   )r  r  r   r8   r   r   r   r   )rb   r   headtailrc   rc   rd   r:  9  s   

z'DataFrameFormatter._truncate_verticallyc           
   	     s  g }t  js1 js1t jD ]\}} |}t| jt j	|d j
d}|| q|S t  jrcttt  j _t jt jkrZtdt j dt j ddd  jD }n  j} jrv|D ]}|d qnt jD ]N\}}|| }tt j	|dg fd	d
|D R  } |}t| j| j
d}tg  fdd
|D |R  }	 j
j||	 jd}|||  q{|S )Nr   )stringsrM   minimumr   zWriting z cols but got z aliasesc                 S  s   g | ]}|gqS rc   rc   )ru   labelrc   rc   rd   rw   b  r,  zADataFrameFormatter._get_strcols_without_index.<locals>.<listcomp>r`   c                 3      | ]	} j |V  qd S r   r   ri   r   rq   rc   rd   r   m      z@DataFrameFormatter._get_strcols_without_index.<locals>.<genexpr>)rA  r   c                 3  rC  r   rD  r   rq   rc   rd   r   t  rE  r   )r$   r   	enumerater  
format_col_make_fixed_widthrM   r   r   r   r   r|   r   r<  r[   ri   r   r'  _get_formatted_column_labelsr  max)
rb   r  rv   r   r}   str_columnsr   ZcheaderZheader_colwidthr   rc   rq   rd   r  K  sP   


 z-DataFrameFormatter._get_strcols_without_indexrv   rm   c              	   C  sL   | j }| |}t|jd d |f j|| j| j| j|j	| | j
| jdS )N)rn   rZ   r   r   r   )r  _get_formatterro   r   r   rn   rZ   r   r   r   r   r   )rb   rv   r   	formatterrc   rc   rd   rG  z  s   
zDataFrameFormatter.format_col	str | intCallable | Nonec                 C  sZ   t | jttfrt|rtt|}| j| S d S t|r&|| jvr&| j| }| j|d S r   )	r   r   r<  r=  r#   r   r   r   r   )rb   rv   rc   rc   rd   rL    s   


z!DataFrameFormatter._get_formatterc                   s   ddl m} |j}t|tr_|jddd}tt| }jj	j
}tdd |jD tt|tt|  fddttfd	d|D  }jrTt|rT||}d
d t| D }|S | }jj	}tt|tt|  fddt|D }|S )Nr   )sparsify_labelsF)r   r   c                 s  s    | ]}|j V  qd S r   )Zis_floating)ru   levelrc   rc   rd   r     s    zBDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>c                   s"   |j vr |  rsd| S |S )N )r   )r   y)need_leadsprestrict_formattingrb   rc   rd   space_format  s   
zEDataFrameFormatter._get_formatted_column_labels.<locals>.space_formatc                 3  s$    | ]  fd d D V  qdS )c                   s   g | ]} |qS rc   rc   )ru   rS  )rV  r   rc   rd   rw         zMDataFrameFormatter._get_formatted_column_labels.<locals>.<genexpr>.<listcomp>Nrc   )ru   )rV  r   rd   r     s   " c                 S     g | ]}t |qS rc   )r<  r   rc   rc   rd   rw     rx   zCDataFrameFormatter._get_formatted_column_labels.<locals>.<listcomp>c                   s0   g | ]\}} |s | rd | n|gqS )rR  )rL  )ru   rv   r   )rT  rb   rc   rd   rw     s    )Zpandas.core.indexes.multirP  r   r   r3   r   r<  r/  r   dtypesr   r   levelsr&  mapr%   r   ri   rF  )rb   r   rP  r   Zfmt_columnsrZ  rK  rc   )rT  rU  rb   rV  rd   rI    s.   

	
z/DataFrameFormatter._get_formatted_column_labelsc                   s   dd j  D  |j}|j}d}t|tr&|jjdj	|d}n	|jj	|dg} fdd|D }j
jd	g|R  d
}jrSdd  D }ndg|j }jr`|| S |S )Nc                 S  s   i | ]
\}}|t t|qS rc   )r   r   )ru   kvrc   rc   rd   r+    s    z;DataFrameFormatter._get_formatted_index.<locals>.<dictcomp>	__index__F)r   r   r   rM  )r   rM  c              
     s.   g | ]}t tt|d  ddjdqS )rJ   r`   r   )rM   rA  r   )r=  rH  r<  r   r   r   r   rb   rc   rd   rw     s    z;DataFrameFormatter._get_formatted_index.<locals>.<listcomp>r   rh   c                 S  rY  rc   r[   r   rc   rc   rd   rw     rx   r`   )r   itemsr   r   rL  r   r3   r   r   r  r   r   splitr!  _get_column_name_listZnlevelsr   )rb   r   r   r   fmtr   ZadjoinedZ
col_headerrc   r`  rd   r     s,   

	z'DataFrameFormatter._get_formatted_indexlist[Hashable]c                 C  sN   g }| j j}t|tr|dd |jD  |S ||jd u r!dn|j |S )Nc                 s  s     | ]}|d u r
dn|V  qd S r_   rc   r   rc   rc   rd   r     s    z;DataFrameFormatter._get_column_name_list.<locals>.<genexpr>r`   )r   r   r   r3   extendr   r|   r   )rb   r   r   rc   rc   rd   rd    s   
z(DataFrameFormatter._get_column_name_list)NNTTrT   NNNNTNNNFr   FT)&r   rG   r   r   r   r   r   r   r   rY   rZ   r[   r   r   rM   r   rn   r   r   r   r   rY   r   r   r   r   r   r   r   r   r   r[   r  rY   r  rY   r]   r^   )r]   r  r]   rY   r   )r]   r   )r   r   r]   rY   )r   r   r]   rC   )rM   r   r]   r[   )r   r   r]   r2   )r   r   r]   r?   )r]   r   )r   r   r]   r   r   )rv   r   r]   rm   )rv   rN  r]   rO  )r   rG   r]   r  )r   rG   r]   rm   )r]   rf  )(r   r   r   __doc__rI   rR   re   r  propertyr  r  r  r   r  r  r  r  r!  r"  r  r  r  r  r  r	  r  r4  r0  r1  r3  r2  r   r9  r:  r  rG  rL  rI  r   rd  rc   rc   rc   rd   r   .  s    
/

















/


)(r   c                   @  sr   e Zd ZdZd9ddZ									d:d;ddZ			d<d=ddZ													 		!	d>d?d7d8ZdS )@DataFrameRendereraJ  Class for creating dataframe output in multiple formats.

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

    Called in pandas.core.frame.DataFrame:
        - to_html
        - to_string

    Parameters
    ----------
    fmt : DataFrameFormatter
        Formatter with the formatting options.
    re  r   r]   r^   c                 C  s
   || _ d S r   )re  )rb   re  rc   rc   rd   re     s   
zDataFrameRenderer.__init__NFrV   "FilePath | WriteBuffer[str] | Noner   r   classesstr | list | tuple | NonenotebookrY   borderint | bool | Nonetable_idrender_linksc                 C  sF   ddl m}m}	 |r|	n|}
|
| j||||d}| }t|||d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)rm  rp  rr  rs  rV   r   )Zpandas.io.formats.htmlrt  ru  re  r   save_to_buffer)rb   rV   r   rm  ro  rp  rr  rs  rt  ru  ZKlassZhtml_formatterstringrc   rc   rd   to_html  s   "zDataFrameRenderer.to_htmlr   r   c                 C  s0   ddl m} || j|d}| }t|||d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   rv  )Zpandas.io.formats.stringrz  re  r   rw  )rb   rV   r   r   rz  Zstring_formatterrx  rc   rc   rd   r   5  s   zDataFrameRenderer.to_string,winfer"Tstrictpath_or_buf7FilePath | WriteBuffer[bytes] | WriteBuffer[str] | Nonesepr[   r   Sequence[Hashable] | Noneindex_labelIndexLabel | Noner   compressionr@   ra   	quotecharlineterminator	chunksizedate_formatdoublequote
escapecharerrorsstorage_optionsStorageOptions | Nonec                 C  s   ddl m} |du rd}t }nd}|di d|d|
d|d	|d
|d|d|d|d|d|d|d|	d|d|d|d|d| j}|  |rbt|tsXJ | }|  |S dS )z;
        Render dataframe as comma-separated file.
        r   )CSVFormatterNTFr  r  r  r   r  r  ra   r(  r  r   r  r  r  r  r  r  rM  rc   )Zpandas.io.formats.csvsr  r   re  saver   getvalueclose)rb   r  r   r  r   r  r   r  ra   r  r  r  r  r  r  r  r  r  Zcreated_bufferZcsv_formattercontentrc   rc   rd   to_csvO  s^   	
zDataFrameRenderer.to_csv)re  r   r]   r^   )NNNFNNF)rV   rl  r   r   rm  rn  ro  rY   rp  rq  rr  r   rs  rY   r]   r   )NNN)rV   rl  r   r   r   r   r]   r   )NNr{  NNr|  r}  Nr~  NNNTNr  N)"r  r  r   r   r  r[   r   r  r  r  r   r[   r  r@   ra   r   r  r[   r  r   r  r   r  r   r  rY   r  r   r  r[   r  r  r]   r   )r   r   r   ri  re   ry  r   r  rc   rc   rc   rd   rk    s@    
5rk  rx  r[   rV   rl  r   r   c                 C  s\   t ||d}||  |du r| W  d   S 	 W d   dS 1 s'w   Y  dS )zQ
    Perform serialization. Write to buf or return as string if buf is None.
    )r   N)
get_bufferwriter  )rx  rV   r   frc   rc   rd   rw    s   
$rw  IGenerator[WriteBuffer[str], None, None] | Generator[StringIO, None, None]c                 c  s    | dur
t | } nt } |du rd}n	t| tstdt| dr'| V  dS t| trPtt|  t| d|dd}|V  W d   dS 1 sIw   Y  dS td)	z
    Context manager to open, yield and close buffer for filenames or Path-like
    objects, otherwise yield buf unchanged.
    Nzutf-8z1buf is not a file name and encoding is specified.r  r|  r`   )r   newlinez1buf is not a file name and it has no write method)	r:   r   r   r[   r'  hasattrr9   open	TypeError)rV   r   r  rc   rc   rd   r    s    




"r  rT   rK   r   Tr~   r   rM  rO  rn   r   rZ   digitsr   r   str | int | NonerM   r   r   r   ra   fallback_formatterrm   c                 C  s   t | jdr
t}n2t| jtrt}n)t | jdrt}nt| jtr&t	}nt | jdr0t
}nt | jdr:t}nt}|du rBd}|du rJtd}|du rRtd}|| |||||||||	|
d	}| S )
a{  
    Format an array for printing.

    Parameters
    ----------
    values
    formatter
    float_format
    na_rep
    digits
    space
    justify
    decimal
    leading_space : bool, optional, default True
        Whether the array should be formatted with a leading space.
        When an array as a column of a Series or DataFrame, we do want
        the leading space to pad between columns.

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

    Returns
    -------
    List[str]
    MmfciuN   r   display.precision)
r  rZ   rn   rM  r   rM   r   r   ra   r  )r   Zis_np_dtyper   Datetime64Formatterr   r(   Datetime64TZFormatterTimedelta64Formatterr)   ExtensionArrayFormatterFloatArrayFormatterIntArrayFormatterGenericArrayFormatterr   
get_result)r~   rM  rn   rZ   r  r   rM   r   r   ra   r  Z	fmt_klassZfmt_objrc   rc   rd   ro     sB   )ro   c                   @  sB   e Zd Z											d&d'dd Zd(d"d#Zd(d$d%ZdS ))r     NrT   r  rK   r   Tr~   r   r  r   rM  rO  rZ   r[   r   rN  rn   r   rM   r   ra   r   fixed_widthrY   r   r   r  r]   r^   c                 C  sL   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _d S r   )r~   r  rZ   r   rM  rn   rM   r   ra   r  r   r  )rb   r~   r  rM  rZ   r   rn   rM   r   ra   r  r   r  rc   rc   rd   re     s   
zGenericArrayFormatter.__init__rm   c                 C  s   |   }t|| jS r   )_format_stringsrH  rM   )rb   r}   rc   rc   rd   r  0  s   z GenericArrayFormatter.get_resultc                   s|  j d u rtd}|d u rtdfdd}nj }jd ur$j njd ur-j njd uo6jtk}ttjd|d  fdd}t	j
d	d
}t|tjsWtdt|t}|tjt|ttdt|jd@ }j}|d u r{| }g }t|D ]:\}	}
||	 rjd ur|r|d||
  q||	 r|||
 q|du rd}nd}||j||
d q|S )Nr   r  c                   s   t | d ddS )Nz .dr  )_trim_zeros_single_floatrX  )	precisionrc   rd   <lambda>9  s    z7GenericArrayFormatter._format_strings.<locals>.<lambda>r   )r   quote_stringsc              	     s   j d ur;t| r;t| r;z | d u rW dS | tu rttW S | tu s't| r*W dS W j S  tt	fy:   Y j S w t
| trDt| S t
| trMt| S t | S )Nr^   r   )rZ   r&   r*   r   r[   r   npZisnatr  r'  r   r0   r/   reprrX  )rM  rb   rc   rd   _formatK  s&   


z6GenericArrayFormatter._format_strings.<locals>._formatTZextract_numpyz<ExtensionArray formatting should use ExtensionArrayFormatterr   r;  rR  Fz{v}z {v}r^  )rn   r   rM  r  ra   r	   r   r;   r   r1   r~   r   r  ndarrayr  r   Z	map_inferr"   r  r+   r=  rangeri   shaper   r   rF  r|   r   )rb   rn   r  r  valsinferredZis_float_typer   r}   rv   r^  Ztplrc   )rM  r  rb   rd   r  4  sT   


 z%GenericArrayFormatter._format_strings)r  NrT   r  NrK   r   NTTN)r~   r   r  r   rM  rO  rZ   r[   r   rN  rn   r   rM   r[   r   r[   ra   r   r  rY   r   r   r  rO  r]   r^   r   )r   r   r   re   r  r  rc   rc   rc   rd   r    s    
r  c                      sB   e Zd Zd fddZ		ddddZdddZdddZ  ZS )r  r]   r^   c                   sT   t  j|i | | jd ur$| jd u r&d| _t| jr(| j| _d | _d S d S d S d S NF)r   re   rn   rM  r  callable)rb   argsr   r   rc   rd   re     s   

zFloatArrayFormatter.__init__Nrn   r   	thresholdfloat | Noner   c                   sl   du rj rfdd nfdd jdkr$ fddn du r,S fdd	}|S )
z;Returns a function to be applied on each value to format itNc                   s$    d usJ t | r | dS jS )Nvalue)r+   rZ   r  )rn   rb   rc   rd   base_formatter  s   
z<FloatArrayFormatter._value_formatter.<locals>.base_formatterc                   s   t | rt| S  jS r   )r+   r[   rZ   r  rq   rc   rd   r    r   r   c                   s    |  djdS )Nr   r   )replacer   r  )r  rb   rc   rd   decimal_formatter  s   z?FloatArrayFormatter._value_formatter.<locals>.decimal_formatterc                   s*   t | rt| kr | S  dS jS )Ng        )r+   absrZ   r  )r  rb   r  rc   rd   rM    s
   z7FloatArrayFormatter._value_formatter.<locals>.formatter)rn   r   )rb   rn   r  rM  rc   )r  r  rn   rb   r  rd   _value_formatter  s   
	z$FloatArrayFormatter._value_formatter
np.ndarrayc           
        sT  ddddd	d
 j durjj jS jr tdnd fdd}jdu rJjrFjdu r;d}nd}t|jj	d}n
j}nfdd}||}jsY|S t
|dkrptdd |D }|j	d k}nd}tj}|dk }|dj	  k |dk@  }	|	s|r|rjdu rd}nd}t|jj	d}||}|S )z
        Returns the float values converted into strings using
        the parameters given at initialisation, as a numpy array
        r~   r<   rM  r   rZ   r[   c                   s<   t | }t fddt|  | D | j}|S )Nc                   s    g | ]\}}|s |nqS rc   rc   )ru   valr  rM  rZ   rc   rd   rw     s    zWFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_rep.<locals>.<listcomp>)r*   r  arrayr/  ravelreshaper  )r~   rM  rZ   mask	formattedrc   r  rd   format_with_na_rep  s   zCFloatArrayFormatter.get_result_as_array.<locals>.format_with_na_repc                 S  s   t |  }t |  }t|t|}}g }t|  ||||D ]R\}}	}
}}|s6|s6||| q#|sF|||	 d| d q#|sj||
 }|dr^|| | d q#|| d| d q#|| d| d q#t 	|
| jS )N+j-)r  realr  imagr*   r/  r|   rs   
startswithr  r  r  )r~   rM  rZ   Zreal_valuesZimag_valuesZ	real_maskZ	imag_maskZformatted_lstr  Zreal_valZimag_valZre_isnaZim_isnaZimag_formattedrc   rc   rd   format_complex_with_na_rep  s,   
zKFloatArrayFormatter.get_result_as_array.<locals>.format_complex_with_na_repNzdisplay.chop_thresholdc                   s    | }jdkrdj nj}j}t|}|r# |||}n|||}jrB|r5t|j}nt|j}t	j
|ddS |S )NrJ   rR  objectr   )r  rM   rZ   r~   r!   r  _trim_zeros_complexr   _trim_zeros_floatr  asarray)rn   rM  rZ   r~   Z
is_complexr   r  r  rb   r  rc   rd   format_values_with  s   zCFloatArrayFormatter.get_result_as_array.<locals>.format_values_withTz{value: .{digits:d}f}z{value:.{digits:d}f})r  c                   s
    j |  S r   )rn   r  rq   rc   rd   r  &  s   
 z9FloatArrayFormatter.get_result_as_array.<locals>.<lambda>r   c                 s      | ]}t |V  qd S r   r   r   rc   rc   rd   r   2      z:FloatArrayFormatter.get_result_as_array.<locals>.<genexpr>   Fg    .A
   z{value: .{digits:d}e}z{value:.{digits:d}e})r~   r<   rM  r   rZ   r[   )rM  r~   rZ   r  r   rn   r   r   r   r  ri   rJ  r  r  r   )
rb   r  Zfmt_strrn   Zformatted_valuesmaxlenZtoo_longZabs_valsZhas_large_valuesZhas_small_valuesrc   r  rd   get_result_as_array  sB   







z'FloatArrayFormatter.get_result_as_arrayrm   c                 C  s   t |  S r   )r<  r  rq   rc   rc   rd   r  H  s   z#FloatArrayFormatter._format_stringsr   NN)rn   r   r  r  r]   r   )r]   r  r   )r   r   r   re   r  r  r  r   rc   rc   r   rd   r    s    
8 r  c                   @     e Zd ZdddZdS )r  r]   rm   c                   s>   | j du r
dd }ndd }| jp|  fdd| jD }|S )NFc                 S     | dj | dS )Nr  rX  r   rX  rc   rc   rd   r  O      z3IntArrayFormatter._format_strings.<locals>.<lambda>c                 S  r  )Nz drX  r  rX  rc   rc   rd   r  Q  r  c                      g | ]} |qS rc   rc   r   rM  rc   rd   rw   S  rx   z5IntArrayFormatter._format_strings.<locals>.<listcomp>)r   rM  r~   )rb   Zformatter_strr}   rc   r  rd   r  M  s   


z!IntArrayFormatter._format_stringsNr   r   r   r   r  rc   rc   rc   rd   r  L      r  c                      s.   e Zd Z		dd fd
dZdddZ  ZS )r  r   Nr~   3np.ndarray | Series | DatetimeIndex | DatetimeArraynat_repr[   r  r^   r]   c                   $   t  j|fi | || _|| _d S r   )r   re   r  r  )rb   r~   r  r  r   r   rc   rd   re   X     
zDatetime64Formatter.__init__rm   c                   sZ    j }t|tst|} jdurt jr fdd|D S |jj j jd}|	 S )z&we by definition have DO NOT have a TZNc                   s   g | ]}  |qS rc   r  r   rq   rc   rd   rw   k  rW  z7Datetime64Formatter._format_strings.<locals>.<listcomp>)rZ   r  )
r~   r   r6   rM  r  _dataZ_format_native_typesr  r  tolist)rb   r~   r}   rc   rq   rd   r  c  s   
z#Datetime64Formatter._format_stringsr   N)r~   r  r  r[   r  r^   r]   r^   r   r   r   r   re   r  r   rc   rc   r   rd   r  W  
    r  c                   @  r  )r  r]   rm   c                 C  s|   t | jdd}| j}d }|d u r|jdd}t|tr | }nt|}t	||| j
| j| j| j| j| j| j| j|d}|S )NTr  )Zboxed)	rn   rZ   r  r   rM   r   r   ra   r  )r1   r~   rM  
_formatterr   r,   rp   r  r  ro   rn   rZ   r  r   rM   r   r   ra   )rb   r~   rM  r  r  r}   rc   rc   rd   r  t  s,   


z'ExtensionArrayFormatter._format_stringsNr   r  rc   rc   rc   rd   r  s  r  r  percentilesnp.ndarray | Sequence[float]c                 C  s@  t | } t| rt | dkrt | dkstdd|  } |  t}t || }t |r=|t	}dd |D S t 
| }|d dkrL|d nd}|d dk rZd|d  nd}t t t t j|||d	t }td|}t j| td
}| |  tt	||< | |  |t	|| < dd |D S )a  
    Outputs rounded and formatted percentiles.

    Parameters
    ----------
    percentiles : list-like, containing floats from interval [0,1]

    Returns
    -------
    formatted : list of strings

    Notes
    -----
    Rounding precision is chosen so that: (1) if any two elements of
    ``percentiles`` differ, they remain different after rounding
    (2) no entry is *rounded* to 0% or 100%.
    Any non-integer is always rounded to at least 1 decimal place.

    Examples
    --------
    Keeps all entries different after rounding:

    >>> format_percentiles([0.01999, 0.02001, 0.5, 0.666666, 0.9999])
    ['1.999%', '2.001%', '50%', '66.667%', '99.99%']

    No element is rounded to 0% or 100% (unless already equal to it).
    Duplicates are allowed:

    >>> format_percentiles([0, 0.5, 0.02001, 0.5, 0.666666, 0.9999])
    ['0%', '50%', '2.0%', '50%', '66.67%', '99.99%']
    r   r   z/percentiles should all be in the interval [0,1]d   c                 S     g | ]}|d  qS %rc   rt   rc   rc   rd   rw     rx   z&format_percentiles.<locals>.<listcomp>N)to_beginto_endr  c                 S  r   r  rc   rt   rc   rc   rd   rw     rx   )r  r  r%   r  r'  roundastyper   iscloser[   uniquefloorlog10r   Zediff1drJ  Z
empty_liker  )r  Zpercentiles_round_typeZint_idxoutZunique_pctsr  r  precrc   rc   rd   format_percentiles  s6   
"



r  2np.ndarray | DatetimeArray | Index | DatetimeIndexrY   c                 C  s~   t | ts	|  } t | ttfst| } | jd urdS | j}|tk}t| j	}t
|}t||| dk dk}|r=dS dS )NFr   T)r   r2   r  r-   r6   tzZasi8r   r   r   r   r  logical_andr   )r~   
values_intconsider_valuesZresoZppd	even_daysrc   rc   rd   is_dates_only  s   


r  r   r   NaTType | Timestampr  c                 C  s   | t u r|S t| S r   )r   r[   )r   r  rc   rc   rd   _format_datetime64  s   r  r  c                 C  s"   t | tr|S |r| |S | jS r   )r   r    strftimeZ
_date_repr)r   r  r  rc   rc   rd   _format_datetime64_dateonly  s
   

r  is_dates_only_r   c                   s   | r	 fddS fddS )z]Return a formatter callable taking a datetime64 as input and providing
    a string as outputc                   s   t |  dS )N)r  r  )r  rX  r  r  rc   rd   r    s    z'get_format_datetime64.<locals>.<lambda>c                   s   t |  dS )Nr  )r  rX  r  rc   rd   r    s    rc   )r  r  r  rc   r  rd   get_format_datetime64  s   r  *np.ndarray | DatetimeArray | DatetimeIndexc                 C  s6   t | tjr| jdkr|  } t| }|r|pdS |S )z6given values and a date_format, return a string formatr   z%Y-%m-%d)r   r  r  ndimr  r  )r~   r  idorc   rc   rd   !get_format_datetime64_from_values  s   r!  c                   @  r  )r  r]   rm   c                   s@   t | j}| jt}| jpt|| jd  fdd|D }|S )zwe by definition have a TZ)r  c                   r  rc   rc   r   r  rc   rd   rw   .  rx   z9Datetime64TZFormatter._format_strings.<locals>.<listcomp>)r  r~   r  r  rM  r  r  )rb   r   r~   r}   rc   r  rd   r  '  s   
z%Datetime64TZFormatter._format_stringsNr   r  rc   rc   rc   rd   r  &  r  r  c                      s.   e Zd Z		dd fddZdddZ  ZS )r  r   Fr~   np.ndarray | TimedeltaIndexr  r[   boxrY   r]   r^   c                   r  r   )r   re   r  r#  )rb   r~   r  r#  r   r   rc   rd   re   4  r  zTimedelta64Formatter.__init__rm   c                   s.   | j pt| j| j| jd  fdd| jD S )N)r  r#  c                   r  rc   rc   r   r  rc   rd   rw   C  rx   z8Timedelta64Formatter._format_strings.<locals>.<listcomp>)rM  get_format_timedelta64r~   r  r#  rq   rc   r  rd   r  ?  s   z$Timedelta64Formatter._format_stringsr   F)r~   r"  r  r[   r#  rY   r]   r^   r   r  rc   rc   r   rd   r  3  r  r  F,np.ndarray | TimedeltaIndex | TimedeltaArraystr | floatr#  c           
        s^   |  tj}|tk}d}|| dk}t||}| dk}|r#dnd fdd}	|	S )z
    Return a formatter function for a range of timedeltas.
    These will all have the same format argument

    If box, then show the return in quotes
    l     "R: r   Nlongc                   sN   | d u st | rt| rS t| tst| } | jd} r%d| d}|S )Nr  ')r&   r*   r   r   Z
_repr_base)r   r   r#  r   r  rc   rd   r  e  s   
z*get_format_timedelta64.<locals>._formatter)viewr  Zint64r   r  r   )
r~   r  r#  r  r  Zone_day_nanosZnot_midnightZbothr  r  rc   r*  rd   r$  F  s   r$  r@  rA  r   TextAdjustment | Nonec                   s   t | dks
|dkr| S |d u rt  n| t fdd| D |d ur*t|tdd ur8kr8d fd	d
fdd| D }  j| |d}|S )Nr   r  c                 3  s    | ]}  |V  qd S r   r   r   )
adjustmentrc   rd   r         z$_make_fixed_width.<locals>.<genexpr>r   r   r[   r]   c                   s6   d urdk  | k@ r| d d  d } | S )Nr   r   r   rX  )r-  conf_maxr   rc   rd   just  s   z_make_fixed_width.<locals>.justc                   r  rc   rc   r   )r0  rc   rd   rw     rx   z%_make_fixed_width.<locals>.<listcomp>r   )r   r[   r]   r[   )ri   r   rJ  r   rM   )r@  rM   rA  r   r   rc   )r-  r/  r0  r   rd   rH  u  s   
rH  str_complexesr  c           	        s   g g }}| D ] }t d|}|d|dd  |d|dd  qt| }t|| |}t|dkr;g S tdd |D d	   fd
dt|d| ||d D }|S )z
    Separates the real and imaginary parts from the complex number, and
    executes the _trim_zeros_float method on each of those.
    z([j+-])r`   Nr   c                 s  r  r   r   )ru   partrc   rc   rd   r     r  z&_trim_zeros_complex.<locals>.<genexpr>r   c                   s6   g | ]\}}||d   |dd d   d qS )r   r   N>r  rc   )ru   Zreal_ptZimag_ptZpadded_lengthrc   rd   rw     s    z'_trim_zeros_complex.<locals>.<listcomp>)rerc  r|   r{   ri   r  rJ  r/  )	r1  r   Z	real_partZ	imag_partr   trimmednZpadded_partspaddedrc   r6  rd   r    s   

r  	str_floatc                 C  s    |  d} | dr| d7 } | S )zX
    Trims trailing zeros after a decimal point,
    leaving just one if necessary.
    0r   )rstripendswith)r;  rc   rc   rd   r    s   

r  
str_floatsnp.ndarray | list[str]c                   sl   | }t d  ddfdddfd	d
}||r*fdd|D }||s fdd|D }|S )z
    Trims the maximum number of trailing zeros equally from
    all numbers containing decimals, leaving just one if
    necessary.
    z^\s*[\+-]?[0-9]+\z[0-9]*$r]   rY   c                   s   t  | d uS r   )r7  matchrX  )number_regexrc   rd   is_number_with_decimal  r   z1_trim_zeros_float.<locals>.is_number_with_decimalr~   r@  c                   s0    fdd| D }t |dkotdd |D S )z
        Determine if an array of strings should be trimmed.

        Returns True if all numbers containing decimals (defined by the
        above regular expression) within the array end in a zero, otherwise
        returns False.
        c                   s   g | ]} |r|qS rc   rc   r   rC  rc   rd   rw     s    z:_trim_zeros_float.<locals>.should_trim.<locals>.<listcomp>r   c                 s  s    | ]}| d V  qdS )r<  Nr>  r   rc   rc   rd   r     r.  z9_trim_zeros_float.<locals>.should_trim.<locals>.<genexpr>)ri   r  )r~   numbersrD  rc   rd   should_trim  s   z&_trim_zeros_float.<locals>.should_trimc                   s$   g | ]} |r|d d n|qS )Nr  rc   r   rD  rc   rd   rw     s   $ z%_trim_zeros_float.<locals>.<listcomp>c                   s*   g | ]}|r|  r|d  n|qS )r<  rE  r   )r   rC  rc   rd   rw     s    Nrh  )r~   r@  r]   rY   )r7  compile)r?  r   r8  rG  r   rc   )r   rC  rB  rd   r    s   r  r   r2   c                 C  s    t | trtj| j S | jd uS r   )r   r3   comZany_not_noner   r   )r   rc   rc   rd   r    s   

r  c                   @  s   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	%d3d4d,d-Zd5d1d2Zd$S )6EngFormatterzl
    Formats float values according to engineering format.

    Based on matplotlib.ticker.EngFormatter
    irS  iziair  ipir9  iur  r   r`   r   r]  r  r  	   Gr  T   P   E   Z   YNFaccuracyr   use_eng_prefixrY   r]   r^   c                 C  s   || _ || _d S r   r[  r\  )rb   r[  r\  rc   rc   rd   re     s   
zEngFormatter.__init__numfloatr[   c           
      C  s  t t|}t |rdS t |rdS d}|dk rd}| }|dkr3t tt| d d }nt d}|t	| j
 }|	t| j
 }t|}| jrX| j
| }n|dk rdd| d}nd	|d}|| d
|  }| jdu rzd}nd| jdd}|j||d}	|	S )a  
        Formats a number in engineering notation, appending a letter
        representing the power of 1000 of the original number. Some examples:
        >>> format_eng = EngFormatter(accuracy=0, use_eng_prefix=True)
        >>> format_eng(0)
        ' 0'
        >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix=True)
        >>> format_eng(1_000_000)
        ' 1.0M'
        >>> format_eng = EngFormatter(accuracy=2, use_eng_prefix=False)
        >>> format_eng("-1e-6")
        '-1.00E-06'

        @param num: the value to represent
        @type num: either a numeric value or a string that can be converted to
                   a numeric value (as per decimal.Decimal constructor)

        @return: engineering formatted string
        rT   infr   r   r  r   zE-02dzE+r  Nz{mant: g}{prefix}z{mant: .r  z
f}{prefix})mantprefix)r   r[   is_nanis_infiniter   mathr
  r  r   rJ  ENG_PREFIXESr.  r\  r[  r   )
rb   r^  ZdnumsignZpow10Z	int_pow10rc  rb  
format_strr  rc   rc   rd   __call__  s4   

 
zEngFormatter.__call__r  )r[  r   r\  rY   r]   r^   )r^  r_  r]   r[   )r   r   r   ri  rg  re   rj  rc   rc   rc   rd   rJ    sP    	
rJ  r   r[  r   r\  r^   c                 C  s   t dt| | dS )a  
    Format float representation in DataFrame with SI notation.

    Parameters
    ----------
    accuracy : int, default 3
        Number of decimal digits after the floating point.
    use_eng_prefix : bool, default False
        Whether to represent a value with SI prefixes.

    Returns
    -------
    None

    Examples
    --------
    >>> df = pd.DataFrame([1e-9, 1e-3, 1, 1e3, 1e6])
    >>> df
                  0
    0  1.000000e-09
    1  1.000000e-03
    2  1.000000e+00
    3  1.000000e+03
    4  1.000000e+06

    >>> pd.set_eng_float_format(accuracy=1)
    >>> df
             0
    0  1.0E-09
    1  1.0E-03
    2  1.0E+00
    3  1.0E+03
    4  1.0E+06

    >>> pd.set_eng_float_format(use_eng_prefix=True)
    >>> df
            0
    0  1.000n
    1  1.000m
    2   1.000
    3  1.000k
    4  1.000M

    >>> pd.set_eng_float_format(accuracy=1, use_eng_prefix=True)
    >>> df
          0
    0  1.0n
    1  1.0m
    2   1.0
    3  1.0k
    4  1.0M

    >>> pd.set_option("display.float_format", None)  # unset option
    r   N)r   rJ  r]  rc   rc   rd   set_eng_float_formatO  s   7rk  r`   r[  sentinelbool | object | strlist[dict[int, int]]c           	      C  s   t | dkrg S dgt | d  }g }| D ]1}d}i }t|D ]\}}|| r,||kr,qd||< || ||< |}qt || ||< || q|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   rF  r|   )	r[  rl  controlr   rQ  Z
last_indexlengthsrv   keyrc   rc   rd   get_level_lengths  s    rr  WriteBuffer[str]linesc                 C  s4   t dd |D rdd |D }| d| dS )z
    Appends lines to a buffer.

    Parameters
    ----------
    buf
        The buffer to write to
    lines
        The lines to append.
    c                 s  s    | ]}t |tV  qd S r   )r   r[   r   rc   rc   rd   r     r.  z#buffer_put_lines.<locals>.<genexpr>c                 S  rY  rc   ra  r   rc   rc   rd   rw     rx   z$buffer_put_lines.<locals>.<listcomp>rh   N)r   r  r{   )rV   rt  rc   rc   rd   buffer_put_lines  s   ru  )r]   r   )r]   r   r  )rx  r[   rV   rl  r   r   r]   r   r   )rV   rl  r   r   r]   r  )	NrT   NNrK   r   TNN)r~   r   rM  rO  rn   r   rZ   r[   r  r   r   r  rM   r[   r   r[   r   r   ra   r   r  rO  r]   rm   )r  r  r]   rm   )r~   r  r]   rY   )r   )r   r  r  r[   r]   r[   r  )r   r  r  r[   r  r   r]   r[   )r  rY   r  r[   r  r   r]   r   )r~   r  r  r   r]   r   r%  )r~   r&  r  r'  r#  rY   r]   r   )rK   NN)
r@  rm   rM   r[   rA  r   r   r,  r]   rm   )r   )r1  r  r   r[   r]   rm   )r;  r[   r]   r[   )r?  r@  r   r[   r]   rm   )r   r2   r]   rY   )r   F)r[  r   r\  rY   r]   r^   )r`   )r[  r   rl  rm  r]   rn  )rV   rs  rt  rm   r]   r^   )ri  
__future__r   collections.abcr   r   r   r   r   
contextlibr   csvr	   r
   r   r   	functoolsr   ior   rf  r7  shutilr   typingr   r   r   r   r   r   unicodedatar   numpyr  Zpandas._config.configr   r   Zpandas._libsr   Zpandas._libs.missingr   Zpandas._libs.tslibsr   r   r   r   r   r   Zpandas._libs.tslibs.nattyper    Zpandas.core.dtypes.commonr!   r"   r#   r$   r%   r&   Zpandas.core.dtypes.dtypesr'   r(   r)   Zpandas.core.dtypes.missingr*   r+   Zpandas.core.arraysr,   r-   r.   Zpandas.core.arrays.string_r/   Zpandas.core.baser0   Zpandas.core.commoncorecommonrI  Zpandas.core.constructionr1   Zpandas.core.indexes.apir2   r3   r4   r5   Zpandas.core.indexes.datetimesr6   Zpandas.core.indexes.timedeltasr7   Zpandas.core.reshape.concatr8   Zpandas.io.commonr9   r:   r   r;   Zpandas._typingr<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   ZpandasrG   rH   rI   __annotations__Z_VALID_JUSTIFY_PARAMETERSrR   rS   r   r   r   r   r   r   r   rk  rw  r  ro   r  r  r  r  r  r  r  r  r  r  r!  r  r  r$  rH  r  r  r  r  rJ  rk  rr  ru  rc   rc   rc   rd   <module>   s       4;	@ !
'

!&   C  (Rp J

E
1"
!
$`;+