


"""simple docstring"""






import copy
import os
import tempfile
from unittest import TestCase
from unittest.mock import patch

import numpy as np
import pyarrow as pa
import pyarrow.parquet as pq
import pytest

from datasets.arrow_writer import ArrowWriter, OptimizedTypedSequence, ParquetWriter, TypedSequence
from datasets.features import ArrayaD, ClassLabel, Features, Image, Value
from datasets.features.features import ArrayaDExtensionType, cast_to_python_objects
from datasets.keyhash import DuplicatedKeysError, InvalidKeyError

from .utils import require_pil





class      lowerCamelCase__   (     A				):







					"""simple docstring"""


					def lowerCamelCase__							(       self    : Tuple  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Tuple      							=					pa.array(TypedSequence([1, 2, 3]  )  )
												self.assertEqual(arr.type ,       pa.intaa()  )






					def lowerCamelCase__							(       self    : List[str]  ):
												'''simple docstring'''






												with self.assertRaises(UpperCamelCase  ):
																			__UpperCAmelCase   :						str      							=					pa.array(TypedSequence([1, 2, 3]  ) ,       type=pa.intaa()  )






					def lowerCamelCase__							(       self    : Union[str, Any]  ):
												'''simple docstring'''






												with self.assertRaises(UpperCamelCase  ):
																			__UpperCAmelCase   :						str      							=					pa.array(TypedSequence([1, 2, 3] ,       try_type=Value("""bool"""  ) ,       type=Value("""int64"""  )  )  )






					def lowerCamelCase__							(       self    : str  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Tuple      							=					pa.array(TypedSequence([1, 2, 3] ,       type=Value("""int32"""  )  )  )
												self.assertEqual(arr.type ,       pa.intaa()  )






					def lowerCamelCase__							(       self    : Tuple  ):
												'''simple docstring'''






												with self.assertRaises((TypeError, pa.lib.ArrowInvalid)  ):
																			__UpperCAmelCase   :						Any      							=					pa.array(TypedSequence(["""foo""", """bar"""] ,       type=Value("""int64"""  )  )  )






					def lowerCamelCase__							(       self    : Tuple  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Dict      							=					pa.array(TypedSequence([1, 2, 3] ,       try_type=Value("""int32"""  )  )  )
												self.assertEqual(arr.type ,       pa.intaa()  )






					def lowerCamelCase__							(       self    : List[str]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Tuple      							=					pa.array(TypedSequence(["""foo""", """bar"""] ,       try_type=Value("""int64"""  )  )  )
												self.assertEqual(arr.type ,       pa.string()  )






					def lowerCamelCase__							(       self    : List[str]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Tuple      							=					pa.array(TypedSequence([[[1, 2, 3]]] ,       type=ArrayaD((1, 3) ,       """int64"""  )  )  )
												self.assertEqual(arr.type ,       ArrayaDExtensionType((1, 3) ,       """int64"""  )  )






					def lowerCamelCase__							(       self    : Tuple  ):
												'''simple docstring'''






												with self.assertRaises((TypeError, pa.lib.ArrowInvalid)  ):
																			__UpperCAmelCase   :						Tuple      							=					pa.array(TypedSequence(["""foo""", """bar"""] ,       type=ArrayaD((1, 3) ,       """int64"""  )  )  )






					def lowerCamelCase__							(       self    : Union[str, Any]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Optional[Any]      							=					pa.array(TypedSequence([[[1, 2, 3]]] ,       try_type=ArrayaD((1, 3) ,       """int64"""  )  )  )
												self.assertEqual(arr.type ,       ArrayaDExtensionType((1, 3) ,       """int64"""  )  )






					def lowerCamelCase__							(       self    : Optional[Any]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						str      							=					pa.array(TypedSequence(["""foo""", """bar"""] ,       try_type=ArrayaD((1, 3) ,       """int64"""  )  )  )
												self.assertEqual(arr.type ,       pa.string()  )






					@require_pil
					def lowerCamelCase__							(       self    : Optional[Any]  ):
												'''simple docstring'''






												import PIL.Image

												__UpperCAmelCase   :						List[str]      							=					PIL.Image.fromarray(np.arange(10 ,       dtype=np.uinta  ).reshape(2 ,       5  )  )
												with patch(
												    """datasets.arrow_writer.cast_to_python_objects""" ,       side_effect=UpperCamelCase  ) as mock_cast_to_python_objects:
																			__UpperCAmelCase   :						Tuple      							=					pa.array(TypedSequence([{"""path""": None, """bytes""": b"""image_bytes"""}, pil_image] ,       type=Image()  )  )
																			__UpperCAmelCase							,__UpperCAmelCase   :						List[str]      							=					mock_cast_to_python_objects.call_args_list[-1]
																			self.assertIn("""optimize_list_casting""" ,       UpperCamelCase  )
																			self.assertFalse(kwargs["""optimize_list_casting"""]  )






def      lowerCamelCase       (     _UpperCamelCase		:      Optional[int]       ,			_UpperCamelCase		:      int							)		->       str:

							'''simple docstring'''



							__UpperCAmelCase   :						List[Any]      							=					pa.BufferReader(_UpperCamelCase							) if isinstance(_UpperCamelCase       ,			pa.Buffer							) else pa.memory_map(_UpperCamelCase							)
							__UpperCAmelCase   :						Optional[int]      							=					pa.ipc.open_stream(_UpperCamelCase							)
							__UpperCAmelCase   :						pa.Table      							=					f.read_all()
							assert len(pa_table.to_batches()							) == expected_num_chunks
							assert pa_table.to_pydict() == {"col_1": ["foo", "bar"], "col_2": [1, 2]}
							del pa_table
@pytest.mark.parametrize("""writer_batch_size"""       ,			[None, 1, 1_0]							)
@pytest.mark.parametrize(
    """fields"""       ,			[None, {"""col_1""": pa.string(), """col_2""": pa.intaa()}, {"""col_1""": pa.string(), """col_2""": pa.intaa()}]							)
def      lowerCamelCase       (     _UpperCamelCase		:      List[Any]       ,			_UpperCamelCase		:      int							)		->       Tuple:

							'''simple docstring'''



							__UpperCAmelCase   :						str      							=					pa.BufferOutputStream()
							__UpperCAmelCase   :						List[Any]      							=					pa.schema(_UpperCamelCase							) if fields else None
							with ArrowWriter(stream=_UpperCamelCase       ,			schema=_UpperCamelCase       ,			writer_batch_size=_UpperCamelCase							) as writer:
														writer.write({"""col_1""": """foo""", """col_2""": 1}							)
														writer.write({"""col_1""": """bar""", """col_2""": 2}							)
														__UpperCAmelCase							,__UpperCAmelCase   :						Tuple      							=					writer.finalize()
							assert num_examples == 2
							assert num_bytes > 0
							if not fields:
														__UpperCAmelCase   :						Optional[Any]      							=					{"""col_1""": pa.string(), """col_2""": pa.intaa()}
							assert writer._schema == pa.schema(_UpperCamelCase       ,			metadata=writer._schema.metadata							)
							_check_output(output.getvalue()       ,			expected_num_chunks=num_examples if writer_batch_size == 1 else 1							)
def      lowerCamelCase       (     )		->       Optional[Any]:

							'''simple docstring'''



							__UpperCAmelCase   :						List[Any]      							=					pa.BufferOutputStream()
							__UpperCAmelCase   :						Any      							=					Features({"""labels""": ClassLabel(names=["""neg""", """pos"""]							)}							)
							with ArrowWriter(stream=_UpperCamelCase       ,			features=_UpperCamelCase							) as writer:
														writer.write({"""labels""": 0}							)
														writer.write({"""labels""": 1}							)
														__UpperCAmelCase							,__UpperCAmelCase   :						str      							=					writer.finalize()
							assert num_examples == 2
							assert num_bytes > 0
							assert writer._schema == features.arrow_schema
							assert writer._schema.metadata == features.arrow_schema.metadata
							__UpperCAmelCase   :						Optional[Any]      							=					pa.BufferReader(output.getvalue()							)
							__UpperCAmelCase   :						int      							=					pa.ipc.open_stream(_UpperCamelCase							)
							__UpperCAmelCase   :						pa.Table      							=					f.read_all()
							__UpperCAmelCase   :						Tuple      							=					pa_table.schema
							assert pa_table.num_rows == 2
							assert schema == features.arrow_schema
							assert schema.metadata == features.arrow_schema.metadata
							assert features == Features.from_arrow_schema(_UpperCamelCase							)
@pytest.mark.parametrize("""writer_batch_size"""       ,			[None, 1, 1_0]							)
def      lowerCamelCase       (     _UpperCamelCase		:      str							)		->       Union[str, Any]:

							'''simple docstring'''



							__UpperCAmelCase   :						int      							=					pa.BufferOutputStream()
							with ArrowWriter(
							    stream=_UpperCamelCase       ,			writer_batch_size=_UpperCamelCase       ,			hash_salt="""split_name"""       ,			check_duplicates=_UpperCamelCase       ,			) as writer:
														with pytest.raises(_UpperCamelCase							):
																					writer.write({"""col_1""": """foo""", """col_2""": 1}       ,			key=[1, 2]							)
																					__UpperCAmelCase							,__UpperCAmelCase   :						List[str]      							=					writer.finalize()
@pytest.mark.parametrize("""writer_batch_size"""       ,			[None, 2, 1_0]							)
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[int]							)		->       List[str]:

							'''simple docstring'''



							__UpperCAmelCase   :						Optional[Any]      							=					pa.BufferOutputStream()
							with ArrowWriter(
							    stream=_UpperCamelCase       ,			writer_batch_size=_UpperCamelCase       ,			hash_salt="""split_name"""       ,			check_duplicates=_UpperCamelCase       ,			) as writer:
														with pytest.raises(_UpperCamelCase							):
																					writer.write({"""col_1""": """foo""", """col_2""": 1}       ,			key=1_0							)
																					writer.write({"""col_1""": """bar""", """col_2""": 2}       ,			key=1_0							)
																					__UpperCAmelCase							,__UpperCAmelCase   :						List[Any]      							=					writer.finalize()
@pytest.mark.parametrize("""writer_batch_size"""       ,			[None, 2, 1_0]							)
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[int]							)		->       Dict:

							'''simple docstring'''



							__UpperCAmelCase   :						str      							=					pa.BufferOutputStream()
							with ArrowWriter(
							    stream=_UpperCamelCase       ,			writer_batch_size=_UpperCamelCase       ,			hash_salt="""split_name"""       ,			check_duplicates=_UpperCamelCase       ,			) as writer:
														writer.write({"""col_1""": """foo""", """col_2""": 1}       ,			key=1							)
														writer.write({"""col_1""": """bar""", """col_2""": 2}       ,			key=2							)
														__UpperCAmelCase							,__UpperCAmelCase   :						List[Any]      							=					writer.finalize()
							assert num_examples == 2
							assert num_bytes > 0
							_check_output(output.getvalue()       ,			expected_num_chunks=num_examples if writer_batch_size == 1 else 1							)
@pytest.mark.parametrize("""writer_batch_size"""       ,			[None, 1, 1_0]							)
@pytest.mark.parametrize(
    """fields"""       ,			[None, {"""col_1""": pa.string(), """col_2""": pa.intaa()}, {"""col_1""": pa.string(), """col_2""": pa.intaa()}]							)
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[Any]       ,			_UpperCamelCase		:      List[Any]							)		->       Dict:

							'''simple docstring'''



							__UpperCAmelCase   :						Tuple      							=					pa.BufferOutputStream()
							__UpperCAmelCase   :						List[Any]      							=					pa.schema(_UpperCamelCase							) if fields else None
							with ArrowWriter(stream=_UpperCamelCase       ,			schema=_UpperCamelCase       ,			writer_batch_size=_UpperCamelCase							) as writer:
														writer.write_batch({"""col_1""": ["""foo""", """bar"""], """col_2""": [1, 2]}							)
														writer.write_batch({"""col_1""": [], """col_2""": []}							)
														__UpperCAmelCase							,__UpperCAmelCase   :						List[Any]      							=					writer.finalize()
							assert num_examples == 2
							assert num_bytes > 0
							if not fields:
														__UpperCAmelCase   :						Dict      							=					{"""col_1""": pa.string(), """col_2""": pa.intaa()}
							assert writer._schema == pa.schema(_UpperCamelCase       ,			metadata=writer._schema.metadata							)
							_check_output(output.getvalue()       ,			expected_num_chunks=num_examples if writer_batch_size == 1 else 1							)
@pytest.mark.parametrize("""writer_batch_size"""       ,			[None, 1, 1_0]							)
@pytest.mark.parametrize(
    """fields"""       ,			[None, {"""col_1""": pa.string(), """col_2""": pa.intaa()}, {"""col_1""": pa.string(), """col_2""": pa.intaa()}]							)
def      lowerCamelCase       (     _UpperCamelCase		:      str       ,			_UpperCamelCase		:      Dict							)		->       Tuple:

							'''simple docstring'''



							__UpperCAmelCase   :						Optional[int]      							=					pa.BufferOutputStream()
							__UpperCAmelCase   :						Optional[Any]      							=					pa.schema(_UpperCamelCase							) if fields else None
							with ArrowWriter(stream=_UpperCamelCase       ,			schema=_UpperCamelCase       ,			writer_batch_size=_UpperCamelCase							) as writer:
														writer.write_table(pa.Table.from_pydict({"""col_1""": ["""foo""", """bar"""], """col_2""": [1, 2]}							)							)
														__UpperCAmelCase							,__UpperCAmelCase   :						str      							=					writer.finalize()
							assert num_examples == 2
							assert num_bytes > 0
							if not fields:
														__UpperCAmelCase   :						int      							=					{"""col_1""": pa.string(), """col_2""": pa.intaa()}
							assert writer._schema == pa.schema(_UpperCamelCase       ,			metadata=writer._schema.metadata							)
							_check_output(output.getvalue()       ,			expected_num_chunks=num_examples if writer_batch_size == 1 else 1							)
@pytest.mark.parametrize("""writer_batch_size"""       ,			[None, 1, 1_0]							)
@pytest.mark.parametrize(
    """fields"""       ,			[None, {"""col_1""": pa.string(), """col_2""": pa.intaa()}, {"""col_1""": pa.string(), """col_2""": pa.intaa()}]							)
def      lowerCamelCase       (     _UpperCamelCase		:      int       ,			_UpperCamelCase		:      Optional[int]							)		->       Any:

							'''simple docstring'''



							__UpperCAmelCase   :						List[str]      							=					pa.BufferOutputStream()
							__UpperCAmelCase   :						Union[str, Any]      							=					pa.schema(_UpperCamelCase							) if fields else None
							with ArrowWriter(stream=_UpperCamelCase       ,			schema=_UpperCamelCase       ,			writer_batch_size=_UpperCamelCase							) as writer:
														writer.write_row(pa.Table.from_pydict({"""col_1""": ["""foo"""], """col_2""": [1]}							)							)
														writer.write_row(pa.Table.from_pydict({"""col_1""": ["""bar"""], """col_2""": [2]}							)							)
														__UpperCAmelCase							,__UpperCAmelCase   :						List[Any]      							=					writer.finalize()
							assert num_examples == 2
							assert num_bytes > 0
							if not fields:
														__UpperCAmelCase   :						Optional[Any]      							=					{"""col_1""": pa.string(), """col_2""": pa.intaa()}
							assert writer._schema == pa.schema(_UpperCamelCase       ,			metadata=writer._schema.metadata							)
							_check_output(output.getvalue()       ,			expected_num_chunks=num_examples if writer_batch_size == 1 else 1							)
def      lowerCamelCase       (     )		->       Optional[Any]:

							'''simple docstring'''



							with tempfile.TemporaryDirectory() as tmp_dir:
														__UpperCAmelCase   :						int      							=					{"""col_1""": pa.string(), """col_2""": pa.intaa()}
														__UpperCAmelCase   :						List[Any]      							=					os.path.join(_UpperCamelCase       ,			"""test.arrow"""							)
														with ArrowWriter(path=_UpperCamelCase       ,			schema=pa.schema(_UpperCamelCase							)							) as writer:
																					writer.write_batch({"""col_1""": ["""foo""", """bar"""], """col_2""": [1, 2]}							)
																					__UpperCAmelCase							,__UpperCAmelCase   :						List[Any]      							=					writer.finalize()
														assert num_examples == 2
														assert num_bytes > 0
														assert writer._schema == pa.schema(_UpperCamelCase       ,			metadata=writer._schema.metadata							)
														_check_output(_UpperCamelCase       ,			1							)
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[Any]							)		->       Any:

							'''simple docstring'''



							if pa.types.is_list(_UpperCamelCase							):
														return get_base_dtype(arr_type.value_type							)
							else:
														return arr_type
def      lowerCamelCase       (     _UpperCamelCase		:      Union[str, Any]       ,			_UpperCamelCase		:      Tuple							)		->       Optional[int]:

							'''simple docstring'''



							if isinstance(lst[0]       ,			_UpperCamelCase							):
														change_first_primitive_element_in_list(lst[0]       ,			_UpperCamelCase							)
							else:
														__UpperCAmelCase   :						List[Any]      							=					value
@pytest.mark.parametrize("""optimized_int_type, expected_dtype"""       ,			[(None, pa.intaa()), (Value("""int32"""							), pa.intaa())]							)
@pytest.mark.parametrize("""sequence"""       ,			[[1, 2, 3], [[1, 2, 3]], [[[1, 2, 3]]]]							)
def      lowerCamelCase       (     _UpperCamelCase		:      Tuple       ,			_UpperCamelCase		:      int       ,			_UpperCamelCase		:      int							)		->       str:

							'''simple docstring'''



							__UpperCAmelCase   :						Optional[Any]      							=					pa.array(TypedSequence(_UpperCamelCase       ,			optimized_int_type=_UpperCamelCase							)							)
							assert get_base_dtype(arr.type							) == expected_dtype
@pytest.mark.parametrize(
    """col, expected_dtype"""       ,			[
        ("""attention_mask""", pa.inta()),
        ("""special_tokens_mask""", pa.inta()),
        ("""token_type_ids""", pa.inta()),
        ("""input_ids""", pa.intaa()),
        ("""other""", pa.intaa()),
    ]       ,			)
@pytest.mark.parametrize("""sequence"""       ,			[[1, 2, 3], [[1, 2, 3]], [[[1, 2, 3]]]]							)
def      lowerCamelCase       (     _UpperCamelCase		:      Tuple       ,			_UpperCamelCase		:      Any       ,			_UpperCamelCase		:      List[str]							)		->       List[str]:

							'''simple docstring'''



							__UpperCAmelCase   :						Union[str, Any]      							=					pa.array(OptimizedTypedSequence(_UpperCamelCase       ,			col=_UpperCamelCase							)							)
							assert get_base_dtype(arr.type							) == expected_dtype

							# not in range
							if col != "other":
														# avoids errors due to in-place modifications
														__UpperCAmelCase   :						Optional[Any]      							=					copy.deepcopy(_UpperCamelCase							)
														__UpperCAmelCase   :						Optional[int]      							=					np.iinfo(expected_dtype.to_pandas_dtype()							).max + 1
														change_first_primitive_element_in_list(_UpperCamelCase       ,			_UpperCamelCase							)
														__UpperCAmelCase   :						Any      							=					pa.array(OptimizedTypedSequence(_UpperCamelCase       ,			col=_UpperCamelCase							)							)
														assert get_base_dtype(arr.type							) == pa.intaa()
@pytest.mark.parametrize("""raise_exception"""       ,			[False, True]							)
def      lowerCamelCase       (     _UpperCamelCase		:      str       ,			_UpperCamelCase		:      List[Any]							)		->       List[Any]:

							'''simple docstring'''



							__UpperCAmelCase   :						Optional[Any]      							=					str(tmp_path / """dataset-train.arrow"""							)
							try:
														with ArrowWriter(path=_UpperCamelCase							) as writer:
																					if raise_exception:
																												raise pa.lib.ArrowInvalid()
																					else:
																												writer.stream.close()
							except pa.lib.ArrowInvalid:
														pass
							finally:
														assert writer.stream.closed
def      lowerCamelCase       (     _UpperCamelCase		:      Dict							)		->       Dict:

							'''simple docstring'''



							__UpperCAmelCase   :						Tuple      							=					"""mock://dataset-train.arrow"""
							with ArrowWriter(path=_UpperCamelCase       ,			storage_options=mockfs.storage_options							) as writer:
														assert isinstance(writer._fs       ,			type(_UpperCamelCase							)							)
														assert writer._fs.storage_options == mockfs.storage_options
														writer.write({"""col_1""": """foo""", """col_2""": 1}							)
														writer.write({"""col_1""": """bar""", """col_2""": 2}							)
														__UpperCAmelCase							,__UpperCAmelCase   :						List[Any]      							=					writer.finalize()
							assert num_examples == 2
							assert num_bytes > 0
							assert mockfs.exists(_UpperCamelCase							)
def      lowerCamelCase       (     )		->       Optional[int]:

							'''simple docstring'''



							__UpperCAmelCase   :						Any      							=					pa.BufferOutputStream()
							with ParquetWriter(stream=_UpperCamelCase							) as writer:
														writer.write({"""col_1""": """foo""", """col_2""": 1}							)
														writer.write({"""col_1""": """bar""", """col_2""": 2}							)
														__UpperCAmelCase							,__UpperCAmelCase   :						Any      							=					writer.finalize()
							assert num_examples == 2
							assert num_bytes > 0
							__UpperCAmelCase   :						int      							=					pa.BufferReader(output.getvalue()							)
							__UpperCAmelCase   :						pa.Table      							=					pq.read_table(_UpperCamelCase							)
							assert pa_table.to_pydict() == {"col_1": ["foo", "bar"], "col_2": [1, 2]}
@require_pil
@pytest.mark.parametrize("""embed_local_files"""       ,			[False, True]							)
def      lowerCamelCase       (     _UpperCamelCase		:      int       ,			_UpperCamelCase		:      List[Any]							)		->       Optional[int]:

							'''simple docstring'''



							import PIL.Image

							__UpperCAmelCase   :						List[Any]      							=					str(tmp_path / """test_image_rgb.jpg"""							)
							PIL.Image.fromarray(np.zeros((5, 5)       ,			dtype=np.uinta							)							).save(_UpperCamelCase       ,			format="""png"""							)
							__UpperCAmelCase   :						Tuple      							=					pa.BufferOutputStream()
							with ParquetWriter(
							    stream=_UpperCamelCase       ,			features=Features({"""image""": Image()}							)       ,			embed_local_files=_UpperCamelCase							) as writer:
														writer.write({"""image""": image_path}							)
														writer.finalize()
							__UpperCAmelCase   :						str      							=					pa.BufferReader(output.getvalue()							)
							__UpperCAmelCase   :						pa.Table      							=					pq.read_table(_UpperCamelCase							)
							__UpperCAmelCase   :						Dict      							=					pa_table.to_pydict()
							if embed_local_files:
														assert isinstance(out["""image"""][0]["""path"""]       ,			_UpperCamelCase							)
														with open(_UpperCamelCase       ,			"""rb"""							) as f:
																					assert out["image"][0]["bytes"] == f.read()
							else:
														assert out["image"][0]["path"] == image_path
														assert out["image"][0]["bytes"] is None
def      lowerCamelCase       (     )		->       int:

							'''simple docstring'''



							__UpperCAmelCase   :						Tuple      							=					pa.schema([pa.field("""col_1"""       ,			pa.string()       ,			nullable=_UpperCamelCase							)]							)
							__UpperCAmelCase   :						Union[str, Any]      							=					pa.BufferOutputStream()
							with ArrowWriter(stream=_UpperCamelCase							) as writer:
														writer._build_writer(inferred_schema=_UpperCamelCase							)
														assert writer._schema == pa.schema([pa.field("""col_1"""       ,			pa.string()							)]							)




"""simple docstring"""






import unittest

from datasets import load_dataset

from transformers import BloomTokenizerFast
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin





@require_tokenizers
class      lowerCamelCase__   (     A     ,    unittest.TestCase				):







					"""simple docstring"""


					__a	       =							None
					__a	       =							BloomTokenizerFast
					__a	       =							BloomTokenizerFast
					__a	       =							True
					__a	       =							False
					__a	       =							"""tokenizer_file"""
					__a	       =							{"""bos_token""": """<s>""", """eos_token""": """</s>""", """unk_token""": """<unk>""", """pad_token""": """<pad>"""}






					def lowerCamelCase__							(       self    : int  ):
												'''simple docstring'''






												super().setUp()
												__UpperCAmelCase   :						Any      							=					BloomTokenizerFast.from_pretrained("""bigscience/tokenizer"""  )
												tokenizer.save_pretrained(self.tmpdirname  )






					def lowerCamelCase__							(       self    : Any ,       **UpperCamelCase    : Optional[int]  ):
												'''simple docstring'''






												kwargs.update(self.special_tokens_map  )
												return BloomTokenizerFast.from_pretrained(self.tmpdirname ,       **UpperCamelCase  )






					def lowerCamelCase__							(       self    : Optional[Any]  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Any      							=					self.get_rust_tokenizer()

												__UpperCAmelCase   :						Optional[Any]      							=					["""The quick brown fox</s>""", """jumps over the lazy dog</s>"""]
												__UpperCAmelCase   :						int      							=					[[2_175, 23_714, 73_173, 144_252, 2], [77, 132_619, 3_478, 368, 109_586, 35_433, 2]]

												__UpperCAmelCase   :						Dict      							=					tokenizer.batch_encode_plus(UpperCamelCase  )["""input_ids"""]
												self.assertListEqual(UpperCamelCase ,       UpperCamelCase  )

												__UpperCAmelCase   :						int      							=					tokenizer.batch_decode(UpperCamelCase  )
												self.assertListEqual(UpperCamelCase ,       UpperCamelCase  )






					def lowerCamelCase__							(       self    : int ,       UpperCamelCase    : Any=6  ):
												'''simple docstring'''






												for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																			with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''  ):
																										__UpperCAmelCase   :						Optional[int]      							=					self.rust_tokenizer_class.from_pretrained(UpperCamelCase ,       **UpperCamelCase  )
																										# tokenizer_r.pad_token = None # Hotfixing padding = None
																										# Simple input
																										__UpperCAmelCase   :						Dict      							=					"""This is a simple input"""
																										__UpperCAmelCase   :						str      							=					["""This is a simple input 1""", """This is a simple input 2"""]
																										__UpperCAmelCase   :						List[str]      							=					("""This is a simple input""", """This is a pair""")
																										__UpperCAmelCase   :						Dict      							=					[
																										    ("""This is a simple input 1""", """This is a simple input 2"""),
																										    ("""This is a simple pair 1""", """This is a simple pair 2"""),
																										]

																										# Simple input tests
																										try:
																																	tokenizer_r.encode(UpperCamelCase ,       max_length=UpperCamelCase  )
																																	tokenizer_r.encode_plus(UpperCamelCase ,       max_length=UpperCamelCase  )

																																	tokenizer_r.batch_encode_plus(UpperCamelCase ,       max_length=UpperCamelCase  )
																																	tokenizer_r.encode(UpperCamelCase ,       max_length=UpperCamelCase  )
																																	tokenizer_r.batch_encode_plus(UpperCamelCase ,       max_length=UpperCamelCase  )
																										except ValueError:
																																	self.fail("""Bloom Tokenizer should be able to deal with padding"""  )

																										__UpperCAmelCase   :						Union[str, Any]      							=					None  # Hotfixing padding = None
																										self.assertRaises(UpperCamelCase ,       tokenizer_r.encode ,       UpperCamelCase ,       max_length=UpperCamelCase ,       padding="""max_length"""  )

																										# Simple input
																										self.assertRaises(UpperCamelCase ,       tokenizer_r.encode_plus ,       UpperCamelCase ,       max_length=UpperCamelCase ,       padding="""max_length"""  )

																										# Simple input
																										self.assertRaises(
																										    UpperCamelCase ,       tokenizer_r.batch_encode_plus ,       UpperCamelCase ,       max_length=UpperCamelCase ,       padding="""max_length""" ,       )

																										# Pair input
																										self.assertRaises(UpperCamelCase ,       tokenizer_r.encode ,       UpperCamelCase ,       max_length=UpperCamelCase ,       padding="""max_length"""  )

																										# Pair input
																										self.assertRaises(UpperCamelCase ,       tokenizer_r.encode_plus ,       UpperCamelCase ,       max_length=UpperCamelCase ,       padding="""max_length"""  )

																										# Pair input
																										self.assertRaises(
																										    UpperCamelCase ,       tokenizer_r.batch_encode_plus ,       UpperCamelCase ,       max_length=UpperCamelCase ,       padding="""max_length""" ,       )






					def lowerCamelCase__							(       self    : Any  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Union[str, Any]      							=					self.get_rust_tokenizer()
												__UpperCAmelCase   :						Optional[Any]      							=					load_dataset("""xnli""" ,       """all_languages""" ,       split="""test""" ,       streaming=UpperCamelCase  )

												__UpperCAmelCase   :						Optional[Any]      							=					next(iter(UpperCamelCase  )  )["""premise"""]  # pick up one data
												__UpperCAmelCase   :						Any      							=					list(sample_data.values()  )

												__UpperCAmelCase   :						Optional[Any]      							=					list(map(tokenizer.encode ,       UpperCamelCase  )  )
												__UpperCAmelCase   :						List[Any]      							=					[tokenizer.decode(UpperCamelCase ,       clean_up_tokenization_spaces=UpperCamelCase  ) for x in output_tokens]
												self.assertListEqual(UpperCamelCase ,       UpperCamelCase  )






					def lowerCamelCase__							(       self    : Optional[Any]  ):
												'''simple docstring'''






												self.assertGreaterEqual(len(self.tokenizer_class.pretrained_vocab_files_map  ) ,       1  )
												self.assertGreaterEqual(len(list(self.tokenizer_class.pretrained_vocab_files_map.values()  )[0]  ) ,       1  )
