

import json
import os
import tempfile

import transformers

import datasets
from utils import generate_example_dataset, get_duration


_UpperCAmelCase		:       Optional[int]						    =	50_0000

_UpperCAmelCase    ,						_UpperCAmelCase		:       Optional[Any]						    =	os.path.split(__file__)
_UpperCAmelCase		:       Tuple						    =	os.path.join(RESULTS_BASEPATH, """results""", RESULTS_FILENAME.replace(""".py""", """.json"""))





@get_duration
def  __lowerCamelCase     (			UpperCamelCase__       ,							**UpperCamelCase__				):







							'''simple docstring'''






							snake_case_          =   dataset.map(**UpperCamelCase__				)





@get_duration
def  __lowerCamelCase     (			UpperCamelCase__       ,							**UpperCamelCase__				):







							'''simple docstring'''






							snake_case_          =   dataset.filter(**UpperCamelCase__				)





def  __lowerCamelCase     (			):







							'''simple docstring'''






							snake_case_          =   {'num examples': SPEED_TEST_N_EXAMPLES}
							with tempfile.TemporaryDirectory() as tmp_dir:
														snake_case_          =   datasets.Features({'text': datasets.Value('string'				), 'numbers': datasets.Value('float32'				)}				)
														snake_case_          =   generate_example_dataset(
														    os.path.join(UpperCamelCase__       ,							'dataset.arrow'				)       ,							UpperCamelCase__       ,							num_examples=UpperCamelCase__				)

														snake_case_          =   transformers.AutoTokenizer.from_pretrained('bert-base-cased'       ,							use_fast=UpperCamelCase__				)

														def tokenize(UpperCamelCase__				):
																					return tokenizer(examples['text']				)

														snake_case_          =   map(UpperCamelCase__				)

														snake_case_          =   map(UpperCamelCase__       ,							batched=UpperCamelCase__				)

														snake_case_          =   map(UpperCamelCase__       ,							function=lambda UpperCamelCase__				: None       ,							batched=UpperCamelCase__				)

														with dataset.formatted_as(type='numpy'				):
																					snake_case_          =   map(UpperCamelCase__       ,							function=lambda UpperCamelCase__				: None       ,							batched=UpperCamelCase__				)

														with dataset.formatted_as(type='pandas'				):
																					snake_case_          =   map(UpperCamelCase__       ,							function=lambda UpperCamelCase__				: None       ,							batched=UpperCamelCase__				)

														with dataset.formatted_as(type='torch'       ,							columns='numbers'				):
																					snake_case_          =   map(UpperCamelCase__       ,							function=lambda UpperCamelCase__				: None       ,							batched=UpperCamelCase__				)

														with dataset.formatted_as(type='tensorflow'       ,							columns='numbers'				):
																					snake_case_          =   map(UpperCamelCase__       ,							function=lambda UpperCamelCase__				: None       ,							batched=UpperCamelCase__				)

														snake_case_          =   map(UpperCamelCase__       ,							function=UpperCamelCase__       ,							batched=UpperCamelCase__				)

														snake_case_          =   filter(UpperCamelCase__				)

														# Activate later when tokenizer support batched inputs
														# with dataset.formatted_as(type='numpy'):
														#     times[func.__name__ + " fast-tokenizer batched numpy"] = func(dataset, function=tokenize, batched=True)

							with open(UpperCamelCase__       ,							'wb'				) as f:
														f.write(json.dumps(UpperCamelCase__				).encode('utf-8'				)				)


if __name__ == "__main__":  # useful to run the profiler
					benchmark_map_filter()







from __future__ import annotations

import os
from typing import Any

import requests

_UpperCAmelCase		:       int						    =	"""https://api.github.com"""

# https://docs.github.com/en/free-pro-team@latest/rest/reference/users#get-the-authenticated-user
_UpperCAmelCase		:       Dict						    =	BASE_URL + """/user"""

# https://github.com/settings/tokens
_UpperCAmelCase		:       Optional[Any]						    =	os.environ.get("""USER_TOKEN""", """""")





def  __lowerCamelCase     (			UpperCamelCase__				):







							'''simple docstring'''






							snake_case_          =   {
							    'Authorization': F'''token {auth_token}''',
							    'Accept': 'application/vnd.github.v3+json',
							}
							return requests.get(UpperCamelCase__       ,							headers=UpperCamelCase__				).json()


if __name__ == "__main__":  # pragma: no cover
					if USER_TOKEN:
										for key, value in fetch_github_info(USER_TOKEN).items():
															print(F'''{key}: {value}''')
					else:
										raise ValueError("""'USER_TOKEN' field cannot be empty.""")




