U
    -e)                     @   s2  U d dl mZmZmZmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZmZmZmZmZ ddlmZ eeZi Zeee ee f ed< i Zeee ef ed	< i Zeee ef ed
< d-eee eee  dddZd.eee eee  dddZeeddgd ee
dddgd eeddgd eeddgd eed ej rpddl!m"Z" ee"dddgd ne#d Z$ee$dddgd ej%rdd!l&m'Z' ee'd"d#gd ne#d$Z(ee(d"d#gd ej)rdd%l*m+Z+ ee+d&g d ne#d'Z,ee,d&g d ee ee d(d)d*Z-ee ed(d+d,Z.dS )/    )DictListOptionalType   )config)logging   )ArrowFormatterCustomFormatter	FormatterPandasFormatterPythonFormatterTensorFormatterformat_tablequery_table)NumpyFormatter_FORMAT_TYPES_FORMAT_TYPES_ALIASES!_FORMAT_TYPES_ALIASES_UNAVAILABLEN)formatter_clsformat_typealiasesc              
   C   s   |dk	r|ng }|t kr>td| dt | j d| j d | t |< t||g D ]6}|tkrtd| dt|  d| d |t|< qTdS )z}
    Register a Formatter object using a name and optional aliases.
    This function must be used on a Formatter class.
    NzOverwriting format type 'z' (z -> )zOverwriting format type alias ')r   loggerwarning__name__setr   )r   r   r   alias r   ]/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/datasets/formatting/__init__.py_register_formatter*   s    	r!   )unavailable_errorr   r   c                 C   s0   |dk	r|ng }t ||g D ]}| t|< qdS )z
    Register an unavailable Formatter object using a name and optional aliases.
    This function must be used on an Exception object that is raised when trying to get the unavailable formatter.
    N)r   r   )r"   r   r   r   r   r   r    _register_unavailable_formatterA   s    r#   python)r   arrowpaZpyarrownumpynpZpandaspdZcustom)TorchFormatterZtorchptZpytorchzCPyTorch needs to be installed to be able to return PyTorch tensors.)TFFormatterZ
tensorflowtfzITensorflow needs to be installed to be able to return Tensorflow tensors.)JaxFormatterZjaxz:JAX needs to be installed to be able to return JAX arrays.)r   returnc                 C   s   | t krt |  S | S dS )ztIf the given format type is a known alias, then return its main type name. Otherwise return the type with no change.N)r   )r   r   r   r    get_format_type_from_aliasm   s    r0   c                 K   s\   t | } | tkrt|  f |S | tkr0t|  n(tdtdd t D  d|  ddS )aF  
    Factory function to get a Formatter given its type name and keyword arguments.
    A formatter is an object that extracts and formats data from pyarrow table.
    It defines the formatting for rows, colums and batches.
    If the formatter for a given type name doesn't exist or is not available, an error is raised.
    z*Return type should be None or selected in c                 s   s   | ]}|d kr|V  qd S )Nr   ).0typer   r   r    	<genexpr>   s      z get_formatter.<locals>.<genexpr>z, but got ''N)r0   r   r   
ValueErrorlistkeys)r   Zformat_kwargsr   r   r    get_formatteru   s    
"r8   )N)N)/typingr   r   r   r    r   utilsr   Z
formattingr
   r   r   r   r   r   r   r   Znp_formatterr   Z
get_loggerr   r   r   str__annotations__r   r   	Exceptionr2   r!   r#   ZTORCH_AVAILABLEZtorch_formatterr*   r5   Z_torch_errorZTF_AVAILABLEZtf_formatterr,   Z	_tf_errorZJAX_AVAILABLEZjax_formatterr.   Z
_jax_errorr0   r8   r   r   r   r    <module>   sV    (

 
   

