"""simple docstring"""







from copy import deepcopy
from unittest.case import TestCase

import pytest

from datasets.arrow_dataset import Dataset
from datasets.features import Audio, ClassLabel, Features, Image, Sequence, Value
from datasets.info import DatasetInfo
from datasets.tasks import (
    AudioClassification,
    AutomaticSpeechRecognition,
    ImageClassification,
    LanguageModeling,
    QuestionAnsweringExtractive,
    Summarization,
    TextClassification,
    task_template_from_dict,
)
from datasets.utils.py_utils import asdict


UpperCamelCase_							:							Union[str, Any]				 =		{
    """id""": """5733be284776f41900661182""",
    """title""": """University_of_Notre_Dame""",
    """context""": """Architecturally, the school has a Catholic character. Atop the Main Building\'s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend \"Venite Ad Me Omnes\". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.""",
    """question""": """To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?""",
    """answers""": {"""text""": ["""Saint Bernadette Soubirous"""], """answer_start""": [515]},
}


@pytest.mark.parametrize(
    """task_cls"""		,      [
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]		,      )
def 	a__   (		UpperCAmelCase__							:      List[Any]      )->						Optional[Any]:
						UpperCAmelCase__       						=		task_cls()
						UpperCAmelCase__       						=		asdict(UpperCAmelCase__      )
						UpperCAmelCase__       						=		task_template_from_dict(UpperCAmelCase__      )
						assert task == reloaded


class       _lowercase		:

				def 							A			(  self							:     str  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		LanguageModeling(text_column="""input_text"""  )
										assert {"input_text": "text"} == task.column_mapping

				def 							A			(  self							:     Tuple  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		Features({"""text""": Value("""string"""  )}  )
										UpperCAmelCase__       						=		{"""text_column""": """input_text"""}
										UpperCAmelCase__       						=		LanguageModeling.from_dict(_lowercase  )
										assert "language-modeling" == task.task
										assert input_schema == task.input_schema


class       _lowercase		( __lowerCamelCase	):

				def 							A			(  self							:     List[str]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		sorted(["""pos""", """neg"""]  )

				def 							A			(  self							:     List[str]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TextClassification(text_column="""input_text"""							,     label_column="""input_label"""  )
										self.assertDictEqual({"""input_text""": """text""", """input_label""": """labels"""}							,     task.column_mapping  )

				def 							A			(  self							:     Dict  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		Features({"""text""": Value("""string"""  )}  )
										# Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
										UpperCAmelCase__       						=		Features({"""labels""": ClassLabel}  )
										UpperCAmelCase__       						=		{"""text_column""": """input_text""", """label_column""": """input_labels"""}
										UpperCAmelCase__       						=		TextClassification.from_dict(_lowercase  )
										self.assertEqual("""text-classification"""							,     task.task  )
										self.assertEqual(_lowercase							,     task.input_schema  )
										self.assertEqual(_lowercase							,     task.label_schema  )

				def 							A			(  self							:     Tuple  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TextClassification(text_column="""input_text"""							,     label_column="""input_label"""  )
										self.assertEqual(task.label_schema["""labels"""]							,     _lowercase  )
										UpperCAmelCase__       						=		task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels  )}  )  )
										self.assertEqual(task.label_schema["""labels"""]							,     ClassLabel(names=self.labels  )  )


class       _lowercase		( __lowerCamelCase	):

				def 							A			(  self							:     List[Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		QuestionAnsweringExtractive(
										    context_column="""input_context"""							,     question_column="""input_question"""							,     answers_column="""input_answers"""  )
										self.assertDictEqual(
										    {"""input_context""": """context""", """input_question""": """question""", """input_answers""": """answers"""}							,     task.column_mapping  )

				def 							A			(  self							:     int  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		Features({"""question""": Value("""string"""  ), """context""": Value("""string"""  )}  )
										UpperCAmelCase__       						=		Features(
										    {
										        """answers""": Sequence(
										            {
										                """text""": Value("""string"""  ),
										                """answer_start""": Value("""int32"""  ),
										            }  )
										    }  )
										UpperCAmelCase__       						=		{
										    """context_column""": """input_input_context""",
										    """question_column""": """input_question""",
										    """answers_column""": """input_answers""",
										}
										UpperCAmelCase__       						=		QuestionAnsweringExtractive.from_dict(_lowercase  )
										self.assertEqual("""question-answering-extractive"""							,     task.task  )
										self.assertEqual(_lowercase							,     task.input_schema  )
										self.assertEqual(_lowercase							,     task.label_schema  )


class       _lowercase		( __lowerCamelCase	):

				def 							A			(  self							:     int  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		Summarization(text_column="""input_text"""							,     summary_column="""input_summary"""  )
										self.assertDictEqual({"""input_text""": """text""", """input_summary""": """summary"""}							,     task.column_mapping  )

				def 							A			(  self							:     Tuple  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		Features({"""text""": Value("""string"""  )}  )
										UpperCAmelCase__       						=		Features({"""summary""": Value("""string"""  )}  )
										UpperCAmelCase__       						=		{"""text_column""": """input_text""", """summary_column""": """input_summary"""}
										UpperCAmelCase__       						=		Summarization.from_dict(_lowercase  )
										self.assertEqual("""summarization"""							,     task.task  )
										self.assertEqual(_lowercase							,     task.input_schema  )
										self.assertEqual(_lowercase							,     task.label_schema  )


class       _lowercase		( __lowerCamelCase	):

				def 							A			(  self							:     str  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		AutomaticSpeechRecognition(audio_column="""input_audio"""							,     transcription_column="""input_transcription"""  )
										self.assertDictEqual({"""input_audio""": """audio""", """input_transcription""": """transcription"""}							,     task.column_mapping  )

				def 							A			(  self							:     Optional[int]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		Features({"""audio""": Audio()}  )
										UpperCAmelCase__       						=		Features({"""transcription""": Value("""string"""  )}  )
										UpperCAmelCase__       						=		{
										    """audio_column""": """input_audio""",
										    """transcription_column""": """input_transcription""",
										}
										UpperCAmelCase__       						=		AutomaticSpeechRecognition.from_dict(_lowercase  )
										self.assertEqual("""automatic-speech-recognition"""							,     task.task  )
										self.assertEqual(_lowercase							,     task.input_schema  )
										self.assertEqual(_lowercase							,     task.label_schema  )


class       _lowercase		( __lowerCamelCase	):

				def 							A			(  self							:     List[Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		sorted(["""pos""", """neg"""]  )

				def 							A			(  self							:     Tuple  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		AudioClassification(audio_column="""input_audio"""							,     label_column="""input_label"""  )
										self.assertDictEqual({"""input_audio""": """audio""", """input_label""": """labels"""}							,     task.column_mapping  )

				def 							A			(  self							:     Union[str, Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		Features({"""audio""": Audio()}  )
										UpperCAmelCase__       						=		Features({"""labels""": ClassLabel}  )
										UpperCAmelCase__       						=		{
										    """audio_column""": """input_image""",
										    """label_column""": """input_label""",
										}
										UpperCAmelCase__       						=		AudioClassification.from_dict(_lowercase  )
										self.assertEqual("""audio-classification"""							,     task.task  )
										self.assertEqual(_lowercase							,     task.input_schema  )
										self.assertEqual(_lowercase							,     task.label_schema  )

				def 							A			(  self							:     Tuple  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		AudioClassification(audio_column="""input_audio"""							,     label_column="""input_label"""  )
										self.assertEqual(task.label_schema["""labels"""]							,     _lowercase  )
										UpperCAmelCase__       						=		task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels  )}  )  )
										self.assertEqual(task.label_schema["""labels"""]							,     ClassLabel(names=self.labels  )  )


class       _lowercase		( __lowerCamelCase	):

				def 							A			(  self							:     List[Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		sorted(["""pos""", """neg"""]  )

				def 							A			(  self							:     Optional[int]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		ImageClassification(image_column="""input_image"""							,     label_column="""input_label"""  )
										self.assertDictEqual({"""input_image""": """image""", """input_label""": """labels"""}							,     task.column_mapping  )

				def 							A			(  self							:     Union[str, Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		Features({"""image""": Image()}  )
										UpperCAmelCase__       						=		Features({"""labels""": ClassLabel}  )
										UpperCAmelCase__       						=		{
										    """image_column""": """input_image""",
										    """label_column""": """input_label""",
										}
										UpperCAmelCase__       						=		ImageClassification.from_dict(_lowercase  )
										self.assertEqual("""image-classification"""							,     task.task  )
										self.assertEqual(_lowercase							,     task.input_schema  )
										self.assertEqual(_lowercase							,     task.label_schema  )

				def 							A			(  self							:     Dict  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		ImageClassification(image_column="""input_image"""							,     label_column="""input_label"""  )
										self.assertEqual(task.label_schema["""labels"""]							,     _lowercase  )
										UpperCAmelCase__       						=		task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels  )}  )  )
										self.assertEqual(task.label_schema["""labels"""]							,     ClassLabel(names=self.labels  )  )


class       _lowercase		( __lowerCamelCase	):

				def 							A			(  self							:     Union[str, Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		DatasetInfo(task_templates=QuestionAnsweringExtractive()  )
										UpperCAmelCase__       						=		Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}							,     info=_lowercase  )
										assert isinstance(dataset.info.task_templates							,     _lowercase  )
										assert len(dataset.info.task_templates  ) == 1

										def keep_task(_lowercase							:     Any  ):
																return x

										def dont_keep_task(_lowercase							:     str  ):
																UpperCAmelCase__       						=		deepcopy(_lowercase  )
																UpperCAmelCase__       						=		0
																return out

										UpperCAmelCase__       						=		dataset.map(_lowercase  )
										assert mapped_dataset.info.task_templates == dataset.info.task_templates
										# reload from cache
										UpperCAmelCase__       						=		dataset.map(_lowercase  )
										assert mapped_dataset.info.task_templates == dataset.info.task_templates

										UpperCAmelCase__       						=		dataset.map(_lowercase  )
										assert mapped_dataset.info.task_templates == []
										# reload from cache
										UpperCAmelCase__       						=		dataset.map(_lowercase  )
										assert mapped_dataset.info.task_templates == []

				def 							A			(  self							:     Any  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		Features({"""text""": Value("""string"""  ), """label""": ClassLabel(names=("""pos""", """neg""")  )}  )
										UpperCAmelCase__       						=		TextClassification(text_column="""text"""							,     label_column="""label"""  )
										UpperCAmelCase__       						=		DatasetInfo(features=_lowercase							,     task_templates=_lowercase  )
										UpperCAmelCase__       						=		Dataset.from_dict({"""text""": ["""A sentence."""], """label""": ["""pos"""]}							,     info=_lowercase  )

										def process(_lowercase							:     Union[str, Any]  ):
																return example

										UpperCAmelCase__       						=		dataset.remove_columns("""label"""  )
										UpperCAmelCase__       						=		modified_dataset.map(_lowercase  )
										assert mapped_dataset.info.task_templates == []


"""simple docstring"""







from __future__ import annotations


def 	a__   (		UpperCAmelCase__							:      list      )->						int | float:
						UpperCAmelCase__       						=		sorted(UpperCAmelCase__      )
						UpperCAmelCase__       						=		len(UpperCAmelCase__      )
						UpperCAmelCase__       						=		length >> 1
						return (
						    (sorted_list[mid_index] + sorted_list[mid_index - 1]) / 2
						    if length % 2 == 0
						    else sorted_list[mid_index]
						)


def 	a__   (		)->						Dict:
						import doctest

						doctest.testmod()


if __name__ == "__main__":
						main()

