o
    d                     @  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mZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ ed(ddZed)ddZe	d*d+ddZed,d d!Zed,d"d#Zed-d,d$d%Zd&d' ZdS ).    )annotations)contextmanagerN)Path)IOAny	Generator)
BaseBufferCompressionOptionsFilePath)PYPY)ChainedAssignmentError)
set_option)
get_handle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   ]/var/www/html/visualizacion-main/env/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                   sB   | d u rzt jd= W d S  ty   Y d S w | t jd<    d S )NTZ)osenvironKeyErrortzset)r   timer   r   setTZJ   s   
zset_timezone.<locals>.setTZr   )r   r   )r$   r   r    get)r   r%   orig_tzr   r#   r   set_timezone2   s   
r(   Freturn_filelikeboolkwargsr   Generator[Any, None, None]c              	   k  s    t t }| du rd} tt |  } ||  }|  t|}|r1|dd t|fi |}z|V  W t	|ts?|
  | rI|  dS dS t	|tsT|
  | r]|  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 modezw+b)r   tempfile
gettempdirr   uuiduuid4touch
setdefaultopen
isinstancecloseis_fileunlink)filenamer)   r+   folderr   handle_or_strr   r   r   ensure_clean\   s.   


r=   c               	   c  sH    t tj} zdV  W tj  tj|  dS tj  tj|  w )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)saved_environr   r   r   !ensure_safe_environment_variables   s   


rB   c              	   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)namer+   rF   _BUILTIN_DIALECTSr   r   r   with_csv_dialect   s   rL   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.computationrM   _MIN_ELEMENTSUSE_NUMEXPRr   )usemin_elementsexprolduseoldminr   r   r   use_numexpr   s   
rV   c                  C  s.   t rddlm}  |  S ddlm} |tddS )Nr   )nullcontext)assert_produces_warningzYA value is trying to be set on a copy of a DataFrame or Series through chained assignment)match)r   
contextlibrW   pandas._testingrX   r   )rW   rX   r   r   r   raises_chained_assignment_error   s   r\   )r   r   r   r	   r   r   )r   r   r   r   )NF)r)   r*   r+   r   r   r,   )r   r   )N) 
__future__r   rZ   r   r   pathlibr   r/   typingr   r   r   r1   pandas._typingr   r	   r
   pandas.compatr   pandas.errorsr   pandasr   pandas.io.commonr   r   r(   r=   rB   rL   rV   r\   r   r   r   r   <module>   s4    ),!