a
    oÝEb¦  ã                   @  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	 d dl
Z
d dlZd dlmZmZ d dlZd dlmZ d dlmZ ed	d
„ ƒZeddœdd„ƒZeddddœdd„ƒZedd„ ƒZedd„ ƒZedd„ ƒZed dd„ƒZG dd„ dƒZdS )!é    )Úannotations)ÚcontextmanagerN)ÚPath)Úrmtree)ÚIOÚAny)Ú
set_option)Ú
get_handlec                 c  s<   t | d|dd��}|jV  W d  ƒ n1 s.0    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)ÚcompressionZis_textN)r	   Úhandle)Úpathr   r   © r   úX/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/pandas/_testing/contexts.pyÚdecompress_file   s    r   Ústr©Útzc                 #  sT   ddl ‰ ddl‰‡ ‡fdd„}ˆ j d¡}|| ƒ zdV  W ||ƒ n
||ƒ 0 dS )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   Nc                   s@   | d u r*zˆ j d= W q< ty&   Y q<0 n| ˆ j d< ˆ ¡  d S )NÚTZ)ÚenvironÚKeyErrorÚtzsetr   ©ÚosÚtimer   r   ÚsetTZD   s    
zset_timezone.<locals>.setTZr   )r   r   r   Úget)r   r   Zorig_tzr   r   r   Úset_timezone+   s    
r   FÚboolr   )Úreturn_filelikeÚkwargsc              	   k  sÆ   t t ¡ ƒ}| du rd} d tjtjtj dd�¡|  } ||  }| 	¡  t
|ƒ}|rp| dd¡ t|fi |¤Ž}z,|V  W t|t
ƒsŒ| ¡  | ¡ rÂ| ¡  n$t|t
ƒs°| ¡  | ¡ rÀ| ¡  0 dS )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Ú é   )ÚkÚmodezw+b)r   ÚtempfileÚ
gettempdirÚjoinÚrandomÚchoicesÚstringÚascii_lettersÚdigitsÚtouchr   Ú
setdefaultÚopenÚ
isinstanceÚcloseÚis_fileÚunlink)Úfilenamer   r    Úfolderr   Zhandle_or_strr   r   r   Úensure_cleanV   s*    ÿ

ý
r6   c                  c  s^   t jdd�} z*| V  W zt| ƒ W qZ ty4   Y qZ0 n"zt| ƒ W n tyV   Y n0 0 dS )z{
    Get a temporary directory path and agrees to remove on close.

    Yields
    ------
    Temporary directory path
    r!   )ÚsuffixN)r%   Úmkdtempr   ÚOSError)Zdirectory_namer   r   r   Úensure_clean_dirƒ   s    	ýr:   c               	   c  sH   t tjƒ} z dV  W tj ¡  tj | ¡ ntj ¡  tj | ¡ 0 dS )zÚ
    Get a context manager to safely set environment variables

    All changes will be undone on close, hence environment variables set
    within this contextmanager will neither persist nor change global state.
    N)Údictr   r   ÚclearÚupdate)Zsaved_environr   r   r   Ú!ensure_safe_environment_variables–   s    

ÿ
r>   c              	   k  sX   ddl }h d£}| |v r tdƒ‚|j| fi |¤Ž zdV  W | | ¡ n| | ¡ 0 dS )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>   Úexcelz	excel-tabÚunixz Cannot override builtin dialect.)ÚcsvÚ
ValueErrorÚregister_dialectÚunregister_dialect)Únamer    rA   Z_BUILTIN_DIALECTSr   r   r   Úwith_csv_dialect¦   s    rF   c              	   c  sh   ddl m} |d u r|j}|j}|j}td| ƒ ||_zd V  W ||_td|ƒ n||_td|ƒ 0 d S )Nr   )Úexpressionszcompute.use_numexpr)Zpandas.core.computationrG   Z_MIN_ELEMENTSZUSE_NUMEXPRr   )ZuseZmin_elementsÚexprZolduseZoldminr   r   r   Úuse_numexprÈ   s    
ÿrI   c                   @  s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú
RNGContexta,  
    Context manager to set the numpy random number generator speed. Returns
    to the original value upon exiting the context manager.

    Parameters
    ----------
    seed : int
        Seed for numpy.random.seed

    Examples
    --------
    with RNGContext(42):
        np.random.randn()
    c                 C  s
   || _ d S ©N)Úseed)ÚselfrL   r   r   r   Ú__init__ê   s    zRNGContext.__init__c                 C  s   t j ¡ | _t j | j¡ d S rK   )Únpr(   Z	get_stateÚstart_staterL   )rM   r   r   r   Ú	__enter__í   s    zRNGContext.__enter__c                 C  s   t j | j¡ d S rK   )rO   r(   Z	set_staterP   )rM   Úexc_typeÚ	exc_valueÚ	tracebackr   r   r   Ú__exit__ò   s    zRNGContext.__exit__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rN   rQ   rU   r   r   r   r   rJ   Ú   s   rJ   )NF)N)Ú
__future__r   Ú
contextlibr   r   Úpathlibr   r(   Úshutilr   r*   r%   Útypingr   r   ÚnumpyrO   Zpandasr   Zpandas.io.commonr	   r   r   r6   r:   r>   rF   rI   rJ   r   r   r   r   Ú<module>   s4   
*,


!