a
    Of`                     @  s   d dl mZ d dlZd dlZd dlZd dlZd dlmZmZm	Z	 d dl
Z
d dlZd dlmZmZ d dlmZ d dlZd dlmZ erd dlmZmZ d dlmZmZ dd	d
ddddZdddddZdddddZddddddZdS )    )annotationsN)TYPE_CHECKINGAnyCallable)get_bz2_fileget_lzma_file)import_optional_dependency)ensure_clean)FilePathReadPickleBuffer)	DataFrameSeriesr   z"FilePath | ReadPickleBuffer | NonezDataFrame | Series)objpathreturnc                 C  s^   |}|du rdt   d}t|&}t| | t|W  d   S 1 sP0    Y  dS )a  
    Pickle an object and then read it again.

    Parameters
    ----------
    obj : any object
        The object to pickle and then re-read.
    path : str, path object or file-like object, default None
        The path where the pickled object is written and then read.

    Returns
    -------
    pandas object
        The original object that was pickled and then re-read.
    N__z	__.pickle)uuiduuid4r	   pdZ	to_pickleZread_pickle)r   r   _pathZ	temp_path r   L/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/_testing/_io.pyround_trip_pickle'   s    
r   z
str | None)r   c                 C  sV   t j}|du rd}t|(}| || |||}W d   n1 sH0    Y  |S )a  
    Write an object to file specified by a pathlib.Path and read it back

    Parameters
    ----------
    writer : callable bound to pandas object
        IO writing function (e.g. DataFrame.to_csv )
    reader : callable
        IO reading function (e.g. pd.read_csv )
    path : str, default None
        The path where the object is written and then read.

    Returns
    -------
    pandas object
        The original object that was serialized and then re-read.
    NZ___pathlib___)pathlibPathr	   )writerreaderr   r   r   r   r   r   round_trip_pathlibA   s    
*r   c                 C  sd   ddl }|dj}|du r d}t|(}| || |||}W d   n1 sV0    Y  |S )a  
    Write an object to file specified by a py.path LocalPath and read it back.

    Parameters
    ----------
    writer : callable bound to pandas object
        IO writing function (e.g. DataFrame.to_csv )
    reader : callable
        IO reading function (e.g. pd.read_csv )
    path : str, default None
        The path where the object is written and then read.

    Returns
    -------
    pandas object
        The original object that was serialized and then re-read.
    r   Nzpy.pathZ___localpath___)pytestZimportorskiplocalr	   )r   r   r   r   Z	LocalPathr   r   r   r   round_trip_localpath\   s    
*r    teststrNone)destr   c                 C  s   |f}d}d}| dkr.t j}d}||f}d}n| dkrntj}d}tj|d}t|}	t||_||	f}d}nR| d	kr~t	j
}nB| d
krt }n2| dkrtdj}n| dkrt }ntd|  |||d}
t|
||  W d   n1 s0    Y  dS )a  
    Write data to a compressed file.

    Parameters
    ----------
    compression : {'gzip', 'bz2', 'zip', 'xz', 'zstd'}
        The compression type to use.
    path : str
        The file path to write the data.
    data : str
        The data to write.
    dest : str, default "test"
        The destination file (for ZIP only)

    Raises
    ------
    ValueError : An invalid compression value was passed in.
    wbwritezipwwritestrtar)nameaddfilegzipbz2ZzstdZ	zstandardxzzUnrecognized compression type: )modeN)zipfileZipFiletarfileTarFileTarInfoioBytesIOlensizer-   GzipFiler   r   openr   
ValueErrorgetattr)compressionr   datar$   argsr0   methodZcompress_methodfilebytesfr   r   r   write_to_compressedy   s6    

rE   )N)N)N)r!   )
__future__r   r-   r6   r   r3   typingr   r   r   r   r1   Zpandas.compatr   r   Zpandas.compat._optionalr   Zpandasr   Zpandas._testing.contextsr	   Zpandas._typingr
   r   r   r   r   r   r    rE   r   r   r   r   <module>   s&   
 