a
    é´«j`  ã                   @  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r¤d 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   úR/var/www/html/laksyashrimp/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rŽtƒ }n2| dkr¢tdƒj}n| dkr²tƒ }ntd| › �ƒ‚|||d��}
t|
|ƒ|Ž  W d  ƒ n1 sð0    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&   
 ÿ