"""simple docstring"""







import unittest

from transformers import ElectraConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import (
	    MODEL_FOR_PRETRAINING_MAPPING,
	    ElectraForCausalLM,
	    ElectraForMaskedLM,
	    ElectraForMultipleChoice,
	    ElectraForPreTraining,
	    ElectraForQuestionAnswering,
	    ElectraForSequenceClassification,
	    ElectraForTokenClassification,
	    ElectraModel,
	)
	from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST

class 						UpperCamelCase     :



				def __init__(self							: List[str]      ,    _A							: Any      ,    _A							: Union[str, Any]=13      ,    _A							: Optional[Any]=7      ,    _A							: List[str]=True      ,    _A							: Optional[int]=True      ,    _A							: List[str]=True      ,    _A							: Dict=True      ,    _A							: Tuple=99      ,    _A							: Optional[Any]=32      ,    _A							: List[Any]=5      ,    _A							: str=4      ,    _A							: Optional[int]=37      ,    _A							: Any="gelu"      ,    _A							: Optional[Any]=0.1      ,    _A							: Union[str, Any]=0.1      ,    _A							: Optional[Any]=5_12      ,    _A							: Optional[int]=16      ,    _A							: Optional[Any]=2      ,    _A							: Dict=0.02      ,    _A							: List[str]=3      ,    _A							: Any=4      ,    _A							: int=None      ,    )       ->      int:
					__snake_case     :				Any 						=					parent
					__snake_case     :				Any 						=					batch_size
					__snake_case     :				Optional[Any] 						=					seq_length
					__snake_case     :				Union[str, Any] 						=					is_training
					__snake_case     :				Optional[int] 						=					use_input_mask
					__snake_case     :				Optional[Any] 						=					use_token_type_ids
					__snake_case     :				Tuple 						=					use_labels
					__snake_case     :				Union[str, Any] 						=					vocab_size
					__snake_case     :				Optional[int] 						=					hidden_size
					__snake_case     :				Dict 						=					num_hidden_layers
					__snake_case     :				Optional[int] 						=					num_attention_heads
					__snake_case     :				List[Any] 						=					intermediate_size
					__snake_case     :				Any 						=					hidden_act
					__snake_case     :				Dict 						=					hidden_dropout_prob
					__snake_case     :				str 						=					attention_probs_dropout_prob
					__snake_case     :				int 						=					max_position_embeddings
					__snake_case     :				Optional[int] 						=					type_vocab_size
					__snake_case     :				Dict 						=					type_sequence_label_size
					__snake_case     :				Union[str, Any] 						=					initializer_range
					__snake_case     :				Tuple 						=					num_labels
					__snake_case     :				Any 						=					num_choices
					__snake_case     :				List[Any] 						=					scope



				def    _lowercase	(self							: Dict)       ->      List[str]:
					__snake_case     :				Tuple 						=					ids_tensor([self.batch_size, self.seq_length]      ,    self.vocab_size)

					__snake_case     :				Any 						=					None
					if self.use_input_mask:
						__snake_case     :				Tuple 						=					random_attention_mask([self.batch_size, self.seq_length])

					__snake_case     :				List[str] 						=					None
					if self.use_token_type_ids:
						__snake_case     :				Any 						=					ids_tensor([self.batch_size, self.seq_length]      ,    self.type_vocab_size)

					__snake_case     :				List[Any] 						=					None
					__snake_case     :				Tuple 						=					None
					__snake_case     :				Any 						=					None
					if self.use_labels:
						__snake_case     :				Any 						=					ids_tensor([self.batch_size]      ,    self.type_sequence_label_size)
						__snake_case     :				Optional[int] 						=					ids_tensor([self.batch_size, self.seq_length]      ,    self.num_labels)
						__snake_case     :				Dict 						=					ids_tensor([self.batch_size]      ,    self.num_choices)
						__snake_case     :				List[Any] 						=					ids_tensor([self.batch_size, self.seq_length]      ,    1)

					__snake_case     :				Any 						=					self.get_config()

					return (
					    config,
					    input_ids,
					    token_type_ids,
					    input_mask,
					    sequence_labels,
					    token_labels,
					    choice_labels,
					    fake_token_labels,
					)



				def    _lowercase	(self							: Optional[int])       ->      List[Any]:
					return ElectraConfig(
					    vocab_size=self.vocab_size      ,    hidden_size=self.hidden_size      ,    num_hidden_layers=self.num_hidden_layers      ,    num_attention_heads=self.num_attention_heads      ,    intermediate_size=self.intermediate_size      ,    hidden_act=self.hidden_act      ,    hidden_dropout_prob=self.hidden_dropout_prob      ,    attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,    max_position_embeddings=self.max_position_embeddings      ,    type_vocab_size=self.type_vocab_size      ,    is_decoder=_A      ,    initializer_range=self.initializer_range      ,    )



				def    _lowercase	(self							: Optional[Any])       ->      Union[str, Any]:
					(
					    (
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							
					)     :				List[str] 						=					self.prepare_config_and_inputs()

					__snake_case     :				Any 						=					True
					__snake_case     :				Tuple 						=					floats_tensor([self.batch_size, self.seq_length, self.hidden_size])
					__snake_case     :				int 						=					ids_tensor([self.batch_size, self.seq_length]      ,    vocab_size=2)

					return (
					    config,
					    input_ids,
					    token_type_ids,
					    input_mask,
					    sequence_labels,
					    token_labels,
					    choice_labels,
					    encoder_hidden_states,
					    encoder_attention_mask,
					)



				def    _lowercase	(self							: str      ,    _A							: Tuple      ,    _A							: Dict      ,    _A							: List[str]      ,    _A							: List[str]      ,    _A							: Optional[Any]      ,    _A							: Optional[int]      ,    _A							: Tuple      ,    _A							: Dict      ,    )       ->      Optional[Any]:
					__snake_case     :				Union[str, Any] 						=					ElectraModel(config=_A)
					model.to(_A)
					model.eval()
					__snake_case     :				int 						=					model(_A      ,    attention_mask=_A      ,    token_type_ids=_A)
					__snake_case     :				List[Any] 						=					model(_A      ,    token_type_ids=_A)
					__snake_case     :				Tuple 						=					model(_A)
					self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.hidden_size))



				def    _lowercase	(self							: int      ,    _A							: Dict      ,    _A							: List[Any]      ,    _A							: Any      ,    _A							: Dict      ,    _A							: Optional[int]      ,    _A							: List[str]      ,    _A							: Union[str, Any]      ,    _A							: Optional[int]      ,    _A							: Tuple      ,    )       ->      Tuple:
					__snake_case     :				Union[str, Any] 						=					True
					__snake_case     :				Optional[Any] 						=					ElectraModel(_A)
					model.to(_A)
					model.eval()
					__snake_case     :				int 						=					model(
					    _A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    encoder_hidden_states=_A      ,    encoder_attention_mask=_A      ,    )
					__snake_case     :				Union[str, Any] 						=					model(
					    _A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    encoder_hidden_states=_A      ,    )
					__snake_case     :				List[str] 						=					model(_A      ,    attention_mask=_A      ,    token_type_ids=_A)
					self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.hidden_size))



				def    _lowercase	(self							: Optional[int]      ,    _A							: Tuple      ,    _A							: Optional[int]      ,    _A							: Optional[int]      ,    _A							: List[str]      ,    _A							: int      ,    _A							: Optional[Any]      ,    _A							: Optional[Any]      ,    _A							: Optional[int]      ,    )       ->      int:
					__snake_case     :				List[Any] 						=					ElectraForMaskedLM(config=_A)
					model.to(_A)
					model.eval()
					__snake_case     :				Optional[int] 						=					model(_A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A)
					self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.vocab_size))



				def    _lowercase	(self							: Optional[Any]      ,    _A							: Optional[int]      ,    _A							: Tuple      ,    _A							: Optional[int]      ,    _A							: List[str]      ,    _A							: str      ,    _A							: Optional[Any]      ,    _A							: Union[str, Any]      ,    _A							: List[Any]      ,    _A							: int      ,    )       ->      int:
					__snake_case     :				Optional[Any] 						=					ElectraForCausalLM(config=_A)
					model.to(_A)
					model.eval()
					__snake_case     :				List[str] 						=					model(_A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A)
					self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.vocab_size))



				def    _lowercase	(self							: Optional[Any]      ,    _A							: List[Any]      ,    _A							: Tuple      ,    _A							: str      ,    _A							: Dict      ,    _A							: str      ,    _A							: Optional[Any]      ,    _A							: int      ,    _A							: Union[str, Any]      ,    )       ->      Optional[Any]:
					__snake_case     :				Optional[int] 						=					self.num_labels
					__snake_case     :				Optional[int] 						=					ElectraForTokenClassification(config=_A)
					model.to(_A)
					model.eval()
					__snake_case     :				Optional[Any] 						=					model(_A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A)
					self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.num_labels))



				def    _lowercase	(self							: List[Any]      ,    _A							: Dict      ,    _A							: Union[str, Any]      ,    _A							: Tuple      ,    _A							: Any      ,    _A							: List[str]      ,    _A							: Any      ,    _A							: str      ,    _A							: Tuple      ,    )       ->      List[str]:
					__snake_case     :				Optional[int] 						=					self.num_labels
					__snake_case     :				Optional[int] 						=					ElectraForPreTraining(config=_A)
					model.to(_A)
					model.eval()
					__snake_case     :				Optional[int] 						=					model(_A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A)
					self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length))



				def    _lowercase	(self							: Optional[Any]      ,    _A							: Union[str, Any]      ,    _A							: Any      ,    _A							: List[Any]      ,    _A							: Dict      ,    _A							: Union[str, Any]      ,    _A							: Dict      ,    _A							: List[str]      ,    _A							: Optional[int]      ,    )       ->      Any:
					__snake_case     :				int 						=					self.num_labels
					__snake_case     :				Tuple 						=					ElectraForSequenceClassification(_A)
					model.to(_A)
					model.eval()
					__snake_case     :				List[Any] 						=					model(_A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A)
					self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_labels))



				def    _lowercase	(self							: Dict      ,    _A							: Tuple      ,    _A							: Optional[Any]      ,    _A							: Dict      ,    _A							: Optional[Any]      ,    _A							: Dict      ,    _A							: Tuple      ,    _A							: Tuple      ,    _A							: List[str]      ,    )       ->      str:
					__snake_case     :				Dict 						=					ElectraForQuestionAnswering(config=_A)
					model.to(_A)
					model.eval()
					__snake_case     :				Optional[Any] 						=					model(
					    _A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    start_positions=_A      ,    end_positions=_A      ,    )
					self.parent.assertEqual(result.start_logits.shape      ,    (self.batch_size, self.seq_length))
					self.parent.assertEqual(result.end_logits.shape      ,    (self.batch_size, self.seq_length))



				def    _lowercase	(self							: Tuple      ,    _A							: Dict      ,    _A							: Union[str, Any]      ,    _A							: int      ,    _A							: Optional[int]      ,    _A							: Dict      ,    _A							: List[str]      ,    _A							: str      ,    _A							: Dict      ,    )       ->      str:
					__snake_case     :				str 						=					self.num_choices
					__snake_case     :				Tuple 						=					ElectraForMultipleChoice(config=_A)
					model.to(_A)
					model.eval()
					__snake_case     :				Optional[Any] 						=					input_ids.unsqueeze(1).expand(-1      ,    self.num_choices      ,    -1).contiguous()
					__snake_case     :				Union[str, Any] 						=					token_type_ids.unsqueeze(1).expand(-1      ,    self.num_choices      ,    -1).contiguous()
					__snake_case     :				int 						=					input_mask.unsqueeze(1).expand(-1      ,    self.num_choices      ,    -1).contiguous()
					__snake_case     :				int 						=					model(
					    _A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A      ,    )
					self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_choices))






				def    _lowercase	(self							: int)       ->      Any:
					__snake_case     :				Dict 						=					self.prepare_config_and_inputs()
					(
					    (
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							(
					    __snake_case
					)						,							
					)     :				str 						=					config_and_inputs
					__snake_case     :				Union[str, Any] 						=					{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
					return config, inputs_dict







@require_torch
class 						UpperCamelCase     (       lowercase ,      lowercase ,      unittest.TestCase		):
				UpperCAmelCase							: List[Any]       =						(
				    (
				        ElectraModel,
				        ElectraForPreTraining,
				        ElectraForMaskedLM,
				        ElectraForCausalLM,
				        ElectraForMultipleChoice,
				        ElectraForTokenClassification,
				        ElectraForSequenceClassification,
				        ElectraForQuestionAnswering,
				    )
				    if is_torch_available()
				    else ()
				)
				UpperCAmelCase							: List[Any]       =						(
				    {
				        """feature-extraction""": ElectraModel,
				        """fill-mask""": ElectraForMaskedLM,
				        """question-answering""": ElectraForQuestionAnswering,
				        """text-classification""": ElectraForSequenceClassification,
				        """text-generation""": ElectraForCausalLM,
				        """token-classification""": ElectraForTokenClassification,
				        """zero-shot""": ElectraForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				UpperCAmelCase							: Tuple       =						True



				def    _lowercase	(self							: Union[str, Any]      ,    _A							: List[str]      ,    _A							: Union[str, Any]      ,    _A							: List[str]=False)       ->      str:
					__snake_case     :				List[Any] 						=					super()._prepare_for_class(_A      ,    _A      ,    return_labels=_A)

					if return_labels:
						if model_class in get_values(_A):
							__snake_case     :				List[Any] 						=					torch.zeros(
							    (self.model_tester.batch_size, self.model_tester.seq_length)      ,    dtype=torch.long      ,    device=_A)
					return inputs_dict



				def    _lowercase	(self							: int)       ->      Optional[int]:
					__snake_case     :				Optional[Any] 						=					ElectraModelTester(self)
					__snake_case     :				Union[str, Any] 						=					ConfigTester(self      ,    config_class=_A      ,    hidden_size=37)



				def    _lowercase	(self							: Union[str, Any])       ->      str:
					self.config_tester.run_common_tests()



				def    _lowercase	(self							: Optional[Any])       ->      Optional[int]:
					__snake_case     :				Optional[Any] 						=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_electra_model(*_A)



				def    _lowercase	(self							: Tuple)       ->      Optional[int]:
					__snake_case     :				Tuple 						=					self.model_tester.prepare_config_and_inputs_for_decoder()
					self.model_tester.create_and_check_electra_model_as_decoder(*_A)



				def    _lowercase	(self							: int)       ->      Any:
					__snake_case     :				Optional[Any] 						=					self.model_tester.prepare_config_and_inputs()
					for type in ["absolute", "relative_key", "relative_key_query"]:
						__snake_case     :				Any 						=					type
						self.model_tester.create_and_check_electra_model(*_A)



				def    _lowercase	(self							: List[Any])       ->      Tuple:
					__snake_case     :				Tuple 						=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_electra_for_masked_lm(*_A)



				def    _lowercase	(self							: Dict)       ->      Any:
					__snake_case     :				Any 						=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_electra_for_token_classification(*_A)



				def    _lowercase	(self							: Tuple)       ->      Union[str, Any]:
					__snake_case     :				Optional[Any] 						=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_electra_for_pretraining(*_A)



				def    _lowercase	(self							: Tuple)       ->      Dict:
					__snake_case     :				int 						=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_electra_for_sequence_classification(*_A)



				def    _lowercase	(self							: Any)       ->      Optional[int]:
					__snake_case     :				Tuple 						=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_electra_for_question_answering(*_A)



				def    _lowercase	(self							: str)       ->      List[str]:
					__snake_case     :				Any 						=					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_electra_for_multiple_choice(*_A)



				@slow
				def    _lowercase	(self							: str)       ->      List[str]:
					for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						__snake_case     :				Dict 						=					ElectraModel.from_pretrained(_A)
						self.assertIsNotNone(_A)






				def    _lowercase	(self							: List[Any])       ->      Optional[Any]:
					__snake_case     :				Optional[Any] 						=					self.model_tester.prepare_config_and_inputs_for_decoder()
					self.model_tester.create_and_check_electra_for_causal_lm(*_A)







@require_torch
class 						UpperCamelCase     (       unittest.TestCase		):



				@slow
				def    _lowercase	(self							: str)       ->      int:
					__snake_case     :				Any 						=					ElectraModel.from_pretrained('google/electra-small-discriminator')
					__snake_case     :				Any 						=					torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]])
					__snake_case     :				Tuple 						=					torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
					__snake_case     :				Tuple 						=					model(_A      ,    attention_mask=_A)[0]
					__snake_case     :				List[str] 						=					torch.Size((1, 11, 2_56))
					self.assertEqual(output.shape      ,    _A)
					__snake_case     :				Optional[Any] 						=					torch.tensor(
					    [[[0.4_471, 0.6_821, -0.3_265], [0.4_627, 0.5_255, -0.3_668], [0.4_532, 0.3_313, -0.4_344]]])

					self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,    _A      ,    atol=1E-4))






"""simple docstring"""







import dataclasses
import enum
import functools
import math
import re

# The following script is adapted from the script of TaPas.
# Original: https://github.com/google-research/tapas/master/wikisql_utils.py
from typing import Any, List, Text


_a	:	List[Any]=					"none"
_a	:	List[str]=					"none"
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Optional[int]     ,				UpperCAmelCase_       :							Tuple    )				->     Dict:

	'''simple docstring'''





	__snake_case     :				int 						=					value.split(UpperCAmelCase_    )
	return len(UpperCAmelCase_    ) > 1 and any((len(UpperCAmelCase_    ) == 3 for x in split)    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Optional[Any]    )				->     Tuple:

	'''simple docstring'''





	if isinstance(UpperCAmelCase_     ,				UpperCAmelCase_    ):
		return value
	if isinstance(UpperCAmelCase_     ,				UpperCAmelCase_    ):
		return float(UpperCAmelCase_    )
	if not isinstance(UpperCAmelCase_     ,				UpperCAmelCase_    ):
		raise ValueError('Argument value is not a string. Can\'t parse it as float'    )
	__snake_case     :				Any 						=					value

	try:
		# Example: 1,000.7
		if "." in sanitized and "," in sanitized:
			return float(sanitized.replace(','     ,				''    )    )
		# 1,000
		if "," in sanitized and _split_thousands(','     ,				UpperCAmelCase_    ):
			return float(sanitized.replace(','     ,				''    )    )
		# 5,5556
		if "," in sanitized and sanitized.count(','    ) == 1 and not _split_thousands(','     ,				UpperCAmelCase_    ):
			return float(sanitized.replace(','     ,				'.'    )    )
		# 0.0.0.1
		if sanitized.count('.'    ) > 1:
			return float(sanitized.replace('.'     ,				''    )    )
		# 0,0,0,1
		if sanitized.count(','    ) > 1:
			return float(sanitized.replace(','     ,				''    )    )
		return float(UpperCAmelCase_    )
	except ValueError:
		# Avoid adding the sanitized value in the error message.
		raise ValueError('Unable to convert value to float'    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							str    )				->     Any:

	'''simple docstring'''





	if answer is None:
		return None
	try:
		__snake_case     :				Dict 						=					convert_to_float(UpperCAmelCase_    )
		if isinstance(UpperCAmelCase_     ,				UpperCAmelCase_    ) and math.isnan(UpperCAmelCase_    ):
			return None
		return value
	except ValueError:
		return answer.lower()


_a	:	Union[str, Any]=					{
    "text": lambda x: x,
    "real": convert_to_float,
}

class 						UpperCamelCase     (       enum.Enum		):
				UpperCAmelCase							: int       =						0
				UpperCAmelCase							: Optional[Any]       =						1
				UpperCAmelCase							: List[Any]       =						2
				UpperCAmelCase							: Dict       =						3
				UpperCAmelCase							: Union[str, Any]       =						4
				UpperCAmelCase							: int       =						5







class 						UpperCamelCase     (       enum.Enum		):
				UpperCAmelCase							: List[str]       =						0
				UpperCAmelCase							: List[str]       =						1
				UpperCAmelCase							: int       =						2







@dataclasses.dataclass
class 						UpperCamelCase     :
				UpperCAmelCase							: Text
				UpperCAmelCase							: _Operator
				UpperCAmelCase							: Any







_a	:	Union[str, Any]=					re.compile(R"\w+|[^\w\s]+", re.UNICODE | re.MULTILINE | re.DOTALL)
def     __UpperCAmelCase							(       UpperCAmelCase_       :							List[str]    )				->     Optional[Any]:

	'''simple docstring'''





	return list(_TOKENIZER.findall(x.lower()    )    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Tuple     ,				UpperCAmelCase_       :							int     ,				UpperCAmelCase_       :							List[Any]    )				->     List[str]:

	'''simple docstring'''





	if operator == _Operator.EQUALS:
		return src == tgt
	elif operator == _Operator.GREATER:
		return src > tgt
	elif operator == _Operator.LESSER:
		return src < tgt
	raise ValueError(F"Unknown operator: {operator}"    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							List[Any]     ,				UpperCAmelCase_       :							int     ,				UpperCAmelCase_       :							Optional[Any]    )				->     Dict:

	'''simple docstring'''





	__snake_case     :				Optional[Any] 						=					table['types']
	return _TYPE_CONVERTER[types[column]](UpperCAmelCase_    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							List[Any]    )				->     str:

	'''simple docstring'''





	return isinstance(UpperCAmelCase_     ,				UpperCAmelCase_    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Dict     ,				UpperCAmelCase_       :							Union[str, Any]     ,				UpperCAmelCase_       :							int    )				->     List[Any]:

	'''simple docstring'''





	for cond in conditions:
		__snake_case     :				Any 						=					row[cond.column]

		__snake_case     :				Tuple 						=					_parse_value(UpperCAmelCase_     ,				cond.column     ,				cond.cmp_value    )

		if _is_string(UpperCAmelCase_    ) and _is_string(UpperCAmelCase_    ):
			__snake_case     :				str 						=					_normalize_for_match(UpperCAmelCase_    )
			__snake_case     :				Dict 						=					_normalize_for_match(UpperCAmelCase_    )

		if not isinstance(UpperCAmelCase_     ,				type(UpperCAmelCase_    )    ):
			raise ValueError('Type difference {} != {}'.format(type(UpperCAmelCase_    )     ,				type(UpperCAmelCase_    )    )    )

		if not _compare(cond.operator     ,				UpperCAmelCase_     ,				UpperCAmelCase_    ):
			return False
	return True
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Union[str, Any]     ,				UpperCAmelCase_       :							List[str]     ,				UpperCAmelCase_       :							Optional[int]    )				->     Dict:

	'''simple docstring'''





	if not answer_coordinates:
		if aggregation_op == _Aggregation.COUNT:
			return 0.0
		else:
			return EMPTY_ANSWER_AGG

    # Count can support non numeric answers.
	if aggregation_op == _Aggregation.COUNT:
		return float(len(UpperCAmelCase_    )    )

	# If we have just one answer, if float returns it or try a conversion.
	__snake_case     :				Any 						=					[table['rows'][i][j] for (i, j) in answer_coordinates]
	if len(UpperCAmelCase_    ) == 1:
		try:
			return convert_to_float(values[0]    )
		except ValueError as e:
			if aggregation_op != _Aggregation.NONE:
				raise e

	if aggregation_op == _Aggregation.NONE:
		return None

	# Other aggregation only support numeric values. Bail out if we have strings.
	if not all((isinstance(UpperCAmelCase_     ,				(int, float)    ) for v in values)    ):
		return None

	if aggregation_op == _Aggregation.SUM:
		return float(sum(UpperCAmelCase_    )    )
	elif aggregation_op == _Aggregation.AVERAGE:
		return sum(UpperCAmelCase_    ) / len(UpperCAmelCase_    )
	else:
		raise ValueError(F"Unknown aggregation: {aggregation_op}"    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Optional[Any]     ,				UpperCAmelCase_       :							int    )				->     str:

	'''simple docstring'''





	__snake_case     :				int 						=					sql_query['agg']
	if aggregation_op_index >= 3:
		__snake_case     :				Optional[Any] 						=					_Aggregation(UpperCAmelCase_    )
	else:
		__snake_case     :				Any 						=					_Aggregation.NONE

	__snake_case     :				Dict 						=					sql_query['sel']
	__snake_case     :				Dict 						=					[
	    _Condition(UpperCAmelCase_     ,				_Operator(UpperCAmelCase_    )     ,				UpperCAmelCase_    )
	    for column, operator, cmp_value in zip(
	        sql_query['conds']['column_index']     ,				sql_query['conds']['operator_index']     ,				sql_query['conds']['condition']    )
	]

	__snake_case     :				str 						=					[]
	for row in range(len(table['rows']    )    ):
		if _respect_conditions(UpperCAmelCase_     ,				table['rows'][row]     ,				UpperCAmelCase_    ):
			indices.append((row, target_column)    )

	if not indices:
		return [], aggregation_op

	if len(UpperCAmelCase_    ) == 1:
		return indices, aggregation_op

	# Parsing of MIN/MAX.
	if aggregation_op_index in (1, 2):
		__snake_case     :				Union[str, Any] 						=					{2: min, 1: max}
		__snake_case     :				Optional[Any] 						=					[(table['rows'][i][j], index) for index, (i, j) in enumerate(UpperCAmelCase_    )]
		__snake_case     :				Tuple 						=					functools.reduce(operators[sql_query['agg']]     ,				UpperCAmelCase_    )

		__snake_case     :				str 						=					[indices[reduced[1]]]
		return ret, _Aggregation.NONE

	return indices, aggregation_op
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Dict     ,				UpperCAmelCase_       :							List[Any]     ,				UpperCAmelCase_       :							Any    )				->     Optional[Any]:

	'''simple docstring'''





	if float_answer is not None:
		return [str(UpperCAmelCase_    )]
	return [str(table['real_rows'][r][c]    ) for r, c in answer_coordinates]

def     __UpperCAmelCase							(       UpperCAmelCase_       :							int     ,				UpperCAmelCase_       :							Tuple    )				->     List:

	'''simple docstring'''





	__snake_case						,							__snake_case     :				List[Any] 						=					_get_answer_coordinates(UpperCAmelCase_     ,				UpperCAmelCase_    )
	__snake_case     :				Optional[int] 						=					_get_float_answer(UpperCAmelCase_     ,				UpperCAmelCase_     ,				UpperCAmelCase_    )
	__snake_case     :				Union[str, Any] 						=					_get_answer_text(UpperCAmelCase_     ,				UpperCAmelCase_     ,				UpperCAmelCase_    )
	# keep the original data the same with TaPas
	if len(UpperCAmelCase_    ) == 0:
		__snake_case     :				List[str] 						=					[EMPTY_ANSWER]
	return answer_text





