o
    Eh                     @  sZ  U d dl mZ d dlmZmZmZ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mZmZ erHd dlmZ ee Zede
egef dZi Zd	ed
< dKddZdLdMddZdNddZdOddZdPd!d"ZedQd%d&Z edRd(d&Z edSd)d&Z edTd*d&Z dUd-d&Z edVd1d2Z!edWd4d2Z!dXd7d2Z!dYd=d>Z"dZdBdCZ#d[dHdIZ$dJS )\    )annotations)HashableIterableMutableMappingSequence)TYPE_CHECKINGAnyCallableLiteralTypeVaroverloadimport_optional_dependency)
is_integeris_list_like)ExcelWriterusecols_func)Zboundz"MutableMapping[str, ExcelWriter_t]_writersklassExcelWriter_treturnNonec                 C  s"   t | std| j}| t|< dS )z
    Add engine to the excel writer registry.io.excel.

    You must use this method to integrate with ``to_excel``.

    Parameters
    ----------
    klass : ExcelWriter
    z&Can only register callables as enginesN)callable
ValueErrorZ_enginer   )r   engine_name r   5lib/python3.10/site-packages/pandas/io/excel/_util.pyregister_writer"   s   
r   readerextstrmodeLiteral['reader', 'writer']c                 C  sZ   dddddd}ddddd}|dv sJ |dkr)t d	d
d}|r%d	|d< ||  S ||  S )a  
    Return the default reader/writer for the given extension.

    Parameters
    ----------
    ext : str
        The excel file extension for which to get the default engine.
    mode : str {'reader', 'writer'}
        Whether to get the default engine for reading or writing.
        Either 'reader' or 'writer'

    Returns
    -------
    str
        The default engine for the extension.
    ZopenpyxlZpyxlsbZxlrdZodf)xlsxxlsmxlsbZxlsods)r#   r$   r%   r&   )r   writerr'   
xlsxwriterwarn)errorsr#   r   )r   r!   Z_default_readersZ_default_writersr(   r   r   r   get_default_engine2   s$   r+   r   c              
   C  s6   zt |  W S  ty } z	td|  d|d }~ww )NzNo Excel writer '')r   KeyErrorr   )r   errr   r   r   
get_writer[   s   
r/   xintc                 C  sd   d}|    D ]%}t|}|tdk s|tdkr!td|  |d | td d }q|d S )ai  
    Convert Excel column name like 'AB' to 0-based column index.

    Parameters
    ----------
    x : str
        The Excel column name to convert to a 0-based column index.

    Returns
    -------
    num : int
        The column index corresponding to the name.

    Raises
    ------
    ValueError
        Part of the Excel column name was invalid.
    r   AZzInvalid column name:       )upperstripordr   )r0   indexcZcpr   r   r   
_excel2numb   s   r;   areas	list[int]c                 C  s^   g }|  dD ]%}d|v r%| d}|tt|d t|d d  q|t| q|S )a  
    Convert comma separated list of column names and ranges to indices.

    Parameters
    ----------
    areas : str
        A string containing a sequence of column ranges (or areas).

    Returns
    -------
    cols : list
        A list of 0-based column indices.

    Examples
    --------
    >>> _range2cols('A:E')
    [0, 1, 2, 3, 4]
    >>> _range2cols('A,C,Z:AB')
    [0, 2, 25, 26, 27]
    ,:r   r5   )splitextendranger;   append)r<   ZcolsrngZrngsr   r   r   _range2cols   s   
&rE   usecolsstr | list[int]c                 C     d S Nr   rF   r   r   r   maybe_convert_usecols      rK   	list[str]c                 C  rH   rI   r   rJ   r   r   r   rK      rL   c                 C  rH   rI   r   rJ   r   r   r   rK      rL   c                 C  rH   rI   r   rJ   r   r   r   rK      rL   1str | list[int] | list[str] | usecols_func | None+None | list[int] | list[str] | usecols_funcc                 C  s2   | du r| S t | rtdt| trt| S | S )a  
    Convert `usecols` into a compatible format for parsing in `parsers.py`.

    Parameters
    ----------
    usecols : object
        The use-columns object to potentially convert.

    Returns
    -------
    converted : object
        The compatible format of `usecols`.
    Nz}Passing an integer for `usecols` is no longer supported.  Please pass in a list of int from 0 to `usecols` inclusive instead.)r   r   
isinstancer    rE   rJ   r   r   r   rK      s   
freeze_panestuple[int, int]Literal[True]c                 C  rH   rI   r   rQ   r   r   r   validate_freeze_panes   rL   rU   Literal[False]c                 C  rH   rI   r   rT   r   r   r   rU      rL   tuple[int, int] | Noneboolc                 C  s6   | d urt | dkrtdd | D rdS tddS )N   c                 s  s    | ]}t |tV  qd S rI   )rP   r1   ).0itemr   r   r   	<genexpr>   s    

z(validate_freeze_panes.<locals>.<genexpr>TzLfreeze_panes must be of form (row, column) where row and column are integersF)lenallr   rT   r   r   r   rU      s   rowlist[Hashable]control_row
list[bool]!tuple[list[Hashable], list[bool]]c                 C  sf   | d }t dt| D ]#}|| s| | }| | dks!| | du r&|| |< qd||< | | }q| |fS )a  
    Forward fill blank entries in row but only inside the same parent index.

    Used for creating headers in Multiindex.

    Parameters
    ----------
    row : list
        List of items in a single row.
    control_row : list of bool
        Helps to determine if particular column is in same parent index as the
        previous value. Used to stop propagation of empty cells between
        different indexes.

    Returns
    -------
    Returns changed row and control_row
    r   r5    NF)rB   r]   )r_   ra   Zlastir   r   r   fill_mi_header   s   

rf   	index_colint | Sequence[int]&tuple[Hashable | None, list[Hashable]]c                 C  sp   t |rt|tsJ t|}n	t|trJ |}| | }|dkr#dn|}|| d| dg | |d d  fS )a  
    Pop the header name for MultiIndex parsing.

    Parameters
    ----------
    row : list
        The data row to parse for the header name.
    index_col : int, list
        The index columns for our data. Assumed to be non-null.

    Returns
    -------
    header_name : str
        The extracted header name.
    trimmed_row : list
        The original data row with the header name removed.
    rd   Nr5   )r   rP   r   max)r_   rg   re   Zheader_namer   r   r   pop_header_name  s   
&rk   engine_kwargsdict[str, Any] | Nonekwargsdictc                 C  s$   | du ri }n|   }|| |S )a  
    Used to combine two sources of kwargs for the backend engine.

    Use of kwargs is deprecated, this function is solely for use in 1.3 and should
    be removed in 1.4/2.0. Also _base.ExcelWriter.__new__ ensures either engine_kwargs
    or kwargs must be None or empty respectively.

    Parameters
    ----------
    engine_kwargs: dict
        kwargs to be passed through to the engine.
    kwargs: dict
        kwargs to be psased through to the engine (deprecated)

    Returns
    -------
    engine_kwargs combined with kwargs
    N)copyupdate)rl   rn   resultr   r   r   combine_kwargs6  s
   
rs   N)r   r   r   r   )r   )r   r    r!   r"   r   r    )r   r    r   r   )r0   r    r   r1   )r<   r    r   r=   )rF   rG   r   r=   )rF   rM   r   rM   )rF   r   r   r   )rF   r   r   r   )rF   rN   r   rO   )rQ   rR   r   rS   )rQ   r   r   rV   )rQ   rW   r   rX   )r_   r`   ra   rb   r   rc   )r_   r`   rg   rh   r   ri   )rl   rm   rn   ro   r   ro   )%Z
__future__r   Zcollections.abcr   r   r   r   typingr   r   r	   r
   r   r   Zpandas.compat._optionalr   Zpandas.core.dtypes.commonr   r   Zpandas.io.excel._baser   typer   objectr   r   __annotations__r   r+   r/   r;   rE   rK   rU   rf   rk   rs   r   r   r   r   <module>   s@     	

)

 !



#"