o
    Û­jQ  ã                   @  s  d dl mZ d dlmZ d dlZd dlmZ d dlZd dlm	Z	m
Z
m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 e
rZd dlmZ d dlmZmZmZ ed-dd„ƒZed.dd„ƒZe	d/d0d d!„ƒZ ed1d#d$„ƒZ!ed2d3d%d&„ƒZ"d4d)d*„Z#d5d+d,„Z$dS )6é    )Úannotations)ÚcontextmanagerN)ÚPath)ÚIOÚTYPE_CHECKINGÚAny)Úusing_copy_on_write)ÚPYPYÚWARNING_CHECK_DISABLED)ÚChainedAssignmentError)Ú
set_option)Ú
get_handle)Ú	Generator)Ú
BaseBufferÚCompressionOptionsÚFilePathÚpathúFilePath | BaseBufferÚcompressionr   Úreturnú Generator[IO[bytes], None, None]c                 c  s@   � t | d|dd��}|jV  W d  ƒ dS 1 sw   Y  dS )a&  
    Open a compressed file and return a file object.

    Parameters
    ----------
    path : str
        The path where the file is read from.

    compression : {'gzip', 'bz2', 'zip', 'xz', 'zstd', None}
        Name of the decompression to use

    Returns
    -------
    file object
    ÚrbF)r   Úis_textN)r   Úhandle)r   r   r   © r   úU/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pandas/_testing/contexts.pyÚdecompress_file$   s   €
"ÿr   ÚtzÚstrúGenerator[None, None, None]c                 #  sL   � ddl ‰ d‡ fdd„}tj d¡}|| ƒ z
dV  W ||ƒ dS ||ƒ w )	a¼  
    Context manager for temporarily setting a timezone.

    Parameters
    ----------
    tz : str
        A string representing a valid timezone.

    Examples
    --------
    >>> from datetime import datetime
    >>> from dateutil.tz import tzlocal
    >>> tzlocal().tzname(datetime(2021, 1, 1))  # doctest: +SKIP
    'IST'

    >>> with set_timezone('US/Eastern'):
    ...     tzlocal().tzname(datetime(2021, 1, 1))
    ...
    'EST'
    r   Nr   ÚNonec                   sP   t ˆ dƒr&| d u rztjd= W d S  ty   Y d S w | tjd< ˆ  ¡  d S d S )NÚtzsetÚTZ)ÚhasattrÚosÚenvironÚKeyErrorr!   )r   ©Útimer   r   ÚsetTZS   s   
ÿ
øzset_timezone.<locals>.setTZr"   )r   r    )r(   r$   r%   Úget)r   r)   Úorig_tzr   r'   r   Úset_timezone;   s   €r,   FÚreturn_filelikeÚboolÚkwargsr   úGenerator[Any, None, None]c              	   k  sä   � t t ¡ ƒ}| du rd} tt ¡ ƒ|  } ||  }| ¡  t|ƒ}| dd¡}|rE| dd¡ |du r;d|d vr;d}t	|fd|i|¤Ž}z|V  W t
|tƒsS| ¡  | ¡ r]| ¡  dS dS t
|tƒsh| ¡  | ¡ rq| ¡  w w )az  
    Gets a temporary path and agrees to remove on close.

    This implementation does not use tempfile.mkstemp to avoid having a file handle.
    If the code using the returned path wants to delete the file itself, windows
    requires that no program has a file handle to it.

    Parameters
    ----------
    filename : str (optional)
        suffix of the created file.
    return_filelike : bool (default False)
        if True, returns a file-like which is *always* cleaned. Necessary for
        savefig and other functions which want to append extensions.
    **kwargs
        Additional keywords are passed to open().

    NÚ ÚencodingÚmodezw+bÚbzutf-8)r   ÚtempfileÚ
gettempdirr   ÚuuidÚuuid4ÚtouchÚpopÚ
setdefaultÚopenÚ
isinstanceÚcloseÚis_fileÚunlink)Úfilenamer-   r/   Úfolderr   Úhandle_or_strr2   r   r   r   Úensure_cleanf   s4   €
ÿ
þ
ÿrD   Únamec              	   k  sX   � ddl }h d£}| |v rtdƒ‚|j| fi |¤Ž zdV  W | | ¡ dS | | ¡ w )au  
    Context manager to temporarily register a CSV dialect for parsing CSV.

    Parameters
    ----------
    name : str
        The name of the dialect.
    kwargs : mapping
        The parameters for the dialect.

    Raises
    ------
    ValueError : the name of the dialect conflicts with a builtin one.

    See Also
    --------
    csv : Python's CSV library.
    r   N>   ú	excel-tabÚunixÚexcelz Cannot override builtin dialect.)ÚcsvÚ
ValueErrorÚregister_dialectÚunregister_dialect)rE   r/   rI   Ú_BUILTIN_DIALECTSr   r   r   Úwith_csv_dialect–   s   €rN   c              	   c  sh   � ddl m} |d u r|j}|j}|j}td| ƒ ||_zd V  W ||_td|ƒ d S ||_td|ƒ w )Nr   )Úexpressionszcompute.use_numexpr)Úpandas.core.computationrO   Ú_MIN_ELEMENTSÚUSE_NUMEXPRr   )ÚuseÚmin_elementsÚexprÚolduseÚoldminr   r   r   Úuse_numexpr¸   s   €
ÿrX   Tr   c                 C  s    ddl m} | sddlm} |ƒ S tstr |s ddlm} |ƒ S ts$tr/|r/||d |¡d�S tƒ r7t}d}nt	}d}|rC|g|¢R }||d |g|¢R ¡d�S )Nr   ©Úassert_produces_warning©Únullcontextú|)ÚmatchzYA value is trying to be set on a copy of a DataFrame or Series through chained assignmentr   )
Úpandas._testingrZ   Ú
contextlibr\   r	   r
   Újoinr   r   ÚFutureWarning)ÚwarnÚextra_warningsÚextra_matchrZ   r\   Úwarningr^   r   r   r   Úraises_chained_assignment_errorÊ   s0   þÿþrg   c                 K  sB   ddl m} | r
trddlm} |ƒ S |sd}|tfd|i|¤ŽS )aq  
    Assert that a warning is raised in the CoW warning mode.

    Parameters
    ----------
    warn : bool, default True
        By default, check that a warning is raised. Can be turned off by passing False.
    match : str
        The warning message to match against, if different from the default.
    kwargs
        Passed through to assert_produces_warning
    r   rY   r[   zSetting a value on a viewr^   )r_   rZ   r
   r`   r\   rb   )rc   r^   r/   rZ   r\   r   r   r   Úassert_cow_warningî   s   rh   )r   r   r   r   r   r   )r   r   r   r   )NF)r-   r.   r/   r   r   r0   )rE   r   r   r   )N)r   r   )Tr   r   )TN)%Ú
__future__r   r`   r   r$   Úpathlibr   r5   Útypingr   r   r   r7   Úpandas._configr   Úpandas.compatr	   r
   Úpandas.errorsr   Úpandasr   Úpandas.io.commonr   Úcollections.abcr   Úpandas._typingr   r   r   r   r,   rD   rN   rX   rg   rh   r   r   r   r   Ú<module>   s8    *ÿ/!
$