




import json
import os
import pickle
import subprocess
from hashlib import mda
from pathlib import Path
from tempfile import gettempdir
from textwrap import dedent
from types import CodeType, FunctionType
from unittest import TestCase
from unittest.mock import patch

import pytest
from multiprocess import Pool
from packaging import version

import datasets
from datasets.fingerprint import Hasher, fingerprint_transform
from datasets.table import InMemoryTable

from .utils import (
    require_regex,
    require_spacy,
    require_spacy_model,
    require_tiktoken,
    require_torch,
    require_transformers,
)
class 				__snake_case     :



				def __init__(					self					:						Dict						,		_UpperCAmelCase					:						Tuple					)     ->			str:





								'''simple docstring'''




								_lowerCAmelCase			:			Optional[Any]        =					foo



				def __call__(					self					:						List[Any]					)     ->			Any:





								'''simple docstring'''




								return self.foo






class 				__snake_case     (datasets.Dataset						):



				@fingerprint_transform(inplace=_UpperCAmelCase					)
				def 					SCREAMING_SNAKE_CASE				(					self					:						Any						,		_UpperCAmelCase					:						str						,		*_UpperCAmelCase					:						List[Any]						,		**_UpperCAmelCase					:						Dict					)     ->			List[Any]:





								'''simple docstring'''




								return DatasetChild(self.data						,		fingerprint=_UpperCAmelCase					)



				@fingerprint_transform(inplace=_UpperCAmelCase					)
				def 					SCREAMING_SNAKE_CASE				(					self					:						Optional[int]						,		_UpperCAmelCase					:						List[str]						,		*_UpperCAmelCase					:						Dict						,		**_UpperCAmelCase					:						Tuple					)     ->			int:





								'''simple docstring'''




								return DatasetChild(self.data						,		fingerprint=_UpperCAmelCase					)






class 				__snake_case     :



				def __init__(					self					:						int						,		_UpperCAmelCase					:						int					)     ->			str:





								'''simple docstring'''




								_lowerCAmelCase			:			Optional[int]        =					callable



				def __call__(					self					:						List[Any]						,		*_UpperCAmelCase					:						Dict						,		**_UpperCAmelCase					:						Optional[Any]					)     ->			Any:





								'''simple docstring'''




								if self.callable is not None:
												return self.callable(*_UpperCAmelCase						,		**_UpperCAmelCase					)



				def __getstate__(					self					:						Optional[int]					)     ->			Optional[Any]:





								'''simple docstring'''




								raise pickle.PicklingError()






class 				__snake_case     (_a						):



				@require_transformers
				@pytest.mark.integration
				def 					SCREAMING_SNAKE_CASE				(					self					:						Optional[Any]					)     ->			List[Any]:





								'''simple docstring'''




								from transformers import AutoTokenizer

								def encode(_UpperCAmelCase					:						Optional[int]					):
												return tokenizer(_UpperCAmelCase					)

								# TODO: add hash consistency tests across sessions
								_lowerCAmelCase			:			str        =					AutoTokenizer.from_pretrained("""bert-base-uncased"""					)
								_lowerCAmelCase			:			List[str]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			Tuple        =					mda(datasets.utils.py_utils.dumps(lambda _UpperCAmelCase					: tokenizer(_UpperCAmelCase					)					)					).hexdigest()
								_lowerCAmelCase			:			List[str]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			str        =					AutoTokenizer.from_pretrained("""bert-base-cased"""					)
								_lowerCAmelCase			:			Union[str, Any]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			Optional[Any]        =					mda(datasets.utils.py_utils.dumps(lambda _UpperCAmelCase					: tokenizer(_UpperCAmelCase					)					)					).hexdigest()
								_lowerCAmelCase			:			List[Any]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			List[Any]        =					AutoTokenizer.from_pretrained("""bert-base-uncased"""					)
								_lowerCAmelCase			:			str        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			Any        =					mda(datasets.utils.py_utils.dumps(lambda _UpperCAmelCase					: tokenizer(_UpperCAmelCase					)					)					).hexdigest()
								_lowerCAmelCase			:			List[str]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				@require_transformers
				@pytest.mark.integration
				def 					SCREAMING_SNAKE_CASE				(					self					:						Tuple					)     ->			List[Any]:





								'''simple docstring'''




								from transformers import AutoTokenizer

								_lowerCAmelCase			:			Dict        =					AutoTokenizer.from_pretrained("""gpt2"""					)
								_lowerCAmelCase			:			List[Any]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								tokenizer("""Hello world !"""					)  # call once to change the tokenizer's cache
								_lowerCAmelCase			:			Tuple        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				@require_regex
				def 					SCREAMING_SNAKE_CASE				(					self					:						int					)     ->			Dict:





								'''simple docstring'''




								import regex

								_lowerCAmelCase			:			Optional[int]        =					regex.Regex("""foo"""					)
								_lowerCAmelCase			:			List[Any]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			Optional[Any]        =					regex.Regex("""bar"""					)
								_lowerCAmelCase			:			Optional[Any]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			Optional[int]        =					regex.Regex("""foo"""					)
								_lowerCAmelCase			:			Optional[int]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)






class 				__snake_case     (_a						):



				def 					SCREAMING_SNAKE_CASE				(					self					:						int					)     ->			List[str]:





								'''simple docstring'''




								def func():
												return foo

								_lowerCAmelCase			:			Dict        =					[0]
								_lowerCAmelCase			:			List[str]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			Union[str, Any]        =					[1]
								_lowerCAmelCase			:			List[str]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			str        =					[0]
								_lowerCAmelCase			:			Optional[Any]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				def 					SCREAMING_SNAKE_CASE				(					self					:						str					)     ->			Optional[int]:





								'''simple docstring'''




								def func():
												pass

								_lowerCAmelCase			:			List[Any]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()

								def func():
												pass

								_lowerCAmelCase			:			str        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				def 					SCREAMING_SNAKE_CASE				(					self					:						Optional[int]					)     ->			Dict:





								'''simple docstring'''




								_lowerCAmelCase			:			Union[str, Any]        =					mda(datasets.utils.py_utils.dumps(Foo([0]					)					)					).hexdigest()
								_lowerCAmelCase			:			Optional[Any]        =					mda(datasets.utils.py_utils.dumps(Foo([1]					)					)					).hexdigest()
								_lowerCAmelCase			:			int        =					mda(datasets.utils.py_utils.dumps(Foo([0]					)					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



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





								'''simple docstring'''




								_lowerCAmelCase			:			str        =					mda(datasets.utils.py_utils.dumps(Foo([0]					).__call__					)					).hexdigest()
								_lowerCAmelCase			:			Optional[Any]        =					mda(datasets.utils.py_utils.dumps(Foo([1]					).__call__					)					).hexdigest()
								_lowerCAmelCase			:			str        =					mda(datasets.utils.py_utils.dumps(Foo([0]					).__call__					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				def 					SCREAMING_SNAKE_CASE				(					self					:						Any					)     ->			int:





								'''simple docstring'''




								_lowerCAmelCase			:			Union[str, Any]        =					(
								    """co_argcount""",
								    """co_kwonlyargcount""",
								    """co_nlocals""",
								    """co_stacksize""",
								    """co_flags""",
								    """co_code""",
								    """co_consts""",
								    """co_names""",
								    """co_varnames""",
								    """co_filename""",
								    """co_name""",
								    """co_firstlineno""",
								    """co_lnotab""",
								    """co_freevars""",
								    """co_cellvars""",
								)

								def _create_code_pyaa(*_UpperCAmelCase					:						List[Any]					):
												if hasattr(args[-3]						,		"""encode"""					):
																_lowerCAmelCase			:			int        =					list(_UpperCAmelCase					)
																_lowerCAmelCase			:			Optional[int]        =					args[-3].encode()  # co_lnotab
																_lowerCAmelCase			:			Union[str, Any]        =					args[-10].encode()  # co_code
												if hasattr(_UpperCAmelCase						,		"""co_posonlyargcount"""					):
																if len(_UpperCAmelCase					) == 16:
																				return CodeType(*_UpperCAmelCase					)
																elif len(_UpperCAmelCase					) == 15:
																				return CodeType(args[0]						,		0						,		*args[1:]					)
																return CodeType(args[0]						,		0						,		0						,		*args[1:]					)
												elif hasattr(_UpperCAmelCase						,		"""co_kwonlyargcount"""					):
																if len(_UpperCAmelCase					) == 16:
																				return CodeType(args[0]						,		*args[2:]					)
																elif len(_UpperCAmelCase					) == 15:
																				return CodeType(*_UpperCAmelCase					)
																return CodeType(args[0]						,		0						,		*args[1:]					)
												if len(_UpperCAmelCase					) == 16:
																return CodeType(args[0]						,		*args[3:]					)
												elif len(_UpperCAmelCase					) == 15:
																return CodeType(args[0]						,		*args[2:]					)
												return CodeType(*_UpperCAmelCase					)

								def create_ipython_func(_UpperCAmelCase					:						int						,		_UpperCAmelCase					:						Tuple					):
												def func():
																return returned_obj

												_lowerCAmelCase			:			Tuple        =					func.__code__
												# Use _create_code from dill in order to make it work for different python versions
												if datasets.config.PY_VERSION < version.parse("""3.8"""					):
																_lowerCAmelCase			:			Optional[int]        =					_create_code_pyaa(
																    *[getattr(_UpperCAmelCase						,		_UpperCAmelCase					) if k != """co_filename""" else co_filename for k in code_args_pyaa]					)
												else:
																_lowerCAmelCase			:			int        =					code.replace(co_filename=_UpperCAmelCase					)
												return FunctionType(_UpperCAmelCase						,		func.__globals__						,		func.__name__						,		func.__defaults__						,		func.__closure__					)

								_lowerCAmelCase    ,			_lowerCAmelCase			:			Tuple        =					"""<ipython-input-2-e0383a102aae>""", [0]
								_lowerCAmelCase			:			Tuple        =					mda(datasets.utils.py_utils.dumps(create_ipython_func(_UpperCAmelCase						,		_UpperCAmelCase					)					)					).hexdigest()
								_lowerCAmelCase    ,			_lowerCAmelCase			:			Optional[Any]        =					"""<ipython-input-2-e0383a102aae>""", [1]
								_lowerCAmelCase			:			Optional[int]        =					mda(datasets.utils.py_utils.dumps(create_ipython_func(_UpperCAmelCase						,		_UpperCAmelCase					)					)					).hexdigest()
								_lowerCAmelCase    ,			_lowerCAmelCase			:			Union[str, Any]        =					"""<ipython-input-5-713f6613acf3>""", [0]
								_lowerCAmelCase			:			Union[str, Any]        =					mda(datasets.utils.py_utils.dumps(create_ipython_func(_UpperCAmelCase						,		_UpperCAmelCase					)					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)

								_lowerCAmelCase    ,			_lowerCAmelCase			:			Optional[int]        =					os.path.join(gettempdir()						,		"""ipykernel_12345"""						,		"""321456789.py"""					), [0]
								_lowerCAmelCase			:			Optional[Any]        =					mda(datasets.utils.py_utils.dumps(create_ipython_func(_UpperCAmelCase						,		_UpperCAmelCase					)					)					).hexdigest()
								_lowerCAmelCase    ,			_lowerCAmelCase			:			List[Any]        =					os.path.join(gettempdir()						,		"""ipykernel_12345"""						,		"""321456789.py"""					), [1]
								_lowerCAmelCase			:			Optional[int]        =					mda(datasets.utils.py_utils.dumps(create_ipython_func(_UpperCAmelCase						,		_UpperCAmelCase					)					)					).hexdigest()
								_lowerCAmelCase    ,			_lowerCAmelCase			:			Dict        =					os.path.join(gettempdir()						,		"""ipykernel_12345"""						,		"""654123987.py"""					), [0]
								_lowerCAmelCase			:			List[str]        =					mda(datasets.utils.py_utils.dumps(create_ipython_func(_UpperCAmelCase						,		_UpperCAmelCase					)					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				def 					SCREAMING_SNAKE_CASE				(					self					:						Optional[int]					)     ->			Any:





								'''simple docstring'''




								_lowerCAmelCase    ,			_lowerCAmelCase			:			int        =					[0], [1]

								def func():
												return foo, bar

								_lowerCAmelCase			:			Any        =					"""__main__"""

								def globalvars_mocka_side_effect(_UpperCAmelCase					:						Any						,		*_UpperCAmelCase					:						List[Any]						,		**_UpperCAmelCase					:						str					):
												return {"foo": foo, "bar": bar}

								def globalvars_mocka_side_effect(_UpperCAmelCase					:						Tuple						,		*_UpperCAmelCase					:						Optional[int]						,		**_UpperCAmelCase					:						int					):
												return {"bar": bar, "foo": foo}

								with patch("""dill.detect.globalvars"""						,		side_effect=_UpperCAmelCase					) as globalvars_mocka:
												_lowerCAmelCase			:			str        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
												self.assertGreater(globalvars_mocka.call_count						,		0					)
								with patch("""dill.detect.globalvars"""						,		side_effect=_UpperCAmelCase					) as globalvars_mocka:
												_lowerCAmelCase			:			Tuple        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
												self.assertGreater(globalvars_mocka.call_count						,		0					)
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)






class 				__snake_case     (_a						):



				def 					SCREAMING_SNAKE_CASE				(					self					:						List[str]					)     ->			Optional[int]:





								'''simple docstring'''




								_lowerCAmelCase			:			List[Any]        =					Hasher.hash("""hello"""					)
								_lowerCAmelCase			:			Optional[Any]        =					Hasher.hash("""hello"""					)
								_lowerCAmelCase			:			Tuple        =					Hasher.hash("""there"""					)
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				def 					SCREAMING_SNAKE_CASE				(					self					:						List[str]					)     ->			int:





								'''simple docstring'''




								_lowerCAmelCase			:			List[str]        =					Hasher.hash(Foo("""hello"""					)					)
								_lowerCAmelCase			:			Optional[int]        =					Hasher.hash(Foo("""hello"""					)					)
								_lowerCAmelCase			:			List[str]        =					Hasher.hash(Foo("""there"""					)					)
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				def 					SCREAMING_SNAKE_CASE				(					self					:						str					)     ->			List[str]:





								'''simple docstring'''




								_lowerCAmelCase			:			List[Any]        =					Hasher()
								for x in ["hello", Foo("""hello"""					)]:
												hasher.update(_UpperCAmelCase					)
								_lowerCAmelCase			:			int        =					hasher.hexdigest()
								_lowerCAmelCase			:			Tuple        =					Hasher()
								for x in ["hello", Foo("""hello"""					)]:
												hasher.update(_UpperCAmelCase					)
								_lowerCAmelCase			:			Optional[Any]        =					hasher.hexdigest()
								_lowerCAmelCase			:			int        =					Hasher()
								for x in ["there", Foo("""there"""					)]:
												hasher.update(_UpperCAmelCase					)
								_lowerCAmelCase			:			Any        =					hasher.hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				def 					SCREAMING_SNAKE_CASE				(					self					:						Optional[int]					)     ->			List[str]:





								'''simple docstring'''




								with self.assertRaises(pickle.PicklingError					):
												Hasher.hash(UnpicklableCallable(Foo("""hello"""					)					)					)



				def 					SCREAMING_SNAKE_CASE				(					self					:						Optional[int]					)     ->			Dict:





								'''simple docstring'''




								_lowerCAmelCase			:			int        =					"""abc"""
								_lowerCAmelCase			:			Tuple        =					[string, string]  # two strings have the same ids
								_lowerCAmelCase			:			Union[str, Any]        =					[string, string]
								_lowerCAmelCase			:			Union[str, Any]        =					json.loads(f"[\"{string}\", \"{string}\"]"					)  # two strings have different ids
								self.assertIs(obja[0]						,		_UpperCAmelCase					)
								self.assertIs(obja[0]						,		obja[1]					)
								self.assertIs(obja[0]						,		_UpperCAmelCase					)
								self.assertIs(obja[0]						,		obja[1]					)
								self.assertIsNot(obja[0]						,		_UpperCAmelCase					)
								self.assertIsNot(obja[0]						,		obja[1]					)
								_lowerCAmelCase			:			Optional[int]        =					Hasher.hash(_UpperCAmelCase					)
								_lowerCAmelCase			:			List[Any]        =					Hasher.hash(_UpperCAmelCase					)
								_lowerCAmelCase			:			int        =					Hasher.hash(_UpperCAmelCase					)
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				@require_tiktoken
				def 					SCREAMING_SNAKE_CASE				(					self					:						str					)     ->			str:





								'''simple docstring'''




								import tiktoken

								_lowerCAmelCase			:			int        =					tiktoken.get_encoding("""gpt2"""					)
								_lowerCAmelCase			:			Any        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			Tuple        =					tiktoken.get_encoding("""r50k_base"""					)
								_lowerCAmelCase			:			Tuple        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			Tuple        =					tiktoken.get_encoding("""gpt2"""					)
								_lowerCAmelCase			:			Optional[int]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				@require_torch
				def 					SCREAMING_SNAKE_CASE				(					self					:						List[Any]					)     ->			Any:





								'''simple docstring'''




								import torch

								_lowerCAmelCase			:			List[str]        =					torch.tensor([1.0]					)
								_lowerCAmelCase			:			str        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			int        =					torch.tensor([2.0]					)
								_lowerCAmelCase			:			Tuple        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			Dict        =					torch.tensor([1.0]					)
								_lowerCAmelCase			:			str        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)



				@require_spacy
				@require_spacy_model("""en_core_web_sm"""					)
				@require_spacy_model("""fr_core_news_sm"""					)
				@pytest.mark.integration
				def 					SCREAMING_SNAKE_CASE				(					self					:						List[str]					)     ->			str:





								'''simple docstring'''




								import spacy

								_lowerCAmelCase			:			List[str]        =					spacy.load("""en_core_web_sm"""					)
								_lowerCAmelCase			:			Dict        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			List[Any]        =					spacy.load("""fr_core_news_sm"""					)
								_lowerCAmelCase			:			str        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								_lowerCAmelCase			:			Union[str, Any]        =					spacy.load("""en_core_web_sm"""					)
								_lowerCAmelCase			:			List[str]        =					mda(datasets.utils.py_utils.dumps(_UpperCAmelCase					)					).hexdigest()
								self.assertEqual(_UpperCAmelCase						,		_UpperCAmelCase					)
								self.assertNotEqual(_UpperCAmelCase						,		_UpperCAmelCase					)






@pytest.mark.integration
def 							_UpperCAmelCase     (UpperCamelCase_       :       Path				):
				'''simple docstring'''
				_lowerCAmelCase			:			List[str]        =					tmp_path / """dir1"""
				_lowerCAmelCase			:			Optional[Any]        =					tmp_path / """dir2"""
				dira.mkdir()
				dira.mkdir()
				_lowerCAmelCase			:			List[str]        =					"""script.py"""
				_lowerCAmelCase			:			Optional[int]        =					dedent(
				    """
    from datasets.fingerprint import Hasher
    def foo():
        pass
    print(Hasher.hash(foo))
    """				)
				_lowerCAmelCase			:			Dict        =					dira / script_filename
				_lowerCAmelCase			:			Dict        =					dira / script_filename
				with script_patha.open("""w"""				) as f:
								f.write(UpperCamelCase_				)
				with script_patha.open("""w"""				) as f:
								f.write(UpperCamelCase_				)
				_lowerCAmelCase			:			str        =					subprocess.check_output(["""python""", str(UpperCamelCase_				)]				)
				_lowerCAmelCase			:			Union[str, Any]        =					subprocess.check_output(["""python""", str(UpperCamelCase_				)]				)
				assert fingerprinta == fingerprinta




def 							_UpperCAmelCase     ():
				'''simple docstring'''
				_lowerCAmelCase			:			int        =					{"""a""": [0, 1, 2]}
				_lowerCAmelCase			:			Union[str, Any]        =					DatasetChild(InMemoryTable.from_pydict(UpperCamelCase_				)				)
				_lowerCAmelCase			:			Optional[Any]        =					dataset.funca()._fingerprint
				assert expected_fingerprint == dataset.funca()._fingerprint
				assert expected_fingerprint != dataset.funca()._fingerprint

				with Pool(2				) as p:
								assert expected_fingerprint == p.apply_async(dataset.funca				).get()._fingerprint
								assert expected_fingerprint != p.apply_async(dataset.funca				).get()._fingerprint




def 							_UpperCAmelCase     ():
				'''simple docstring'''
				_lowerCAmelCase			:			Optional[Any]        =					{"""a""": [0, 1, 2]}
				class 				__snake_case     (datasets.Dataset						):



								@fingerprint_transform(inplace=_UpperCAmelCase					)
								def 					SCREAMING_SNAKE_CASE				(					self					:						str						,		_UpperCAmelCase					:						List[Any]					)     ->			int:





												'''simple docstring'''




												return DummyDatasetChild(self.data						,		fingerprint=_UpperCAmelCase					)






				_lowerCAmelCase			:			Any        =					DummyDatasetChild(InMemoryTable.from_pydict(UpperCamelCase_				)				).func()
				class 				__snake_case     (datasets.Dataset						):



								@fingerprint_transform(inplace=_UpperCAmelCase						,		version="""1.0.0"""					)
								def 					SCREAMING_SNAKE_CASE				(					self					:						Optional[Any]						,		_UpperCAmelCase					:						Tuple					)     ->			List[Any]:





												'''simple docstring'''




												return DummyDatasetChild(self.data						,		fingerprint=_UpperCAmelCase					)






				_lowerCAmelCase			:			List[str]        =					DummyDatasetChild(InMemoryTable.from_pydict(UpperCamelCase_				)				).func()
				class 				__snake_case     (datasets.Dataset						):



								@fingerprint_transform(inplace=_UpperCAmelCase						,		version="""2.0.0"""					)
								def 					SCREAMING_SNAKE_CASE				(					self					:						Optional[int]						,		_UpperCAmelCase					:						List[Any]					)     ->			int:





												'''simple docstring'''




												return DummyDatasetChild(self.data						,		fingerprint=_UpperCAmelCase					)






				_lowerCAmelCase			:			Tuple        =					DummyDatasetChild(InMemoryTable.from_pydict(UpperCamelCase_				)				).func()

				assert len({fingeprint_no_version, fingeprint_a, fingeprint_a}				) == 3





def 							_UpperCAmelCase     ():
				'''simple docstring'''
				# AttributeError: module 'dill._dill' has no attribute 'stack'
				_lowerCAmelCase			:			Optional[Any]        =					Hasher()
				hasher.update(lambda UpperCamelCase_				: x				)







def 							_UpperCAmelCase     (UpperCamelCase_       :       int					,			UpperCamelCase_       :       Optional[int]				):
				'''simple docstring'''
				_lowerCAmelCase			:			Dict        =					len(UpperCamelCase_				)
				# Create a stack and push index of fist element to it
				_lowerCAmelCase			:			Tuple        =					[]
				st.append(0				)

				# Span value of first element is always 1
				_lowerCAmelCase			:			List[Any]        =					1

				# Calculate span values for rest of the elements
				for i in range(1					,			UpperCamelCase_				):
								# Pop elements from stack while stack is not
								# empty and top of stack is smaller than price[i]
								while len(UpperCamelCase_				) > 0 and price[st[0]] <= price[i]:
												st.pop()

								# If stack becomes empty, then price[i] is greater
								# than all elements on left of it, i.e. price[0],
								# price[1], ..price[i-1]. Else the price[i]  is
								# greater than elements after top of stack
								_lowerCAmelCase			:			Union[str, Any]        =					i + 1 if len(UpperCamelCase_				) <= 0 else (i - st[0])

								# Push this element to stack
								st.append(UpperCamelCase_				)




def 							_UpperCAmelCase     (UpperCamelCase_       :       Dict					,			UpperCamelCase_       :       Union[str, Any]				):
				'''simple docstring'''
				for i in range(0					,			UpperCamelCase_				):
								print(arr[i]					,			end=""" """				)


# Driver program to test above function
_lowerCamelCase					:     Union[str, Any]					  =  [1_0, 4, 5, 9_0, 1_2_0, 8_0]
_lowerCamelCase					:     List[Any]					  =  [0 for i in range(len(price) + 1)]

# Fill the span values in array S[]
calculation_span(price, S)





print_array(S, len(price))

