






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


lowerCAmelCase_     =			{
    '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   snake_case		(				UpperCAmelCase						:							Dict ):
				A									=   task_cls()
				A									=   asdict(UpperCAmelCase )
				A									=   task_template_from_dict(UpperCAmelCase )
				assert task == reloaded
class   UpperCamelCase			:







		"""simple docstring"""



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


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







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


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


class   UpperCamelCase			(					snake_case__			):







		"""simple docstring"""



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


						'''simple docstring'''
						A									=   sorted(['pos', 'neg']		)
		def    A(	self		:							List[Any]		)     -> str:


						'''simple docstring'''
						A									=   TextClassification(text_column='input_text'    ,label_column='input_label'		)
						self.assertDictEqual({'input_text': 'text', 'input_label': 'labels'}    ,task.column_mapping		)
		def    A(	self		:							List[Any]		)     -> Optional[int]:


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







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


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


class   UpperCamelCase			(					snake_case__			):







		"""simple docstring"""



		def    A(	self		:							Tuple		)     -> Optional[int]:


						'''simple docstring'''
						A									=   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		:							Any		)     -> Any:


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


class   UpperCamelCase			(					snake_case__			):







		"""simple docstring"""



		def    A(	self		:							Optional[Any]		)     -> Dict:


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







		def    A(	self		:							List[str]		)     -> Dict:


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


class   UpperCamelCase			(					snake_case__			):







		"""simple docstring"""



		def    A(	self		:							List[Any]		)     -> List[str]:


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







		def    A(	self		:							Optional[Any]		)     -> Any:


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


class   UpperCamelCase			(					snake_case__			):







		"""simple docstring"""



		def    A(	self		:							Optional[Any]		)     -> List[Any]:


						'''simple docstring'''
						A									=   sorted(['pos', 'neg']		)
		def    A(	self		:							Dict		)     -> Optional[Any]:


						'''simple docstring'''
						A									=   AudioClassification(audio_column='input_audio'    ,label_column='input_label'		)
						self.assertDictEqual({'input_audio': 'audio', 'input_label': 'labels'}    ,task.column_mapping		)
		def    A(	self		:							List[Any]		)     -> Optional[int]:


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







		def    A(	self		:							Dict		)     -> List[str]:


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


class   UpperCamelCase			(					snake_case__			):







		"""simple docstring"""



		def    A(	self		:							Dict		)     -> List[str]:


						'''simple docstring'''
						A									=   sorted(['pos', 'neg']		)
		def    A(	self		:							int		)     -> Dict:


						'''simple docstring'''
						A									=   ImageClassification(image_column='input_image'    ,label_column='input_label'		)
						self.assertDictEqual({'input_image': 'image', 'input_label': 'labels'}    ,task.column_mapping		)
		def    A(	self		:							List[str]		)     -> List[str]:


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







		def    A(	self		:							Dict		)     -> int:


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


class   UpperCamelCase			(					snake_case__			):







		"""simple docstring"""



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


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

						def keep_task(_SCREAMING_SNAKE_CASE		:							Optional[int]		):
										return x

						def dont_keep_task(_SCREAMING_SNAKE_CASE		:							str		):
										A									=   deepcopy(_SCREAMING_SNAKE_CASE		)
										A									=   0
										return out

						A									=   dataset.map(_SCREAMING_SNAKE_CASE		)
						assert mapped_dataset.info.task_templates == dataset.info.task_templates
						# reload from cache
						A									=   dataset.map(_SCREAMING_SNAKE_CASE		)
						assert mapped_dataset.info.task_templates == dataset.info.task_templates

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







		def    A(	self		:							Dict		)     -> Dict:


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

						def process(_SCREAMING_SNAKE_CASE		:							Optional[Any]		):
										return example

						A									=   dataset.remove_columns('label'		)
						A									=   modified_dataset.map(_SCREAMING_SNAKE_CASE		)
						assert mapped_dataset.info.task_templates == []













import hashlib
import importlib.util
import json
import os
import pathlib
from types import ModuleType

import pytest
import requests

lowerCAmelCase_     =			pathlib.Path.cwd().joinpath('project_euler')
lowerCAmelCase_     =			pathlib.Path.cwd().joinpath(
    'scripts', 'project_euler_answers.json'
)

with open(PROJECT_EULER_ANSWERS_PATH) as file_handle:
					lowerCAmelCase_     =			json.load(file_handle)







def   snake_case		(				UpperCAmelCase						:							pathlib.Path ):
				A									=   importlib.util.spec_from_file_location(file_path.name,    str(UpperCAmelCase ) )
				A									=   importlib.util.module_from_spec(UpperCAmelCase )  # type: ignore
				spec.loader.exec_module(UpperCAmelCase )  # type: ignore
				return module







def   snake_case		(				):
				A									=   []
				for problem_dir_path in PROJECT_EULER_DIR_PATH.iterdir():
								if problem_dir_path.is_file() or problem_dir_path.name.startswith('_' ):
												continue
								for file_path in problem_dir_path.iterdir():
												if file_path.suffix != ".py" or file_path.name.startswith(('_', 'test') ):
																continue
												solution_file_paths.append(UpperCAmelCase )
				return solution_file_paths







def   snake_case		(				):
				with open(os.environ['GITHUB_EVENT_PATH'] ) as file:
								A									=   json.load(UpperCAmelCase )
				return event["pull_request"]["url"] + "/files"







def   snake_case		(				):
				A									=   []
				A									=   {
				    'Accept': 'application/vnd.github.v3+json',
				    'Authorization': 'token ' + os.environ['GITHUB_TOKEN'],
				}
				A									=   requests.get(get_files_url(),    headers=UpperCAmelCase ).json()
				for file in files:
								A									=   pathlib.Path.cwd().joinpath(file['filename'] )
								if (
								    filepath.suffix != ".py"
								    or filepath.name.startswith(('_', 'test') )
								    or not filepath.name.startswith('sol' )
								):
												continue
								solution_file_paths.append(UpperCAmelCase )
				return solution_file_paths







def   snake_case		(				):
				if os.environ.get('CI' ) and os.environ.get('GITHUB_EVENT_NAME' ) == "pull_request":
								# Return only if there are any, otherwise default to all solutions
								if filepaths := added_solution_file_path():
												return filepaths
				return all_solution_file_paths()







@pytest.mark.parametrize(
    'solution_path',    collect_solution_file_paths(),    ids=lambda UpperCAmelCase : f'{path.parent.name}/{path.name}',    )
def   snake_case		(				UpperCAmelCase						:							pathlib.Path ):
				A									=   solution_path.parent.name[8:].zfill(3 )
				A									=   PROBLEM_ANSWERS[problem_number]
				A									=   convert_path_to_module(UpperCAmelCase )
				A									=   str(solution_module.solution() )  # type: ignore
				A									=   hashlib.shaaaa(answer.encode() ).hexdigest()
				assert (
				    answer == expected
				), f'Expected solution to {problem_number} to have hash {expected}, got {answer}'





