U
    ?vf                     @  s  d Z ddlmZ ddlmZmZ ddlZddlmZ ddl	Z	ddl
Z
ddlZddl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ZddlZddlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% dd	l&m'Z'm(Z)m*Z*m+Z+m,Z, ddl-Z-ddl.Z.dd
l/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z> ddl?m@Z@ ddlAmBZB ddlCmDZDmEZEmFZFmGZG ddlHmIZI ddlJmKZK eLe,e* e+ ZMeMNd eOdZPe#de0dZQe	jRG dd dZSe	jRG dd dee ZTdddddZUe%d d d!d"d#ZVe%ddd!d$d#ZVd%d%d!d&d#ZVdd'd(d)d*ZWe%dd,dd d-d.d/ZXe%ddddd-d0d/ZXdd2dd%d-d3d/ZXd4d5 ZYd6ddd7d8ZZe@eKd9 eKd: d; d<dd6d d?d d@ddAdBdCZ[d d dDdEdFZ\dGdGdGdGdHdIdJdKdLdM	Z]eLe]^ Z_d?dNdOdPdQZ`e@eKd: d; dRd6dSdSdTdUdVZadWd'dDdXdYZbe%d+d+d+d+d+dZd6d dSd?dd[dSd@d\d]	d^d_Zce%d+d+d+d+d+d+d`d6d dSd?ddadSd@dbd]	dcd_Zce%d+d+d+d+d+d+d`d6d dSd?dddSd@ddd]	ded_Zce@eKd: df dRddd1dgddd`d6d dSd?dddSd@ddd]	dhd_ZcG didj djeeZdG dkdl dledZeG dmdn dnedZfG dodp dpZgG dqdr drZhdsddtdudvdwZid6dd!dxdyZjd6d ddzd{d|Zke
jld}d~ddZmdddddddZnddddddZodS )zCommon IO api utilities    )annotations)ABCabstractmethodN)defaultdict)BufferedIOBaseBytesIO	RawIOBaseStringIO
TextIOBaseTextIOWrapper)Path)IOAnyAnyStrDefaultDictGenericHashableLiteralMappingSequenceTypeVarcastoverload)urljoinurlparseuses_netlocuses_paramsuses_relative)
BaseBufferCompressionDictCompressionOptionsFilePath
ReadBufferReadCsvBufferStorageOptionsWriteBuffer)get_lzma_file)import_optional_dependency)BZ2File)doc)find_stack_level)is_boolis_file_like
is_integeris_list_like)
MultiIndex)_shared_docs z^[A-Za-z][A-Za-z0-9+\-+.]*://BaseBufferT)boundc                   @  s>   e Zd ZU dZded< ded< ded< ded< d	Zd
ed< dS )IOArgsz?
    Return value of io/common.py:_get_filepath_or_buffer.
    str | BaseBufferfilepath_or_bufferstrencodingmoder   compressionFboolshould_closeN)__name__
__module____qualname____doc____annotations__r<    rB   rB   4/tmp/pip-unpacked-wheel-vdrwu74i/pandas/io/common.pyr4   S   s   
r4   c                   @  sn   e Zd ZU dZded< ded< ejedZded< d	Z	d
ed< ddddZ
ddddZdddddZdS )	IOHandlesau  
    Return value of io/common.py:get_handle

    Can be used as a context manager.

    This is used to easily close created buffers and to handle corner cases when
    TextIOWrapper is inserted.

    handle: The file handle to be used.
    created_handles: All file handles that are created by get_handle
    is_wrapped: Whether a TextIOWrapper needs to be detached.
    z
IO[AnyStr]handler   r:   )default_factoryzlist[IO[bytes] | IO[str]]created_handlesFr;   
is_wrappedNonereturnc                 C  s\   | j r8t| jtst| j  | j  | j| j | jD ]}|	  q>g | _d| _ dS )z
        Close all created buffers.

        Note: If a TextIOWrapper was inserted, it is flushed and detached to
        avoid closing the potentially user-created buffer.
        FN)
rH   
isinstancerE   r   AssertionErrorflushdetachrG   removeclose)selfrE   rB   rB   rC   rQ   u   s    



zIOHandles.closezIOHandles[AnyStr]c                 C  s   | S NrB   rR   rB   rB   rC   	__enter__   s    zIOHandles.__enter__r   )argsrK   c                 G  s   |    d S rS   )rQ   )rR   rV   rB   rB   rC   __exit__   s    zIOHandles.__exit__N)r=   r>   r?   r@   rA   dataclassesfieldlistrG   rH   rQ   rU   rW   rB   rB   rB   rC   rD   `   s   
rD   objectr;   )urlrK   c                 C  s   t | tsdS t| jtkS )z
    Check to see if a URL has a valid protocol.

    Parameters
    ----------
    url : str or unicode

    Returns
    -------
    isurl : bool
        If `url` has a valid protocol return True otherwise False.
    F)rL   r7   	parse_urlscheme_VALID_URLSr\   rB   rB   rC   is_url   s    
ra   r7   )r6   rK   c                 C  s   d S rS   rB   r6   rB   rB   rC   _expand_user   s    rc   c                 C  s   d S rS   rB   rb   rB   rB   rC   rc      s    zstr | BaseBufferTc                 C  s   t | trtj| S | S )a]  
    Return the argument with an initial component of ~ or ~user
    replaced by that user's home directory.

    Parameters
    ----------
    filepath_or_buffer : object to be converted if possible

    Returns
    -------
    expanded_filepath_or_buffer : an expanded filepath or the
                                  input if not expandable
    )rL   r7   ospath
expanduserrb   rB   rB   rC   rc      s    
rI   )headerrK   c                 C  s   | d krd S t | r2tt| } | dk r.tdd S t| ddr|tt| } ttt | s^tdtdd | D rxtdd S t	| rt
d	tdd S )
Nr   zUPassing negative integer to header is invalid. For no header, use header=None insteadF)Z
allow_setsz*header must be integer or list of integersc                 s  s   | ]}|d k V  qdS )r   NrB   ).0irB   rB   rC   	<genexpr>   s     z&validate_header_arg.<locals>.<genexpr>z8cannot specify multi-index header with negative integerszPassing a bool to header is invalid. Use header=None for no header or header=int or list-like of ints to specify the row(s) making up the column names)r-   r   int
ValueErrorr.   r   allmapanyr+   	TypeError)rg   rB   rB   rC   validate_header_arg   s*    

rq   .r!   )r6   convert_file_likerK   c                 C  s   d S rS   rB   r6   rr   rB   rB   rC   stringify_path   s    rt   c                 C  s   d S rS   rB   rs   rB   rB   rC   rt      s    FzFilePath | BaseBufferTc                 C  s2   |st | rtt| S t| tjr*|  } t| S )a  
    Attempt to convert a path-like object to a string.

    Parameters
    ----------
    filepath_or_buffer : object to be converted

    Returns
    -------
    str_filepath_or_buffer : maybe a string version of the object

    Notes
    -----
    Objects supporting the fspath protocol (python 3.6+) are coerced
    according to its __fspath__ method.

    Any other object is passed through unchanged, which includes bytes,
    strings, buffers, or anything else that's not even path-like.
    )r,   r   r2   rL   rd   PathLike
__fspath__rc   rs   rB   rB   rC   rt      s
    
c                  O  s   ddl }|jj| |S )z`
    Lazy-import wrapper for stdlib urlopen, as that imports a big chunk of
    the stdlib.
    r   N)urllib.requestrequesturlopen)rV   kwargsurllibrB   rB   rC   ry     s    ry   zFilePath | BaseBufferc                 C  s$   t | to"tt| o"| d S )zR
    Returns true if the given URL looks like
    something fsspec can handle
    )zhttp://zhttps://)rL   r7   r;   _RFC_3986_PATTERNmatch
startswithr`   rB   rB   rC   is_fsspec_url  s
    

r   storage_optionscompression_optionsr6   )r   r   utf-8rr    r$   )r6   r8   r:   r9   r   rK   c              	   C  s  t | } t|\}}t| |}|rJt| drJd|krJtjdtt d d}t||d}d|kr|dkr|d	krtj| d
| t	t d |}d|krd|kr|d7 }t
| tr.t| r.|pi }ddl}|jj| |d}t|2}	|	jdd}
|
dkrddi}t|	 }W 5 Q R X t|||d|dS t| rXt
| tsHt| dr`| dd} | drx| dd} td}g }z&td ddlm}m} ||tg}W n tk
r   Y nX z$|j | fd|i|pi   }W n^ t!|k
rD   |dkrddi}nt|}d|d< |j | fd|i|p6i   }Y nX t|||d|dS |rft"dt
| tt#t$j$frtt%| ||d|dS t| dst| dsdt&|  }t"|t| ||d|dS )a%  
    If the filepath_or_buffer is a url, translate and return the buffer.
    Otherwise passthrough.

    Parameters
    ----------
    filepath_or_buffer : a url, filepath (str, py.path.local or pathlib.Path),
                         or buffer
    {compression_options}

        .. versionchanged:: 1.4.0 Zstandard support.

    encoding : the encoding to use to decode bytes, default is 'utf-8'
    mode : str, optional

    {storage_options}

        .. versionadded:: 1.2.0

    ..versionchange:: 1.2.0

      Returns the dataclass IOArgs.
    writebzDcompression has no effect when passing a non-binary object as input.)
stacklevelN)methodw)bz2xz)zutf-16zutf-32z( will not write the byte order mark for tr   )headerszContent-Encodinggzipr   T)r6   r8   r:   r<   r9   zs3a://zs3://zs3n://fsspecZbotocore)ClientErrorNoCredentialsErrorr9   Zanonz?storage_options passed with file object or non-fsspec file pathFreadz)Invalid file path or buffer object type: )'rt   get_compression_methodinfer_compressionhasattrwarningswarnRuntimeWarningr*   dictUnicodeWarningrL   r7   ra   rw   rx   Requestry   r   getr   r   r4   r   rM   r~   replacer'   Zbotocore.exceptionsr   r   PermissionErrorImportErroropentuplerl   bytesmmaprc   type)r6   r8   r:   r9   r   compression_methodZfsspec_moder{   Zreq_inforeqcontent_encodingreaderr   Zerr_types_to_retry_with_anonr   r   Zfile_objmsgrB   rB   rC   _get_filepath_or_buffer  s    "
	


 


r   )re   rK   c                 C  s   ddl m} td|| S )z
    converts an absolute native path to a FILE URL.

    Parameters
    ----------
    path : a path in native format

    Returns
    -------
    a valid FILE URL
    r   )pathname2urlzfile:)rw   r   r   )re   r   rB   rB   rC   file_path_to_url  s    r   tarr   r   zipr   zstd)	.tar.tar.gz.tar.bz2.tar.xz.gz.bz2.zip.xzz.zstz"tuple[str | None, CompressionDict])r:   rK   c              
   C  s`   t | trPt| }z|d}W qX tk
rL } ztd|W 5 d}~X Y qXX ni }| }||fS )a  
    Simplifies a compression argument to a compression method string and
    a mapping containing additional arguments.

    Parameters
    ----------
    compression : str or mapping
        If string, specifies the compression method. If mapping, value at key
        'method' specifies compression method.

    Returns
    -------
    tuple of ({compression method}, Optional[str]
              {compression arguments}, Dict[str, Any])

    Raises
    ------
    ValueError on mapping missing 'method' key
    r   z.If mapping, compression must have key 'method'N)rL   r   r   popKeyErrorrl   )r:   compression_argsr   errrB   rB   rC   r     s    
r   )r   
str | None)r6   r:   rK   c                 C  s   |dkrdS |dkrZt | dd} t| ts.dS t D ]\}}|  |r6|  S q6dS |tkrf|S ddgtt }d| d| }t	|dS )a/  
    Get the compression method for filepath_or_buffer. If compression='infer',
    the inferred compression method is returned. Otherwise, the input
    compression method is returned unchanged, unless it's invalid, in which
    case an error is raised.

    Parameters
    ----------
    filepath_or_buffer : str or file handle
        File path or object.
    {compression_options}

        .. versionchanged:: 1.4.0 Zstandard support.

    Returns
    -------
    string or None

    Raises
    ------
    ValueError on invalid compression specified.
    NZinferT)rr   Unrecognized compression type: z
Valid compression types are )
rt   rL   r7   extension_to_compressionitemslowerendswith_supported_compressionssortedrl   )r6   r:   	extensionZvalidr   rB   rB   rC   r     s     

r   z
Path | strc                 C  s&   t | j}| s"td| ddS )z
    Check if parent directory of a file exists, raise OSError if it does not

    Parameters
    ----------
    path: Path or str
        Path to check parent directory of
    z1Cannot save file into a non-existent directory: ''N)r   parentis_dirOSError)re   r   rB   rB   rC   check_parent_directoryM  s    	
r   )r8   r:   
memory_maperrorsr   zLiteral[False]zIOHandles[bytes])	path_or_bufr9   r8   r:   r   is_textr   r   rK   c                C  s   d S rS   rB   r   r9   r8   r:   r   r   r   r   rB   rB   rC   
get_handle[  s    r   )r8   r:   r   r   r   r   zLiteral[True]zIOHandles[str]c                C  s   d S rS   rB   r   rB   rB   rC   r   j  s    z!IOHandles[str] | IOHandles[bytes]c                C  s   d S rS   rB   r   rB   rB   rC   r   y  s    r   Tc                C  s  |pd}|pd}t | |r*d|kr*|d7 }t| t|trHt| t| ||||d}|j}	t|	|\}	}}
t|	t}t	|j
}|d}d|kr|rtt|	 |rP|dkr|jdd	|_n |dkrd|jkr| jd7  _|d
kr2t|	trtjf |	|jd|}	ntjf |	|jd|}	n|dkrVt|	fd|ji|}	n|dkrt|	|jf|}	|	jjdkr4|
|	 |	j }t|dkr|	j| }	n$|std|  ntd| nZ|dkr|d|j t|	trtf d|	i|}	ntf d|	i|}	t|	ts4td|	jjkr4|
|	 |	j }t|dkr|	j|d }|dk	st|}	n$|std|  ntd| n|dkrt |	|j}	nl|dkr"td}d|jkrd|j f |i}nd|j!f |i}|j|	fd|ji|}	nd| }t|t|	trDt|
|	 nNt|	tr|j"rd|jkrt|	|j|j"|d	d}	nt|	|j}	|
|	 d }|s|jd!krt|	t#rt$|	|j"d"}	n~|rN|s|st |	|jrNt%|	d#rt%|	d$rt%|	d%st&|	}	t'|	|j"|d	d}	|
|	 t|jtpJ|j( }d|jkr|t%|	d&s|t)d't*|j d(|
+  |j(rt|jtrt|
|j t,|	|
||j
d)S )*a  
    Get file handle for given path/buffer and mode.

    Parameters
    ----------
    path_or_buf : str or file handle
        File path or object.
    mode : str
        Mode to open path_or_buf with.
    encoding : str or None
        Encoding to use.
    {compression_options}

        .. versionchanged:: 1.0.0
           May now be a dict with key 'method' as compression mode
           and other keys as compression options if compression
           mode is 'zip'.

        .. versionchanged:: 1.1.0
           Passing compression options as keys in dict is now
           supported for compression modes 'gzip', 'bz2', 'zstd' and 'zip'.

        .. versionchanged:: 1.4.0 Zstandard support.

    memory_map : bool, default False
        See parsers._parser_params for more information. Only used by read_csv.
    is_text : bool, default True
        Whether the type of the content passed to the file/buffer is string or
        bytes. This is not the same as `"b" not in mode`. If a string content is
        passed to a binary file/buffer, a wrapper is inserted.
    errors : str, default 'strict'
        Specifies how encoding and decoding errors are to be handled.
        See the errors argument for :func:`open` for a full list
        of options.
    storage_options: StorageOptions = None
        Passed to _get_filepath_or_buffer

    .. versionchanged:: 1.2.0

    Returns the dataclass IOHandles
    r   strictr   )r8   r:   r9   r   r   r   r   r   r1   r   )filenamer9   )fileobjr9   r   r9   r      zZero files found in ZIP file z9Multiple files found in ZIP file. Only one file per ZIP: r   namer   r   Nz Zero files found in TAR archive zDMultiple files found in TAR archive. Only one file per TAR archive: r   	zstandardZdctxZcctxr   )r8   r   newlineFrb)r8   readablewritableseekabler   z1Expected file path name or file-like object, got z type)rE   rG   rH   r:   )-_is_binary_modecodecslookuprL   r7   lookup_errorr   r6   _maybe_memory_mapr   r:   r   r   r9   r   r   GzipFile_BZ2File_BytesZipFilebufferappendnamelistlenr   rl   
setdefault_BytesTarFilerM   getnamesextractfiler&   r'   ZstdDecompressorZZstdCompressorr8   r
   _BytesIOWrapperr   
_IOWrapperr   r<   rp   r   reverserD   )r   r9   r8   r:   r   r   r   r   ZioargsrE   handlesZis_pathr   Z	zip_namesfilesfiler   Z	open_argsr   rH   rB   rB   rC   r     s>   6







	


 







	


c                      s8   e Zd ZdZeddddZdd fddZ  ZS )_BufferedWriterz
    Some objects do not support multiple .write() calls (TarFile and ZipFile).
    This wrapper writes to the underlying buffer on close.
    rI   rJ   c                 C  s   d S rS   rB   rT   rB   rB   rC   write_to_buffer  s    z_BufferedWriter.write_to_bufferc              	     sP   | j r
d S |  r8| d | j |   W 5 Q R X n
| j  t   d S )Nr   )closedgetvalueseekr   r   rQ   superrT   	__class__rB   rC   rQ     s    

z_BufferedWriter.close)r=   r>   r?   r@   r   r   rQ   __classcell__rB   rB   r   rC   r     s   r   c                      sX   e Zd Zddddddd fdd	Zd
d
dddZddddZddddZ  ZS )r   Nr   r   zLiteral[('r', 'a', 'w', 'x')]z-ReadBuffer[bytes] | WriteBuffer[bytes] | NonerI   )r   r9   r   archive_namerK   c                   s<   t    || _|| _tjjf || ||d|| _d S )N)r   r9   r   )	r   __init__r   r   tarfileTarFiler   extend_moder   )rR   r   r9   r   r   rz   r   rB   rC   r     s    
z_BytesTarFile.__init__r7   )r9   rK   c                 C  sP   | dd}|dkr|S | jd k	rLt| jj}|dkrL| d|dd   }|S )Nr   r1   r   )r   r   r   :r   )r   r   r   suffix)rR   r9   r   rB   rB   rC   r     s    
z_BytesTarFile.extend_moderJ   c                 C  sP   | j dkrdS t| j }|jdkr.|dj S |jdkrJ|ddj S |j S )z
        If an explicit archive_name is not given, we still want the file inside the zip
        file not to be named something.tar, because that causes confusion (GH39465).
        Nr   r1   )r   r   r   )r   r   r   with_suffixrR   r   rB   rB   rC   infer_filename  s    



z_BytesTarFile.infer_filenamec                 C  s>   | j p|  pd}tj|d}t|  |_| j||  d S )Nr   r   )	r   r  r   TarInfor   r   sizer   addfile)rR   r   tarinforB   rB   rC   r     s    z_BytesTarFile.write_to_buffer)Nr   NN)r=   r>   r?   r   r   r  r   r   rB   rB   r   rC   r     s       
r   c                      sF   e Zd Zdddddd fddZdd	d
dZdd	ddZ  ZS )r   Nz1FilePath | ReadBuffer[bytes] | WriteBuffer[bytes]r7   r   rI   )r   r9   r   rK   c                   s@   t    |dd}|| _|dtj tj||f|| _d S )Nr   r1   r:   )	r   r   r   r   r   zipfileZIP_DEFLATEDZipFiler   )rR   r   r9   r   rz   r   rB   rC   r     s
    
z_BytesZipFile.__init__rJ   c                 C  s@   t | jjtjtfr<t| jj}|jdkr6|dj	S |j	S dS )z
        If an explicit archive_name is not given, we still want the file inside the zip
        file not to be named something.zip, because that causes confusion (GH39465).
        r   r1   N)
rL   r   r   rd   ru   r7   r   r   r  r   r  rB   rB   rC   r    s    
z_BytesZipFile.infer_filenamec                 C  s(   | j p|  pd}| j||   d S )Nr   )r   r  r   writestrr   )rR   r   rB   rB   rC   r     s    z_BytesZipFile.write_to_buffer)N)r=   r>   r?   r   r  r   r   rB   rB   r   rC   r     s    r   c                   @  sT   e Zd Zd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S )r   r   rI   )r   rK   c                 C  s
   || _ d S rS   )r   )rR   r   rB   rB   rC   r     s    z_IOWrapper.__init__r7   r  c                 C  s   t | j|S rS   getattrr   )rR   r   rB   rB   rC   __getattr__  s    z_IOWrapper.__getattr__r;   rJ   c                 C  s   t | jdr| j S dS )Nr   T)r   r   r   rT   rB   rB   rC   r   "  s    
z_IOWrapper.readablec                 C  s   t | jdr| j S dS )Nr   T)r   r   r   rT   rB   rB   rC   r   '  s    
z_IOWrapper.seekablec                 C  s   t | jdr| j S dS )Nr   T)r   r   r   rT   rB   rB   rC   r   ,  s    
z_IOWrapper.writableN)r=   r>   r?   r   r  r   r   r   rB   rB   rB   rC   r     s
   r   c                   @  s@   e Zd ZdddddddZddd	d
ZddddddZdS )r   r   zStringIO | TextIOBaser7   rI   )r   r8   rK   c                 C  s   || _ || _d| _d S )N    )r   r8   overflow)rR   r   r8   rB   rB   rC   r   5  s    z_BytesIOWrapper.__init__)attrc                 C  s   t | j|S rS   r  )rR   r  rB   rB   rC   r  >  s    z_BytesIOWrapper.__getattr__z
int | Noner   )nrK   c                 C  st   | j d k	st| j || j}| j| }|d ksH|dk sH|t|krRd| _|S |d | }||d  | _|S d S )Nr   r  )r   rM   r   encoder8   r  r   )rR   r  Z
bytestringZcombined_bytestringZ	to_returnrB   rB   rC   r   A  s    
z_BytesIOWrapper.readN)r   )r  )r=   r>   r?   r   r  r   rB   rB   rB   rC   r   2  s   	r   r5   z/tuple[str | BaseBuffer, bool, list[BaseBuffer]])rE   r   rK   c              	   C  s   g }|t | dpt| tM }|s*| ||fS tt| } t| trRt| d} ||  zt	t
j
|  dt
jd}W 5 t|D ]} |   qzX |||gfS )zTry to memory map file/buffer.filenor   r   )access)r   rL   r7   r   r#   r   r   reversedrQ   r   r   r  ZACCESS_READ)rE   r   r   wrappedrB   rB   rC   r   O  s&    




  r   c              	   C  sH   d}t | } t| ts|S ztj| }W n ttfk
rB   Y nX |S )zTest whether file exists.F)rt   rL   r7   rd   re   existsrp   rl   )r6   r  rB   rB   rC   file_existsq  s    
r  )rE   r9   rK   c                 C  sV   d|ksd|krd|kS t jt jt jf}tt| |r:dS t| t pTdt| d|kS )z+Whether the handle is opened in binary moder   r   Fr9   )	r   StreamWriterStreamReaderStreamReaderWriter
issubclassr   rL   _get_binary_io_classesr  )rE   r9   Ztext_classesrB   rB   rC   r     s      r   ztuple[type, ...]rJ   c               	   C  sH   t tf} tddd}|dk	rD| d}| t|f7 } W 5 Q R X | S )z!IO classes that that expect bytesr   ignore)r   Nr  )r   r   r'   r   Zstream_readerr   )Zbinary_classesr   r   rB   rB   rC   r     s    r   zSequence[Hashable] | MultiIndexzbool | Sequence[int] | None)columns	index_colrK   c                   sD    dkst  trg  tt| o@t | t o@t fdd| D S )a  
    Check whether or not the `columns` parameter
    could be converted into a MultiIndex.

    Parameters
    ----------
    columns : array-like
        Object which may or may not be convertible into a MultiIndex
    index_col : None, bool or list, optional
        Column or columns to use as the (possibly hierarchical) index

    Returns
    -------
    bool : Whether or not columns could become a MultiIndex
    Nc                 3  s$   | ]}|t  krt|tV  qd S rS   )rZ   rL   r   )rh   cr#  rB   rC   rj     s      z+is_potential_multi_index.<locals>.<genexpr>)rL   r;   r   r/   rm   )r"  r#  rB   r%  rC   is_potential_multi_index  s    
r&  zSequence[Hashable])namesis_potential_multiindexrK   c                 C  s   t | } tt}t| D ]\}}|| }|dkr|d ||< |rpt|tsNt|dd |d  d| f }n| d| }|| }q(|| |< |d ||< q| S )a:  
    Rename column names if duplicates exist.

    Currently the renaming is done by appending a period and an autonumeric,
    but a custom pattern may be supported in the future.

    Examples
    --------
    >>> dedup_names(["x", "y", "x", "x"], is_potential_multiindex=False)
    ['x', 'y', 'x.1', 'x.2']
    r   r   Nr  .)rZ   r   rk   	enumeraterL   r   rM   )r'  r(  countsri   colZ	cur_countrB   rB   rC   dedup_names  s    "
r-  ).).)F)r   Nr   N)N)pr@   
__future__r   abcr   r   r   collectionsr   rX   	functoolsr   ior   r   r   r	   r
   r   r   rd   pathlibr   rer   typingr   r   r   r   r   r   r   r   r   r   r   r   urllib.parser   r   r]   r   r   r   r   r	  Zpandas._typingr   r   r    r!   r"   r#   r$   r%   Zpandas.compatr&   Zpandas.compat._optionalr'   Zpandas.compat.compressorsr(   r   Zpandas.util._decoratorsr)   Zpandas.util._exceptionsr*   Zpandas.core.dtypes.commonr+   r,   r-   r.   Zpandas.core.indexes.apir/   Zpandas.core.shared_docsr0   setr_   discardcompiler|   r2   Z	dataclassr4   rD   ra   rc   rq   rt   ry   r   r   r   r   valuesr   r   r   r   r   r   r   r   r   r   r   r  r   	lru_cacher   r&  r-  rB   rB   rB   rC   <module>   s    8(


,  "

     3#6$$$$  7$" 