o
    TZh                  	   @   s<  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/dedee deee  fddZ	d/dedee deee  f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 rd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 dee d*ee fd+d,Z-dee d*efd-d.Z.dS )0    )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ur|ng }|t v rtd| dt | j d| j d | t |< t||g D ]}|tv rAtd| dt|  d| d |t|< q*d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   S/var/www/html/lang_env/lib/python3.10/site-packages/datasets/formatting/__init__.py_register_formatter)   s   	
r!   unavailable_errorc                 C   s0   |du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_formatter@   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.returnc                 C   s   | t v rt |  S | S )ztIf the given format type is a known alias, then return its main type name. Otherwise return the type with no change.)r   )r   r   r   r    get_format_type_from_aliasl   s   r0   c                 K   sZ   t | } | tv rt|  di |S | tv rt|  tdtdd t D  d|  d)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 ''Nr   )r0   r   r   
ValueErrorlistkeys)r   Zformat_kwargsr   r   r    get_formattert   s   "r9   r1   )/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   	Exceptionr3   r!   r#   ZTORCH_AVAILABLEZtorch_formatterr*   r6   Z_torch_errorZTF_AVAILABLEZtf_formatterr,   Z	_tf_errorZJAX_AVAILABLEZjax_formatterr.   Z
_jax_errorr0   r9   r   r   r   r    <module>   s^   (






