






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


a	: Tuple      =				{
    "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        lowerCamelCase__   (					__lowerCamelCase    :  List[str]	):
  __UpperCAmelCase							:			Optional[Any]     =						task_cls()
  __UpperCAmelCase							:			int     =						asdict(__lowerCamelCase	)
  __UpperCAmelCase							:			str     =						task_template_from_dict(__lowerCamelCase	)
  assert task == reloaded
class 					a					:



      """simple docstring"""


      def 			UpperCAmelCase   (   self      :    Tuple      )							->   Optional[int]:
        __UpperCAmelCase							:			Dict     =						LanguageModeling(text_column="""input_text"""      )
        assert {"input_text": "text"} == task.column_mapping




      def 			UpperCAmelCase   (   self      :    str      )							->   Any:
        __UpperCAmelCase							:			int     =						Features({"""text""": Value("""string"""      )}      )
        __UpperCAmelCase							:			List[Any]     =						{"""text_column""": """input_text"""}
        __UpperCAmelCase							:			str     =						LanguageModeling.from_dict(__lowercase      )
        assert "language-modeling" == task.task
        assert input_schema == task.input_schema


class 					a					(				lowercase__     ):



      """simple docstring"""


      def 			UpperCAmelCase   (   self      :    Dict      )							->   Dict:
        __UpperCAmelCase							:			int     =						sorted(["""pos""", """neg"""]      )
      def 			UpperCAmelCase   (   self      :    Tuple      )							->   int:
        __UpperCAmelCase							:			Optional[int]     =						TextClassification(text_column="""input_text"""	,   label_column="""input_label"""      )
        self.assertDictEqual({"""input_text""": """text""", """input_label""": """labels"""}	,   task.column_mapping      )
      def 			UpperCAmelCase   (   self      :    Optional[int]      )							->   List[Any]:
        __UpperCAmelCase							:			str     =						Features({"""text""": Value("""string"""      )}      )
        # Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
        __UpperCAmelCase							:			Union[str, Any]     =						Features({"""labels""": ClassLabel}      )
        __UpperCAmelCase							:			Optional[Any]     =						{"""text_column""": """input_text""", """label_column""": """input_labels"""}
        __UpperCAmelCase							:			Any     =						TextClassification.from_dict(__lowercase      )
        self.assertEqual("""text-classification"""	,   task.task      )
        self.assertEqual(__lowercase	,   task.input_schema      )
        self.assertEqual(__lowercase	,   task.label_schema      )




      def 			UpperCAmelCase   (   self      :    Optional[Any]      )							->   Any:
        __UpperCAmelCase							:			str     =						TextClassification(text_column="""input_text"""	,   label_column="""input_label"""      )
        self.assertEqual(task.label_schema["""labels"""]	,   __lowercase      )
        __UpperCAmelCase							:			List[str]     =						task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels      )}      )      )
        self.assertEqual(task.label_schema["""labels"""]	,   ClassLabel(names=self.labels      )      )


class 					a					(				lowercase__     ):



      """simple docstring"""


      def 			UpperCAmelCase   (   self      :    Union[str, Any]      )							->   Union[str, Any]:
        __UpperCAmelCase							:			Any     =						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 			UpperCAmelCase   (   self      :    Any      )							->   Tuple:
        __UpperCAmelCase							:			Union[str, Any]     =						Features({"""question""": Value("""string"""      ), """context""": Value("""string"""      )}      )
        __UpperCAmelCase							:			int     =						Features(
            {
                """answers""": Sequence(
                    {
                        """text""": Value("""string"""      ),
                        """answer_start""": Value("""int32"""      ),
                    }      )
            }      )
        __UpperCAmelCase							:			Any     =						{
            """context_column""": """input_input_context""",
            """question_column""": """input_question""",
            """answers_column""": """input_answers""",
        }
        __UpperCAmelCase							:			str     =						QuestionAnsweringExtractive.from_dict(__lowercase      )
        self.assertEqual("""question-answering-extractive"""	,   task.task      )
        self.assertEqual(__lowercase	,   task.input_schema      )
        self.assertEqual(__lowercase	,   task.label_schema      )


class 					a					(				lowercase__     ):



      """simple docstring"""


      def 			UpperCAmelCase   (   self      :    List[Any]      )							->   List[str]:
        __UpperCAmelCase							:			Optional[Any]     =						Summarization(text_column="""input_text"""	,   summary_column="""input_summary"""      )
        self.assertDictEqual({"""input_text""": """text""", """input_summary""": """summary"""}	,   task.column_mapping      )




      def 			UpperCAmelCase   (   self      :    Optional[Any]      )							->   Union[str, Any]:
        __UpperCAmelCase							:			int     =						Features({"""text""": Value("""string"""      )}      )
        __UpperCAmelCase							:			Tuple     =						Features({"""summary""": Value("""string"""      )}      )
        __UpperCAmelCase							:			Tuple     =						{"""text_column""": """input_text""", """summary_column""": """input_summary"""}
        __UpperCAmelCase							:			int     =						Summarization.from_dict(__lowercase      )
        self.assertEqual("""summarization"""	,   task.task      )
        self.assertEqual(__lowercase	,   task.input_schema      )
        self.assertEqual(__lowercase	,   task.label_schema      )


class 					a					(				lowercase__     ):



      """simple docstring"""


      def 			UpperCAmelCase   (   self      :    List[Any]      )							->   int:
        __UpperCAmelCase							:			Union[str, Any]     =						AutomaticSpeechRecognition(audio_column="""input_audio"""	,   transcription_column="""input_transcription"""      )
        self.assertDictEqual({"""input_audio""": """audio""", """input_transcription""": """transcription"""}	,   task.column_mapping      )




      def 			UpperCAmelCase   (   self      :    str      )							->   int:
        __UpperCAmelCase							:			List[Any]     =						Features({"""audio""": Audio()}      )
        __UpperCAmelCase							:			Union[str, Any]     =						Features({"""transcription""": Value("""string"""      )}      )
        __UpperCAmelCase							:			Any     =						{
            """audio_column""": """input_audio""",
            """transcription_column""": """input_transcription""",
        }
        __UpperCAmelCase							:			Union[str, Any]     =						AutomaticSpeechRecognition.from_dict(__lowercase      )
        self.assertEqual("""automatic-speech-recognition"""	,   task.task      )
        self.assertEqual(__lowercase	,   task.input_schema      )
        self.assertEqual(__lowercase	,   task.label_schema      )


class 					a					(				lowercase__     ):



      """simple docstring"""


      def 			UpperCAmelCase   (   self      :    Optional[int]      )							->   str:
        __UpperCAmelCase							:			Optional[int]     =						sorted(["""pos""", """neg"""]      )
      def 			UpperCAmelCase   (   self      :    Optional[int]      )							->   List[str]:
        __UpperCAmelCase							:			str     =						AudioClassification(audio_column="""input_audio"""	,   label_column="""input_label"""      )
        self.assertDictEqual({"""input_audio""": """audio""", """input_label""": """labels"""}	,   task.column_mapping      )
      def 			UpperCAmelCase   (   self      :    Optional[Any]      )							->   Optional[Any]:
        __UpperCAmelCase							:			List[Any]     =						Features({"""audio""": Audio()}      )
        __UpperCAmelCase							:			Any     =						Features({"""labels""": ClassLabel}      )
        __UpperCAmelCase							:			str     =						{
            """audio_column""": """input_image""",
            """label_column""": """input_label""",
        }
        __UpperCAmelCase							:			Union[str, Any]     =						AudioClassification.from_dict(__lowercase      )
        self.assertEqual("""audio-classification"""	,   task.task      )
        self.assertEqual(__lowercase	,   task.input_schema      )
        self.assertEqual(__lowercase	,   task.label_schema      )




      def 			UpperCAmelCase   (   self      :    List[str]      )							->   Dict:
        __UpperCAmelCase							:			str     =						AudioClassification(audio_column="""input_audio"""	,   label_column="""input_label"""      )
        self.assertEqual(task.label_schema["""labels"""]	,   __lowercase      )
        __UpperCAmelCase							:			Optional[int]     =						task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels      )}      )      )
        self.assertEqual(task.label_schema["""labels"""]	,   ClassLabel(names=self.labels      )      )


class 					a					(				lowercase__     ):



      """simple docstring"""


      def 			UpperCAmelCase   (   self      :    List[str]      )							->   Tuple:
        __UpperCAmelCase							:			List[str]     =						sorted(["""pos""", """neg"""]      )
      def 			UpperCAmelCase   (   self      :    Optional[Any]      )							->   Tuple:
        __UpperCAmelCase							:			str     =						ImageClassification(image_column="""input_image"""	,   label_column="""input_label"""      )
        self.assertDictEqual({"""input_image""": """image""", """input_label""": """labels"""}	,   task.column_mapping      )
      def 			UpperCAmelCase   (   self      :    List[Any]      )							->   List[str]:
        __UpperCAmelCase							:			List[Any]     =						Features({"""image""": Image()}      )
        __UpperCAmelCase							:			List[str]     =						Features({"""labels""": ClassLabel}      )
        __UpperCAmelCase							:			str     =						{
            """image_column""": """input_image""",
            """label_column""": """input_label""",
        }
        __UpperCAmelCase							:			List[str]     =						ImageClassification.from_dict(__lowercase      )
        self.assertEqual("""image-classification"""	,   task.task      )
        self.assertEqual(__lowercase	,   task.input_schema      )
        self.assertEqual(__lowercase	,   task.label_schema      )




      def 			UpperCAmelCase   (   self      :    str      )							->   Optional[int]:
        __UpperCAmelCase							:			str     =						ImageClassification(image_column="""input_image"""	,   label_column="""input_label"""      )
        self.assertEqual(task.label_schema["""labels"""]	,   __lowercase      )
        __UpperCAmelCase							:			Dict     =						task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels      )}      )      )
        self.assertEqual(task.label_schema["""labels"""]	,   ClassLabel(names=self.labels      )      )


class 					a					(				lowercase__     ):



      """simple docstring"""


      def 			UpperCAmelCase   (   self      :    Any      )							->   Dict:
        __UpperCAmelCase							:			Dict     =						DatasetInfo(task_templates=QuestionAnsweringExtractive()      )
        __UpperCAmelCase							:			Union[str, Any]     =						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      :    Tuple      ):
          return x

        def dont_keep_task(__lowercase      :    Union[str, Any]      ):
          __UpperCAmelCase							:			List[str]     =						deepcopy(__lowercase      )
          __UpperCAmelCase							:			Tuple     =						0
          return out

        __UpperCAmelCase							:			Dict     =						dataset.map(__lowercase      )
        assert mapped_dataset.info.task_templates == dataset.info.task_templates
        # reload from cache
        __UpperCAmelCase							:			Union[str, Any]     =						dataset.map(__lowercase      )
        assert mapped_dataset.info.task_templates == dataset.info.task_templates

        __UpperCAmelCase							:			Optional[int]     =						dataset.map(__lowercase      )
        assert mapped_dataset.info.task_templates == []
        # reload from cache
        __UpperCAmelCase							:			Tuple     =						dataset.map(__lowercase      )
        assert mapped_dataset.info.task_templates == []




      def 			UpperCAmelCase   (   self      :    int      )							->   Any:
        __UpperCAmelCase							:			Dict     =						Features({"""text""": Value("""string"""      ), """label""": ClassLabel(names=("""pos""", """neg""")      )}      )
        __UpperCAmelCase							:			int     =						TextClassification(text_column="""text"""	,   label_column="""label"""      )
        __UpperCAmelCase							:			Optional[Any]     =						DatasetInfo(features=__lowercase	,   task_templates=__lowercase      )
        __UpperCAmelCase							:			Tuple     =						Dataset.from_dict({"""text""": ["""A sentence."""], """label""": ["""pos"""]}	,   info=__lowercase      )

        def process(__lowercase      :    Dict      ):
          return example

        __UpperCAmelCase							:			int     =						dataset.remove_columns("""label"""      )
        __UpperCAmelCase							:			Optional[Any]     =						modified_dataset.map(__lowercase      )
        assert mapped_dataset.info.task_templates == []










import enum
import inspect
import warnings
from functools import wraps
from typing import Callable, Optional

from .logging import get_logger


a	: Any      =				set()
a	: List[Any]      =				get_logger(__name__)






def        lowerCamelCase__   (					__lowerCamelCase    :  Optional[str] = None	):

  def decorator(__lowerCamelCase    :  Callable	):
    global _emitted_deprecation_warnings

    if inspect.isclass(__lowerCamelCase	):
      __UpperCAmelCase							:			Optional[Any]     =						deprecated_class_or_function.__init__
      __UpperCAmelCase							:			int     =						deprecated_class_or_function.__name__
    else:
      __UpperCAmelCase							:			Any     =						deprecated_class_or_function
      __UpperCAmelCase							:			Any     =						deprecated_function.__name__
      # Support deprecating __init__ class method: class name instead
      __UpperCAmelCase							:			List[str]     =						name if name != """__init__""" else deprecated_function.__qualname__.split("""."""	)[-2]

    __UpperCAmelCase							:			Union[str, Any]     =						(
        f"""{name} is deprecated and will be removed in the next major version of datasets.""" + f""" {help_message}"""
        if help_message
        else """"""
    )

    @wraps(__lowerCamelCase	)
    def wrapper(*__lowerCamelCase    :  List[str]						,	**__lowerCamelCase    :  Tuple	):
      __UpperCAmelCase							:			Optional[Any]     =						hash(__lowerCamelCase	)
      if func_hash not in _emitted_deprecation_warnings:
        warnings.warn(__lowerCamelCase						,	category=__lowerCamelCase						,	stacklevel=2	)
        _emitted_deprecation_warnings.add(__lowerCamelCase	)
      return deprecated_function(*__lowerCamelCase						,	**__lowerCamelCase	)

    __UpperCAmelCase							:			List[str]     =						"""deprecated"""

    if inspect.isclass(__lowerCamelCase	):
      __UpperCAmelCase							:			int     =						wrapper
      return deprecated_class_or_function
    else:
      return wrapper

  return decorator
class 					a					(				enum.EnumMeta     ):



      """simple docstring"""


      def __getattribute__(   cls      :    Optional[int]	,   __lowercase      :    List[Any]      )							->   str:
        __UpperCAmelCase							:			List[Any]     =						super().__getattribute__(__lowercase      )
        if isinstance(__lowercase	,   enum.Enum      ) and obj._on_access:
          obj._on_access()
        return obj
      def __getitem__(   cls      :    Union[str, Any]	,   __lowercase      :    Optional[int]      )							->   Optional[int]:
        __UpperCAmelCase							:			Union[str, Any]     =						super().__getitem__(__lowercase      )
        if member._on_access:
          member._on_access()
        return member




      def __call__(   cls      :    List[str]	,   __lowercase      :    Dict	,   __lowercase      :    List[Any]=None	,   *, __lowercase      :    Dict=None	,   __lowercase      :    Any=None	,   __lowercase      :    Optional[Any]=None	,   __lowercase      :    Dict=1      )							->   List[Any]:
        __UpperCAmelCase							:			Union[str, Any]     =						super().__call__(__lowercase	,   __lowercase	,   module=__lowercase	,   qualname=__lowercase	,   type=__lowercase	,   start=__lowercase      )
        if isinstance(__lowercase	,   enum.Enum      ) and obj._on_access:
          obj._on_access()
        return obj


class 					a					(				enum.Enum							, metaclass=lowercase__     ):



      """simple docstring"""


      def __new__(   cls      :    Dict	,   __lowercase      :    Tuple      )							->   Optional[Any]:
        __UpperCAmelCase							:			List[Any]     =						object.__new__(cls      )
        __UpperCAmelCase							:			Any     =						value
        __UpperCAmelCase							:			int     =						member.deprecate
        return member
      @property
      def 			UpperCAmelCase   (   self      :    Optional[Any]      )							->   Dict:
        return ""




      def 			UpperCAmelCase   (   self      :    str      )							->   Dict:
        __UpperCAmelCase							:			Optional[int]     =						f""" {self.help_message}""" if self.help_message else """"""
        warnings.warn(
            f"""'{self.__objclass__.__name__}' is deprecated and will be removed in the next major version of datasets."""
            + help_message	,   __lowercase	,   stacklevel=3	,   )


