U
    ¾mœdè  ã                   @  s\  d Z ddlmZ ddlmZmZ ddlZddlZddlm	Z	m
Z
mZmZmZmZmZ ddlZddl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mZm Z  ddl!m"Z"m#Z#m$Z$m%Z% ddl&m'  m(Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4 G dd„ dƒZ5G dd„ de5ƒZ6G dd„ dƒZ7G dd„ dƒZ8dS )zC
Utilities for conversion to writer-agnostic Excel representation.
é    )Úannotations)Ú	lru_cacheÚreduceN)ÚAnyÚCallableÚHashableÚIterableÚMappingÚSequenceÚcast)Úis_list_like)Ú
IndexLabelÚStorageOptions)Údoc)Úfind_stack_level)Úmissing)Úis_floatÚ	is_scalar)Ú	DataFrameÚIndexÚ
MultiIndexÚPeriodIndex)Ú_shared_docs)ÚCSS4_COLORS)ÚCSSResolverÚ
CSSWarning)Úget_level_lengths)Úpprint_thingc                   @  s,   e Zd ZdZeZd	ddddddœdd„ZdS )
Ú	ExcelCell©ÚrowÚcolÚvalÚstyleÚ
mergestartÚmergeendNÚintú
int | NoneÚNone)r    r!   r$   r%   Úreturnc                 C  s(   || _ || _|| _|| _|| _|| _d S ©Nr   )Úselfr    r!   r"   r#   r$   r%   © r,   úP/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/pandas/io/formats/excel.pyÚ__init__=   s    	zExcelCell.__init__)NNN)Ú__name__Ú
__module__Ú__qualname__Z
__fields__Ú	__slots__r.   r,   r,   r,   r-   r   9   s      ùr   c                	      s0   e Zd Zdddddddddœ‡ fdd„Z‡  ZS )	ÚCssExcelCellr&   zdict | Nonez3dict[tuple[int, int], list[tuple[str, Any]]] | NoneúCallable | Noner(   )r    r!   r#   Ú
css_stylesÚcss_rowÚcss_colÚcss_converterr)   c	                   sR   |r2|r2dd„ |||f D ƒ}
t |
 ¡ ƒ}||ƒ}tƒ jf ||||dœ|	—Ž d S )Nc                 S  s   i | ]\}}|  ¡ |“qS r,   ©Úlower)Ú.0Úpropr"   r,   r,   r-   Ú
<dictcomp>]   s     z)CssExcelCell.__init__.<locals>.<dictcomp>©r    r!   r"   r#   )Ú	frozensetÚitemsÚsuperr.   )r+   r    r!   r"   r#   r5   r6   r7   r8   ÚkwargsZdeclaration_dictZunique_declarations©Ú	__class__r,   r-   r.   O   s    
ÿzCssExcelCell.__init__)r/   r0   r1   r.   Ú__classcell__r,   r,   rC   r-   r3   N   s   r3   c                   @  s.  e Zd ZU dZeZdddddddœZddddddddddddddœZdddd	œZd
ddddœZ	dd„ dD ƒZ
ded< dgdddœdd„Zeƒ Zdddœdd„Zdddœdd „Zd!dd"œd#d$„Zd!d%d"œd&d'„Zd!dd"œd(d)„Zd!d*d"œd+d,„Zd!d-d"œd.d/„Zdddd0œd1d2„Zddd3œd4d5„Zdd6d7œd8d9„Zd:d6d;œd<d=„Zd!d>œd?d@„Zd!dAd"œdBdC„Zd!dDd"œdEdF„Zd!d*d"œdGdH„Zd!d*d"œdIdJ„Zd!dKd"œdLdM„ZdKddNœdOdP„Z d!d*d"œdQdR„Z!d!dKd"œdSdT„Z"d!dUd"œdVdW„Z#dXdYœdZd[„Z$ddd\œd]d^„Z%d:d_d`œdadb„Z&d:d:d`œdcdd„Z'd:d_d`œdedf„Z(dS )hÚCSSToExcelConverteraK  
    A callable for converting CSS declarations to ExcelWriter styles

    Supports parts of CSS 2.2, with minimal CSS 3.0 support (e.g. text-shadow),
    focusing on font styling, backgrounds, borders and alignment.

    Operates by first computing CSS styles in a fairly generic
    way (see :meth:`compute_css`) then determining Excel style
    properties from CSS properties (see :meth:`build_xlstyle`).

    Parameters
    ----------
    inherited : str, optional
        CSS declarations understood to be the containing scope for the
        CSS processed by :meth:`__call__`.
    ÚtopÚcenterÚbottom)rG   ztext-topÚmiddleZbaselinerI   ztext-bottomTF)ÚboldZbolderZ600Z700Z800Z900ÚnormalZlighterÚ100Z200Z300Z400Ú500)rL   ÚitalicZobliqueé   é   é   é   )Zserifz
sans-serifZcursiveZfantasyc                 C  s   i | ]}|  ¡ |“qS r,   r9   )r;   r#   r,   r,   r-   r=   ¢   s   ÿ zCSSToExcelConverter.<dictcomp>)
ÚdashedZmediumDashDotZ
dashDotDotÚhairÚdottedÚmediumDashDotDotÚdoubleZdashDotZslantDashDotÚmediumDashedzdict[str, str] | NoneÚ	inheritedNú
str | Noner(   )rZ   r)   c                 C  s2   |d k	r|   |¡| _nd | _td d�| jƒ| _d S )N)Úmaxsize)Úcompute_cssrZ   r   Ú_call_uncachedÚ_call_cached)r+   rZ   r,   r,   r-   r.   ¸   s    zCSSToExcelConverter.__init__z str | frozenset[tuple[str, str]]zdict[str, dict[str, str]])Údeclarationsr)   c                 C  s
   |   |¡S )aå  
        Convert CSS declarations to ExcelWriter style.

        Parameters
        ----------
        declarations : str | frozenset[tuple[str, str]]
            CSS string or set of CSS declaration tuples.
            e.g. "font-weight: bold; background: blue" or
            {("font-weight", "bold"), ("background", "blue")}

        Returns
        -------
        xlstyle : dict
            A style as interpreted by ExcelWriter when found in
            ExcelCell.style.
        )r_   )r+   r`   r,   r,   r-   Ú__call__Ä   s    zCSSToExcelConverter.__call__c                 C  s   |   || j¡}|  |¡S r*   )r]   rZ   Úbuild_xlstyle)r+   r`   Ú
propertiesr,   r,   r-   r^   Ù   s    z"CSSToExcelConverter._call_uncachedzMapping[str, str])Úpropsr)   c                   sN   |   |¡|  |¡|  |¡|  |¡|  |¡dœ}dddœ‡ fdd„‰ ˆ |ƒ |S )N)Ú	alignmentÚborderÚfillÚfontZnumber_formatúdict[str, str | None]r(   )Údr)   c                   sF   t |  ¡ ƒD ]4\}}|dkr$| |= qt|tƒrˆ |ƒ |s| |= qdS )z4Remove key where value is None, through nested dictsN)Úlistr@   Ú
isinstanceÚdict)rj   ÚkÚv©Úremove_noner,   r-   rq   ê   s    
z6CSSToExcelConverter.build_xlstyle.<locals>.remove_none)Úbuild_alignmentÚbuild_borderÚ
build_fillÚ
build_fontÚbuild_number_format)r+   rd   Úoutr,   rp   r-   rb   ß   s    û

z!CSSToExcelConverter.build_xlstylezdict[str, bool | str | None]c                 C  s   |  d¡|  |¡|  |¡dœS )Nz
text-align)Ú
horizontalÚverticalÚ	wrap_text)ÚgetÚ_get_vertical_alignmentÚ_get_is_wrap_text©r+   rd   r,   r,   r-   rr   ÷   s    ýz#CSSToExcelConverter.build_alignmentc                 C  s   |  d¡}|r| j  |¡S d S )Nzvertical-align)r{   ÚVERTICAL_MAP)r+   rd   Zvertical_alignr,   r,   r-   r|   ÿ   s    
z+CSSToExcelConverter._get_vertical_alignmentzbool | Nonec                 C  s"   |  d¡d krd S t|d dkƒS )Nzwhite-space)ZnowrapÚprezpre-line)r{   Úboolr~   r,   r,   r-   r}     s    z%CSSToExcelConverter._get_is_wrap_textz dict[str, dict[str, str | None]]c                   s   ‡ ‡fdd„dD ƒS )Nc                   sf   i | ]^}|ˆ  ˆ  d |› d�¡ˆ  d |› d�¡ˆ ˆ  d |› d�¡¡¡ˆ ˆ  d |› d�¡¡dœ“qS )zborder-z-stylez-widthz-color)r#   Úcolor)Ú_border_styler{   Úcolor_to_excel)r;   Zside©rd   r+   r,   r-   r=     s   	øýúz4CSSToExcelConverter.build_border.<locals>.<dictcomp>©rG   ÚrightrI   Úleftr,   r~   r,   r…   r-   rs   
  s    	÷z CSSToExcelConverter.build_border)r#   Úwidthr‚   c                 C  sÒ   |d kr|d kr|d krd S |d kr0|d kr0dS |dkr<dS |   |¡}|d krRdS |dkr^|S |dkrjdS |dkr‚|dkr~dS dS |dkrš|dkr–dS d	S || jkr®| j| S tjd
t|ƒ› �ttƒ d� dS d S )NÚnone)rŠ   Zhidden)NZgrooveZridgeZinsetZoutsetÚsolidrX   rV   )rU   ÚthinrW   rT   rY   zUnhandled border style format: ©Ú
stacklevel)Ú_get_width_nameÚBORDER_STYLE_MAPÚwarningsÚwarnÚreprr   r   )r+   r#   r‰   r‚   Z
width_namer,   r,   r-   rƒ     s:    


ýz!CSSToExcelConverter._border_style)Úwidth_inputr)   c                 C  s2   |   |¡}|dk rd S |dk r"dS |dk r.dS dS )Ngñhãˆµøä>gÍÌÌÌÌÌô?rŒ   gffffff@ZmediumZthick)Ú_width_to_float)r+   r”   r‰   r,   r,   r-   r�   P  s    
z#CSSToExcelConverter._get_width_nameÚfloat)r‰   r)   c                 C  s   |d krd}|   |¡S )NZ2pt)Ú_pt_to_float)r+   r‰   r,   r,   r-   r•   Z  s    z#CSSToExcelConverter._width_to_floatÚstr)Ú	pt_stringr)   c                 C  s   |  d¡st‚t| d¡ƒS )NÚpt)ÚendswithÚAssertionErrorr–   Úrstrip)r+   r™   r,   r,   r-   r—   _  s    z CSSToExcelConverter._pt_to_float)rd   c                 C  s&   |  d¡}|dkr"|  |¡ddœS d S )Nzbackground-color)NÚtransparentrŠ   r‹   )ZfgColorZpatternType)r{   r„   )r+   rd   Z
fill_colorr,   r,   r-   rt   c  s    
zCSSToExcelConverter.build_fillri   c                 C  s,   |  d¡}t|tƒr | dd¡n|}d|iS )Nznumber-formatõ   Â§ú;Zformat_code)r{   rl   r˜   Úreplace)r+   rd   Úfcr,   r,   r-   rv   j  s    
z'CSSToExcelConverter.build_number_formatz$dict[str, bool | float | str | None]c                 C  sv   |   |¡}|  |¡}|r |d nd |  |¡|  |¡|  |¡|  |¡d|krNdnd d|kpZd |  | d¡¡|  |¡dœ	S )Nr   Ú	underlineÚsinglezline-throughr‚   )	ÚnameÚfamilyÚsizerK   rO   r£   Ústriker‚   Zshadow)	Ú_get_font_namesÚ_get_decorationÚ_select_font_familyÚ_get_font_sizeÚ_get_is_boldÚ_get_is_italicr„   r{   Ú_get_shadow)r+   rd   Ú
font_namesÚ
decorationr,   r,   r-   ru   o  s    


özCSSToExcelConverter.build_fontc                 C  s   |  d¡}|r| j  |¡S d S )Nzfont-weight)r{   ÚBOLD_MAP)r+   rd   Úweightr,   r,   r-   r­   �  s    
z CSSToExcelConverter._get_is_boldc                 C  s   |  d¡}|r| j  |¡S d S )Nz
font-style)r{   Ú
ITALIC_MAP)r+   rd   Z
font_styler,   r,   r-   r®   ‡  s    
z"CSSToExcelConverter._get_is_italiczSequence[str]c                 C  s"   |  d¡}|d k	r| ¡ S dS d S )Nztext-decorationr,   )r{   Úsplit)r+   rd   r±   r,   r,   r-   rª   �  s    
z#CSSToExcelConverter._get_decoration)r±   r)   c                 C  s   d|krdS d S )Nr£   r¤   r,   )r+   r±   r,   r,   r-   Ú_get_underline”  s    z"CSSToExcelConverter._get_underlinec                 C  s    d|krt t d|d ¡ƒS d S )Nztext-shadowz^[^#(]*[1-9])r�   ÚreÚsearchr~   r,   r,   r-   r¯   ™  s    zCSSToExcelConverter._get_shadowc                 C  sˆ   t  d| dd¡¡}g }|D ]f}|d d… dkrF|dd…  dd¡}n.|d d… dkrl|dd…  d	d¡}n| ¡ }|r| |¡ q|S )
Nz›(?x)
            (
            "(?:[^"]|\\")+"
            |
            '(?:[^']|\\')+'
            |
            [^'",]+
            )(?=,|\s*$)
        zfont-familyÚ rP   ú"éÿÿÿÿz\"ú'z\')r·   Úfindallr{   r¡   ÚstripÚappend)r+   rd   Zfont_names_tmpr°   r¥   r,   r,   r-   r©   ž  s    	
öz#CSSToExcelConverter._get_font_nameszfloat | Nonec                 C  s    |  d¡}|d kr|S |  |¡S )Nz	font-size)r{   r—   )r+   rd   r§   r,   r,   r-   r¬   ¸  s    
z"CSSToExcelConverter._get_font_sizer'   ©r)   c                 C  s&   d }|D ]}| j  |¡}|r q"q|S r*   )Ú
FAMILY_MAPr{   )r+   r°   r¦   r¥   r,   r,   r-   r«   ¾  s    z'CSSToExcelConverter._select_font_family)r"   r)   c                 C  sb   |d krd S |   |¡r |  |¡S z| j| W S  tk
r\   tjdt|ƒ› �ttƒ d� Y nX d S )NzUnhandled color format: r�   )	Ú_is_hex_colorÚ_convert_hex_to_excelÚNAMED_COLORSÚKeyErrorr‘   r’   r“   r   r   ©r+   r"   r,   r,   r-   r„   Ç  s    

ýz"CSSToExcelConverter.color_to_excelr�   )Úcolor_stringr)   c                 C  s   t | d¡ƒS )Nú#)r�   Ú
startswith)r+   rÇ   r,   r,   r-   rÂ   Ø  s    z!CSSToExcelConverter._is_hex_colorc                 C  sH   |  d¡}|  |¡r<|d d |d d  |d d   ¡ S | ¡ S d S )NrÈ   r   rQ   rP   )ÚlstripÚ_is_shorthand_colorÚupper©r+   rÇ   Úcoder,   r,   r-   rÃ   Û  s    

(z)CSSToExcelConverter._convert_hex_to_excelc                 C  s<   |  d¡}t|ƒdkrdS t|ƒdkr*dS td|› �ƒ‚dS )zcCheck if color code is shorthand.

        #FFF is a shorthand as opposed to full #FFFFFF.
        rÈ   é   Té   FzUnexpected color N)rÊ   ÚlenÚ
ValueErrorrÍ   r,   r,   r-   rË   â  s    
z'CSSToExcelConverter._is_shorthand_color)N))r/   r0   r1   Ú__doc__r   rÄ   r   r²   r´   rÁ   r�   Ú__annotations__r.   r   r]   ra   r^   rb   rr   r|   r}   rs   rƒ   r�   r•   r—   rt   rv   ru   r­   r®   rª   r¶   r¯   r©   r¬   r«   r„   rÂ   rÃ   rË   r,   r,   r,   r-   rF   g   s€   
úóýüþ
7
	rF   c                   @  s  e Zd ZdZdZdZd8d	d
dddddd	dddœ
dd„Zeddœdd„ƒZdd„ Z	ddœdd„Z
ddœdd„Zddœdd „Zddœd!d"„Zddœd#d$„Zddœd%d&„Zeddœd'd(„ƒZd)dd*œd+d,„Zddœd-d.„Zeed/ d0�d9d	d)d)d3d
d4dd5œd6d7„ƒZdS ):ÚExcelFormattera9  
    Class for formatting a DataFrame to a list of ExcelCells,

    Parameters
    ----------
    df : DataFrame or Styler
    na_rep: na representation
    float_format : str, default None
        Format string for floating point numbers
    cols : sequence, optional
        Columns to write
    header : bool or sequence of str, default True
        Write out column names. If a list of string is given it is
        assumed to be aliases for the column names
    index : bool, default True
        output row names (index)
    index_label : str or sequence, default None
        Column label for index column(s) if desired. If None is given, and
        `header` and `index` are True, then the index names are used. A
        sequence should be given if the DataFrame uses MultiIndex.
    merge_cells : bool, default False
        Format MultiIndex and Hierarchical Rows as merged cells.
    inf_rep : str, default `'inf'`
        representation for np.inf values (which aren't representable in Excel)
        A `'-'` sign will be added in front of -inf.
    style_converter : callable, optional
        This translates Styler styles (CSS) into ExcelWriter styles.
        Defaults to ``CSSToExcelConverter()``.
        It should have signature css_declarations string -> excel style.
        This is only called for body cells.
    i   i @  r¹   NTFÚinfr˜   r[   zSequence[Hashable] | NonezSequence[Hashable] | boolr�   zIndexLabel | Noner4   r(   )
Úna_repÚfloat_formatÚcolsÚheaderÚindexÚindex_labelÚmerge_cellsÚinf_repÚstyle_converterr)   c                 C  sà   d| _ || _t|tƒsB|| _| j ¡  |j}|
d kr:tƒ }
|
| _nd | _d | _|| _	|d k	r®t
t|ƒ |j¡ƒsxtdƒ‚t
t|ƒ |j¡ƒt
t|ƒƒkr tdƒ‚|j|d�| _	| j	j| _|| _|| _|| _|| _|| _|	| _d S )Nr   z,passes columns are not ALL present dataframez.Not all names specified in 'columns' are found)Úcolumns)Ú
rowcounterr×   rl   r   ÚstylerZ_computeÚdatarF   rß   ÚdfrÑ   r   Úintersectionrà   rÅ   ÚsetZreindexrØ   rÛ   rÜ   rÚ   rÝ   rÞ   )r+   rä   r×   rØ   rÙ   rÚ   rÛ   rÜ   rÝ   rÞ   rß   r,   r,   r-   r.     s2    

 
zExcelFormatter.__init__z dict[str, dict[str, str | bool]]rÀ   c                 C  s    ddidddddœdddœdœS )	NrK   TrŒ   r†   rH   rG   )rx   ry   )rh   Zbordersre   r,   ©r+   r,   r,   r-   Úheader_styleA  s    üøzExcelFormatter.header_stylec                 C  s€   t |ƒrt |¡r| j}nJt|ƒrdt |¡r4| j}n0t |¡rLd| j› �}n| jd k	rdt	| j| ƒ}t
|dd ƒd k	r|tdƒ‚|S )Nú-Útzinfoz{Excel does not support datetimes with timezones. Please ensure that datetimes are timezone unaware before writing to Excel.)r   r   Zisnar×   r   Zisposinf_scalarrÞ   Zisneginf_scalarrØ   r–   ÚgetattrrÒ   rÆ   r,   r,   r-   Ú_format_valueN  s    


ÿzExcelFormatter._format_valuezIterable[ExcelCell]c                 c  sª  | j jdkr| jstdƒ‚| js*| js*d S | j }|j| jddd�}t|ƒ}d}d}| jrzt	| j
jtƒrzt| j
jd ƒd }| j�rHt|jƒD ]\}}t|||| jd�V  qŒtt||j|jƒƒD ]†\}\}}}	| |	¡}
| ¡ D ]d\}}d\}}|dk�r
||| |  }}t||| d |
| | jt| jdd ƒ||| j||d	�
V  qÞq¾nXtt|Ž ƒD ]J\}}
d
 tt|
ƒ¡}t||| d || jt| jdd ƒ||| jd�V  �qT|| _d S )NrP   z]Writing to Excel with MultiIndex columns and no index ('index'=False) is not yet implemented.F©ZsparsifyZadjoinÚnamesr   r>   ©NNÚctx_columns©
r    r!   r"   r#   r5   r6   r7   r8   r$   r%   Ú.©r    r!   r"   r#   r5   r6   r7   r8   )rà   ZnlevelsrÛ   ÚNotImplementedErrorÚ_has_aliasesrÚ   ÚformatrÝ   r   rl   rä   r   rÑ   Ú	enumeraterî   r   rè   ÚzipÚlevelsÚcodesÚtaker@   r3   rë   râ   rß   ÚjoinÚmapr   rá   )r+   rà   Ú
level_strsÚlevel_lengthsÚ	coloffsetÚlnumr¥   Úspansrù   Úlevel_codesÚvaluesÚiÚspan_valr$   r%   ro   r,   r,   r-   Ú_format_header_mi`  sv    ÿ  ÿü
ÿ


ö
øz ExcelFormatter._format_header_mic                 c  sÐ   | j s| jrÌd}| jr6d}t| jjtƒr6t| jjjƒ}| j}| j rŒt	t
| jƒ| _t| jƒt| jƒkr†tdt| jƒ› dt| jƒ› d�ƒ‚| j}t|ƒD ]6\}}t| j|| || jt| jdd ƒd|| jd�V  q”d S )Nr   rP   zWriting z cols but got z aliasesrð   ró   )rõ   rÚ   rÛ   rl   rä   r   rÑ   rî   rà   r   r
   rÒ   r÷   r3   rá   rè   rë   râ   rß   )r+   r   ZcolnamesÚcolindexZcolnamer,   r,   r-   Ú_format_header_regular¥  s2    ÿøz%ExcelFormatter._format_header_regularc                   s˜   t ˆ jtƒrˆ  ¡ }nˆ  ¡ }d}ˆ jjjrŒdd„ ˆ jjjD ƒdgtˆ jƒ  }t	dd„ t
dd„ |ƒƒrŒ‡ fdd	„t|ƒD ƒ}ˆ  jd
7  _t ||¡S )Nr,   c                 S  s   g | ]}|d k	r|nd‘qS ©Nr¹   r,   )r;   Úxr,   r,   r-   Ú
<listcomp>Ï  s     z1ExcelFormatter._format_header.<locals>.<listcomp>r¹   c                 S  s   | o|S r*   r,   )r  Úyr,   r,   r-   Ú<lambda>Ò  ó    z/ExcelFormatter._format_header.<locals>.<lambda>c                 S  s   | dkS r
  r,   )r  r,   r,   r-   r  Ò  r  c                 3  s$   | ]\}}t ˆ j||ˆ jƒV  qd S r*   )r   rá   rè   )r;   r  r"   rç   r,   r-   Ú	<genexpr>Ó  s   ÿz0ExcelFormatter._format_header.<locals>.<genexpr>rP   )rl   rà   r   r  r	  rä   rÛ   rî   rÑ   r   rý   r÷   rá   Ú	itertoolsÚchain)r+   ÚgenZgen2r    r,   rç   r-   Ú_format_headerÄ  s     

ÿþ
þzExcelFormatter._format_headerc                 C  s"   t | jjtƒr|  ¡ S |  ¡ S d S r*   )rl   rä   rÛ   r   Ú_format_hierarchical_rowsÚ_format_regular_rowsrç   r,   r,   r-   Ú_format_bodyÚ  s    zExcelFormatter._format_bodyc                 c  s2  | j s| jr|  jd7  _| j�r| jrJt| jtttj	t
fƒrJ| jd }n(| jrdt| jtƒrd| j}n| jjjd }t| jtƒrŒ|  jd7  _|r²| jdk	r²t| jd d|| jƒV  | jj}t| jjtƒrÔ| jj ¡ }t|ƒD ]6\}}t| j| d|| jt| jdd ƒ|d| jd�V  qÜd}nd}|  |¡E d H  d S )NrP   r   FÚ	ctx_indexró   )rõ   rÚ   rá   rÛ   rÜ   rl   rk   ÚtupleÚnpÚndarrayr   r˜   rä   rî   rà   r   r   rè   r   Zto_timestampr÷   r3   rë   râ   rß   Ú_generate_body)r+   rÜ   Zindex_valuesÚidxZidxvalr   r,   r,   r-   r  à  s@     ÿø

z#ExcelFormatter._format_regular_rowsc                 c  sú  | j s| jr|  jd7  _d}| j�ræ| jjj}| jrRt| jtt	t
jtfƒrR| j}t| jtƒrr| jrr|  jd7  _tj|Ž r°| jdk	r°t|ƒD ] \}}t| jd ||| jƒV  qŽ| j�rˆ| jjjdddd�}t|ƒ}t|| jjj| jjjƒD ]˜\}}}	|j|	|j|jd�}
| ¡ D ]h\}}d\}}|dk�rB| j| | d }|}t| j| ||
| | jt| j dd ƒ||| j!||d	�
V  �q|d7 }qìn^t| jjŽ D ]P}t|ƒD ]8\}}t| j| ||| jt| j dd ƒ||| j!d
�V  �q |d7 }�q”|  "|¡E d H  d S )NrP   r   FTrí   )Z
allow_fillZ
fill_valuerï   r  rñ   ró   )#rõ   rÚ   rá   rÛ   rä   rî   rÜ   rl   rk   r  r  r  r   rà   r   rÝ   ÚcomZany_not_noner÷   r   rè   rö   r   rø   rù   rú   rû   Z_can_hold_naZ	_na_valuer@   r3   rë   râ   rß   r  )r+   ZgcolidxZindex_labelsZcidxr¥   rþ   rÿ   r  rù   r  r  r  r  r$   r%   Zindexcolvalsr  Zindexcolvalr,   r,   r-   r    s€    
 ÿ  ÿ  ÿý
öø
z(ExcelFormatter._format_hierarchical_rowsc                 C  s
   t | jƒS )z1Whether the aliases for column names are present.)r   rÚ   rç   r,   r,   r-   rõ   ]  s    zExcelFormatter._has_aliasesr&   )r   r)   c                 c  sn   t t| jƒƒD ]Z}| jjd d …|f }t|ƒD ]8\}}t| j| || |d t| j	dd ƒ||| j
d�V  q.qd S )NÚctxró   )ÚrangerÑ   rà   rä   Zilocr÷   r3   rá   rë   râ   rß   )r+   r   ZcolidxZseriesr  r"   r,   r,   r-   r  b  s    øzExcelFormatter._generate_bodyc                 c  s2   t  |  ¡ |  ¡ ¡D ]}|  |j¡|_|V  qd S r*   )r  r  r  r  rì   r"   )r+   Úcellr,   r,   r-   Úget_formatted_cellsr  s    z"ExcelFormatter.get_formatted_cellsÚstorage_options)r#  ÚSheet1r   ztuple[int, int] | Noner   )Ú
sheet_nameÚstartrowÚstartcolÚfreeze_panesÚenginer#  r)   c              	   C  s¦   ddl m} | jj\}	}
|	| jks,|
| jkrPtd|	› d|
› d| j› d| j› �ƒ‚|  ¡ }t||ƒrhd}n||||d�}d}z|j
|||||d	� W 5 |r | 	¡  X d
S )a   
        writer : path-like, file-like, or ExcelWriter object
            File path or existing ExcelWriter
        sheet_name : str, default 'Sheet1'
            Name of sheet which will contain DataFrame
        startrow :
            upper left cell row to dump data frame
        startcol :
            upper left cell column to dump data frame
        freeze_panes : tuple of integer (length 2), default None
            Specifies the one-based bottommost row and rightmost column that
            is to be frozen
        engine : string, default None
            write engine to use if writer is a path - you can also set this
            via the options ``io.excel.xlsx.writer``,
            or ``io.excel.xlsm.writer``.

        {storage_options}

            .. versionadded:: 1.2.0
        r   )ÚExcelWriterz-This sheet is too large! Your sheet size is: z, z Max sheet size is: F)r)  r#  T)r&  r'  r(  N)Zpandas.io.excelr*  rä   ÚshapeÚmax_rowsÚmax_colsrÒ   r"  rl   ÚcloseZ_write_cells)r+   Úwriterr%  r&  r'  r(  r)  r#  r*  Znum_rowsZnum_colsZformatted_cellsZ	need_saver,   r,   r-   Úwritew  s2     ÿ
  ÿû
	zExcelFormatter.write)	r¹   NNTTNFrÖ   N)r$  r   r   NNN)r/   r0   r1   rÓ   r,  r-  r.   Úpropertyrè   rì   r  r	  r  r  r  r  rõ   r  r"  r   r   r0  r,   r,   r,   r-   rÕ   ð  sD             õ"-E.O      ørÕ   )9rÓ   Ú
__future__r   Ú	functoolsr   r   r  r·   Útypingr   r   r   r   r	   r
   r   r‘   Únumpyr  Zpandas._libs.libr   Zpandas._typingr   r   Zpandas.util._decoratorsr   Zpandas.util._exceptionsr   Zpandas.core.dtypesr   Zpandas.core.dtypes.commonr   r   Zpandasr   r   r   r   Zpandas.core.commonÚcoreÚcommonr  Zpandas.core.shared_docsr   Zpandas.io.formats._color_datar   Zpandas.io.formats.cssr   r   Zpandas.io.formats.formatr   Zpandas.io.formats.printingr   r   r3   rF   rÕ   r,   r,   r,   r-   Ú<module>   s6   $	   