U
    ÎZj�  ã                	   @  sÈ   d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	 ddl
mZmZmZ ddlmZ ddlmZmZmZmZ dd	lmZ erŒdd
lmZ dddddœdd„Zdddddœdddddddœdd„ZdS )z orc compat é    )ÚannotationsN)Ú
ModuleType)ÚTYPE_CHECKINGÚAnyÚLiteral)ÚFilePathÚ
ReadBufferÚWriteBuffer)Úimport_optional_dependency)Úis_categorical_dtypeÚis_interval_dtypeÚis_period_dtypeÚis_unsigned_integer_dtype)Ú
get_handle)Ú	DataFramezFilePath | ReadBuffer[bytes]zlist[str] | Noner   )ÚpathÚcolumnsÚreturnc              
   K  sR   t dƒ}t| ddd��2}| |j¡}|jf d|i|—Ž ¡ W  5 Q R £ S Q R X dS )a€  
    Load an ORC object from the file path, returning a DataFrame.

    .. versionadded:: 1.0.0

    Parameters
    ----------
    path : str, path object, or file-like object
        String, path object (implementing ``os.PathLike[str]``), or file-like
        object implementing a binary ``read()`` function. The string could be a URL.
        Valid URL schemes include http, ftp, s3, and file. For file URLs, a host is
        expected. A local file could be:
        ``file://localhost/path/to/table.orc``.
    columns : list, default None
        If not None, only these columns will be read from the file.
    **kwargs
        Any additional kwargs are passed to pyarrow.

    Returns
    -------
    DataFrame

    Notes
    -----
    Before using this function you should read the :ref:`user guide about ORC <io.orc>`
    and :ref:`install optional dependencies <install.warn_orc>`.
    úpyarrow.orcÚrbF©Zis_textr   N)r
   r   ZORCFileÚhandleÚreadZ	to_pandas)r   r   ÚkwargsÚorcÚhandlesZorc_file© r   úP/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/pandas/io/orc.pyÚread_orc    s     r   Úpyarrow)ÚengineÚindexÚengine_kwargsz$FilePath | WriteBuffer[bytes] | NonezLiteral['pyarrow']zbool | Nonezdict[str, Any] | Nonezbytes | None)Údfr   r    r!   r"   r   c          
      C  s:  |dkr| j jd dk	}|dkr$i }| jD ],}t|ƒsNt|ƒsNt|ƒsNt|ƒr*tdƒ‚q*|dkrhtdƒ‚t	|dd�}t	dƒ}|dk}|r�t
 ¡ }|dk	sœt‚t|d	d
d��f}t|tƒsºt‚z"|j|jj| |d�|jf|Ž W n. tk
�r
 }	 ztdƒ|	‚W 5 d}	~	X Y nX W 5 Q R X |�r6t|t
jƒ�s.t‚| ¡ S dS )a„  
    Write a DataFrame to the ORC format.

    .. versionadded:: 1.5.0

    Parameters
    ----------
    df : DataFrame
        The dataframe to be written to ORC. Raises NotImplementedError
        if dtype of one or more columns is category, unsigned integers,
        intervals, periods or sparse.
    path : str, file-like object or None, default None
        If a string, it will be used as Root Directory path
        when writing a partitioned dataset. By file-like object,
        we refer to objects with a write() method, such as a file handle
        (e.g. via builtin open function). If path is None,
        a bytes object is returned.
    engine : str, default 'pyarrow'
        ORC library to use. Pyarrow must be >= 7.0.0.
    index : bool, optional
        If ``True``, include the dataframe's index(es) in the file output. If
        ``False``, they will not be written to the file.
        If ``None``, similar to ``infer`` the dataframe's index(es)
        will be saved. However, instead of being saved as values,
        the RangeIndex will be stored as a range in the metadata so it
        doesn't require much space and is faster. Other indexes will
        be included as columns in the file output.
    engine_kwargs : dict[str, Any] or None, default None
        Additional keyword arguments passed to :func:`pyarrow.orc.write_table`.

    Returns
    -------
    bytes if no path argument is provided else None

    Raises
    ------
    NotImplementedError
        Dtype of one or more columns is category, unsigned integers, interval,
        period or sparse.
    ValueError
        engine is not pyarrow.

    Notes
    -----
    * Before using this function you should read the
      :ref:`user guide about ORC <io.orc>` and
      :ref:`install optional dependencies <install.warn_orc>`.
    * This function requires `pyarrow <https://arrow.apache.org/docs/python/>`_
      library.
    * For supported dtypes please refer to `supported ORC features in Arrow
      <https://arrow.apache.org/docs/cpp/orc.html#data-types>`__.
    * Currently timezones in datetime columns are not preserved when a
      dataframe is converted into ORC files.
    Nr   z6The dtype of one or more columns is not supported yet.r   zengine must be 'pyarrow'z7.0.0)Úmin_versionr   ÚwbFr   )Zpreserve_index)r!   ÚnamesZdtypesr   r   r   r   ÚNotImplementedErrorÚ
ValueErrorr
   ÚioÚBytesIOÚAssertionErrorr   Ú
isinstancer   Zwrite_tableÚTableZfrom_pandasr   Ú	TypeErrorÚgetvalue)
r#   r   r    r!   r"   Zdtyper   Zwas_noner   Úer   r   r   Úto_orcG   sV    >
ÿþýüÿþýÿþr1   )N)N)Ú__doc__Ú
__future__r   r)   Útypesr   Útypingr   r   r   Zpandas._typingr   r   r	   Zpandas.compat._optionalr
   Zpandas.core.dtypes.commonr   r   r   r   Zpandas.io.commonr   Zpandasr   r   r1   r   r   r   r   Ú<module>   s$    ÿ) þú