






import shutil
import tempfile
import unittest

from transformers import (
    SPIECE_UNDERLINE,
    AddedToken,
    BatchEncoding,
    NllbTokenizer,
    NllbTokenizerFast,
    is_torch_available,
)
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
)

from ...test_tokenization_common import TokenizerTesterMixin


__UpperCamelCase					:		Tuple	  =						get_tests_dir("""fixtures/test_sentencepiece.model""")


if is_torch_available():
							from transformers.models.mam_aaa.modeling_mam_aaa import shift_tokens_right

__UpperCamelCase					:		Dict	  =						256047
__UpperCamelCase					:		int	  =						256145


@require_sentencepiece
@require_tokenizers
class   __SCREAMING_SNAKE_CASE(	lowerCAmelCase__    ,  unittest.TestCase	):
							_UpperCAmelCase     =       NllbTokenizer
							_UpperCAmelCase     =       NllbTokenizerFast
							_UpperCAmelCase     =       True
							_UpperCAmelCase     =       True
							_UpperCAmelCase     =       {}
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		Tuple:
											super().setUp()

											# We have a SentencePiece fixture for testing
											snake_case__									=     NllbTokenizer(_lowerCamelCase       ,	keep_accents=_lowerCamelCase						)
											tokenizer.save_pretrained(self.tmpdirname						)
							def lowerCAmelCase_ (     self:      List[str]						)		->		List[str]:
											snake_case__									=     NllbTokenizer(_lowerCamelCase       ,	keep_accents=_lowerCamelCase						)

											snake_case__									=     tokenizer.tokenize('This is a test'						)
											self.assertListEqual(_lowerCamelCase       ,	['▁This', '▁is', '▁a', '▁t', 'est']						)

											self.assertListEqual(
											    tokenizer.convert_tokens_to_ids(_lowerCamelCase						)       ,	[value + tokenizer.fairseq_offset for value in [2_85, 46, 10, 1_70, 3_82]]       ,	)

											snake_case__									=     tokenizer.tokenize('I was born in 92000, and this is falsé.'						)
											self.assertListEqual(
											    _lowerCamelCase       ,	[
											        SPIECE_UNDERLINE + 'I',
											        SPIECE_UNDERLINE + 'was',
											        SPIECE_UNDERLINE + 'b',
											        'or',
											        'n',
											        SPIECE_UNDERLINE + 'in',
											        SPIECE_UNDERLINE + '',
											        '9',
											        '2',
											        '0',
											        '0',
											        '0',
											        ',',
											        SPIECE_UNDERLINE + 'and',
											        SPIECE_UNDERLINE + 'this',
											        SPIECE_UNDERLINE + 'is',
											        SPIECE_UNDERLINE + 'f',
											        'al',
											        's',
											        'é',
											        '.',
											    ]       ,	)
											snake_case__									=     tokenizer.convert_tokens_to_ids(_lowerCamelCase						)
											self.assertListEqual(
											    _lowerCamelCase       ,	[
											        value + tokenizer.fairseq_offset
											        for value in [8, 21, 84, 55, 24, 19, 7, 2, 6_02, 3_47, 3_47, 3_47, 3, 12, 66, 46, 72, 80, 6, 2, 4]
											    ]       ,	)

											snake_case__									=     tokenizer.convert_ids_to_tokens(_lowerCamelCase						)
											self.assertListEqual(
											    _lowerCamelCase       ,	[
											        SPIECE_UNDERLINE + 'I',
											        SPIECE_UNDERLINE + 'was',
											        SPIECE_UNDERLINE + 'b',
											        'or',
											        'n',
											        SPIECE_UNDERLINE + 'in',
											        SPIECE_UNDERLINE + '',
											        '<unk>',
											        '2',
											        '0',
											        '0',
											        '0',
											        ',',
											        SPIECE_UNDERLINE + 'and',
											        SPIECE_UNDERLINE + 'this',
											        SPIECE_UNDERLINE + 'is',
											        SPIECE_UNDERLINE + 'f',
											        'al',
											        's',
											        '<unk>',
											        '.',
											    ]       ,	)
							def lowerCAmelCase_ (     self:      Optional[Any]						)		->		List[str]:
											snake_case__									=     (self.rust_tokenizer_class, 'hf-internal-testing/tiny-random-nllb', {})
											for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
															with self.subTest(F'''{tokenizer.__class__.__name__} ({pretrained_name})'''						):
																			snake_case__									=     self.rust_tokenizer_class.from_pretrained(_lowerCamelCase       ,	**_lowerCamelCase						)
																			snake_case__									=     self.tokenizer_class.from_pretrained(_lowerCamelCase       ,	**_lowerCamelCase						)

																			snake_case__									=     tempfile.mkdtemp()

																			snake_case__									=     tokenizer_r.save_pretrained(_lowerCamelCase						)
																			snake_case__									=     tokenizer_p.save_pretrained(_lowerCamelCase						)

																			# Checks it save with the same files + the tokenizer.json file for the fast one
																			self.assertTrue(any('tokenizer.json' in f for f in tokenizer_r_files						)						)
																			snake_case__									=     tuple(f for f in tokenizer_r_files if 'tokenizer.json' not in f						)
																			self.assertSequenceEqual(_lowerCamelCase       ,	_lowerCamelCase						)

																			# Checks everything loads correctly in the same way
																			snake_case__									=     tokenizer_r.from_pretrained(_lowerCamelCase						)
																			snake_case__									=     tokenizer_p.from_pretrained(_lowerCamelCase						)

																			# Check special tokens are set accordingly on Rust and Python
																			for key in tokenizer_pp.special_tokens_map:
																							self.assertTrue(hasattr(_lowerCamelCase       ,	_lowerCamelCase						)						)

																			shutil.rmtree(_lowerCamelCase						)

																			# Save tokenizer rust, legacy_format=True
																			snake_case__									=     tempfile.mkdtemp()

																			snake_case__									=     tokenizer_r.save_pretrained(_lowerCamelCase       ,	legacy_format=_lowerCamelCase						)
																			snake_case__									=     tokenizer_p.save_pretrained(_lowerCamelCase						)

																			# Checks it save with the same files
																			self.assertSequenceEqual(_lowerCamelCase       ,	_lowerCamelCase						)

																			# Checks everything loads correctly in the same way
																			snake_case__									=     tokenizer_r.from_pretrained(_lowerCamelCase						)
																			snake_case__									=     tokenizer_p.from_pretrained(_lowerCamelCase						)

																			# Check special tokens are set accordingly on Rust and Python
																			for key in tokenizer_pp.special_tokens_map:
																							self.assertTrue(hasattr(_lowerCamelCase       ,	_lowerCamelCase						)						)

																			shutil.rmtree(_lowerCamelCase						)

																			# Save tokenizer rust, legacy_format=False
																			snake_case__									=     tempfile.mkdtemp()

																			snake_case__									=     tokenizer_r.save_pretrained(_lowerCamelCase       ,	legacy_format=_lowerCamelCase						)
																			snake_case__									=     tokenizer_p.save_pretrained(_lowerCamelCase						)

																			# Checks it saved the tokenizer.json file
																			self.assertTrue(any('tokenizer.json' in f for f in tokenizer_r_files						)						)

																			# Checks everything loads correctly in the same way
																			snake_case__									=     tokenizer_r.from_pretrained(_lowerCamelCase						)
																			snake_case__									=     tokenizer_p.from_pretrained(_lowerCamelCase						)

																			# Check special tokens are set accordingly on Rust and Python
																			for key in tokenizer_pp.special_tokens_map:
																							self.assertTrue(hasattr(_lowerCamelCase       ,	_lowerCamelCase						)						)

																			shutil.rmtree(_lowerCamelCase						)
							@require_torch
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		Tuple:





											if not self.test_seqaseq:
															return

											snake_case__									=     self.get_tokenizers()
											for tokenizer in tokenizers:
															with self.subTest(F'''{tokenizer.__class__.__name__}'''						):
																			# Longer text that will definitely require truncation.
																			snake_case__									=     [
																			    ' UN Chief Says There Is No Military Solution in Syria',
																			    ' Secretary-General Ban Ki-moon says his response to Russia\'s stepped up military support for'
																			    ' Syria is that \'there is no military solution\' to the nearly five-year conflict and more weapons'
																			    ' will only worsen the violence and misery for millions of people.',
																			]
																			snake_case__									=     [
																			    'Şeful ONU declară că nu există o soluţie militară în Siria',
																			    'Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al'
																			    ' Rusiei pentru Siria este că "nu există o soluţie militară" la conflictul de aproape cinci ani şi'
																			    ' că noi arme nu vor face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.',
																			]
																			try:
																							snake_case__									=     tokenizer.prepare_seqaseq_batch(
																							    src_texts=_lowerCamelCase       ,	tgt_texts=_lowerCamelCase       ,	max_length=3       ,	max_target_length=10       ,	return_tensors='pt'       ,	src_lang='eng_Latn'       ,	tgt_lang='ron_Latn'       ,	)
																			except NotImplementedError:
																							return
																			self.assertEqual(batch.input_ids.shape[1]       ,	3						)
																			self.assertEqual(batch.labels.shape[1]       ,	10						)
																			# max_target_length will default to max_length if not specified
																			snake_case__									=     tokenizer.prepare_seqaseq_batch(
																			    _lowerCamelCase       ,	tgt_texts=_lowerCamelCase       ,	max_length=3       ,	return_tensors='pt'						)
																			self.assertEqual(batch.input_ids.shape[1]       ,	3						)
																			self.assertEqual(batch.labels.shape[1]       ,	3						)

																			snake_case__									=     tokenizer.prepare_seqaseq_batch(
																			    src_texts=_lowerCamelCase       ,	max_length=3       ,	max_target_length=10       ,	return_tensors='pt'						)
																			self.assertEqual(batch_encoder_only.input_ids.shape[1]       ,	3						)
																			self.assertEqual(batch_encoder_only.attention_mask.shape[1]       ,	3						)
																			self.assertNotIn('decoder_input_ids'       ,	_lowerCamelCase						)
							@unittest.skip('Unfortunately way too slow to build a BPE with SentencePiece.'						)
							def lowerCAmelCase_ (     self:      List[Any]						)		->		Optional[int]:
											pass


							def lowerCAmelCase_ (     self:      int						)		->		Dict:





											for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
															with self.subTest(F'''{tokenizer.__class__.__name__} ({pretrained_name})'''						):
																			snake_case__									=     [AddedToken('<special>'       ,	lstrip=_lowerCamelCase						)]

																			snake_case__									=     self.rust_tokenizer_class.from_pretrained(
																			    _lowerCamelCase       ,	additional_special_tokens=_lowerCamelCase       ,	**_lowerCamelCase						)
																			snake_case__									=     tokenizer_r.encode('Hey this is a <special> token'						)

																			snake_case__									=     tokenizer_r.encode('<special>'       ,	add_special_tokens=_lowerCamelCase						)[0]

																			self.assertTrue(special_token_id in r_output						)

																			if self.test_slow_tokenizer:
																							snake_case__									=     self.rust_tokenizer_class.from_pretrained(
																							    _lowerCamelCase       ,	additional_special_tokens=_lowerCamelCase       ,	**_lowerCamelCase       ,	)
																							snake_case__									=     self.tokenizer_class.from_pretrained(
																							    _lowerCamelCase       ,	additional_special_tokens=_lowerCamelCase       ,	**_lowerCamelCase						)

																							snake_case__									=     tokenizer_p.encode('Hey this is a <special> token'						)

																							snake_case__									=     tokenizer_cr.encode('Hey this is a <special> token'						)

																							self.assertEqual(_lowerCamelCase       ,	_lowerCamelCase						)
																							self.assertEqual(_lowerCamelCase       ,	_lowerCamelCase						)
																							self.assertTrue(special_token_id in p_output						)
																							self.assertTrue(special_token_id in cr_output						)


@require_torch
@require_sentencepiece
@require_tokenizers
class   __SCREAMING_SNAKE_CASE(	unittest.TestCase	):
							_UpperCAmelCase     =       "facebook/nllb-200-distilled-600M"
							_UpperCAmelCase     =       [
							    " UN Chief Says There Is No Military Solution in Syria",
							    " Secretary-General Ban Ki-moon says his response to Russia's stepped up military support for Syria is that \"there is no military solution\" to the nearly five-year conflict and more weapons will only worsen the violence and misery for millions of people.",
							]
							_UpperCAmelCase     =       [
							    "Şeful ONU declară că nu există o soluţie militară în Siria",
							    "Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al Rusiei"
							    " pentru Siria este că \"nu există o soluţie militară\" la conflictul de aproape cinci ani şi că noi arme nu vor"
							    " face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.",
							]
							_UpperCAmelCase     =       [
							    2_5_6_0_4_7,
							    1_6_2_9_7,
							    1_3_4_4_0_8,
							    8_1_6_5,
							    2_4_8_0_6_6,
							    1_4_7_3_4,
							    9_5_0,
							    1_1_3_5,
							    1_0_5_7_2_1,
							    3_5_7_3,
							    8_3,
							    2_7_3_5_2,
							    1_0_8,
							    4_9_4_8_6,
							    2,
							]
							@classmethod
							def lowerCAmelCase_ (     cls:      Union[str, Any]						)		->		Optional[Any]:
											snake_case__									=     NllbTokenizer.from_pretrained(
											    cls.checkpoint_name       ,	src_lang='eng_Latn'       ,	tgt_lang='ron_Latn'						)
											snake_case__									=     1
											return cls
							def lowerCAmelCase_ (     self:      List[Any]						)		->		Optional[int]:
											self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['ace_Arab']       ,	25_60_01						)
											self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['ace_Latn']       ,	25_60_02						)
											self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['fra_Latn']       ,	25_60_57						)
							def lowerCAmelCase_ (     self:      List[str]						)		->		Dict:
											snake_case__									=     self.tokenizer.batch_encode_plus(self.src_text						).input_ids[0]
											self.assertListEqual(self.expected_src_tokens       ,	_lowerCamelCase						)
							def lowerCAmelCase_ (     self:      Optional[int]						)		->		int:
											self.assertIn(_lowerCamelCase       ,	self.tokenizer.all_special_ids						)
											# fmt: off
											snake_case__									=     [RO_CODE, 42_54, 9_80_68, 11_29_23, 3_90_72, 39_09, 7_13, 10_27_67, 26, 1_73_14, 3_56_42, 1_46_83, 3_31_18, 20_22, 6_69_87, 2, 25_60_47]
											# fmt: on

											snake_case__									=     self.tokenizer.decode(_lowerCamelCase       ,	skip_special_tokens=_lowerCamelCase						)
											snake_case__									=     self.tokenizer.decode(generated_ids[1:]       ,	skip_special_tokens=_lowerCamelCase						)
											self.assertEqual(_lowerCamelCase       ,	_lowerCamelCase						)
											self.assertNotIn(self.tokenizer.eos_token       ,	_lowerCamelCase						)
							def lowerCAmelCase_ (     self:      List[str]						)		->		Optional[Any]:
											snake_case__									=     ['this is gunna be a long sentence ' * 20]
											assert isinstance(src_text[0]       ,	_lowerCamelCase						)
											snake_case__									=     10
											snake_case__									=     self.tokenizer(_lowerCamelCase       ,	max_length=_lowerCamelCase       ,	truncation=_lowerCamelCase						).input_ids[0]
											self.assertEqual(ids[-1]       ,	2						)
											self.assertEqual(ids[0]       ,	_lowerCamelCase						)
											self.assertEqual(len(_lowerCamelCase						)       ,	_lowerCamelCase						)
							def lowerCAmelCase_ (     self:      int						)		->		Union[str, Any]:
											self.assertListEqual(self.tokenizer.convert_tokens_to_ids(['<mask>', 'ar_AR']						)       ,	[25_62_03, 3]						)
							def lowerCAmelCase_ (     self:      int						)		->		Union[str, Any]:
											snake_case__									=     tempfile.mkdtemp()
											snake_case__									=     self.tokenizer.fairseq_tokens_to_ids
											self.tokenizer.save_pretrained(_lowerCamelCase						)
											snake_case__									=     NllbTokenizer.from_pretrained(_lowerCamelCase						)
											self.assertDictEqual(new_tok.fairseq_tokens_to_ids       ,	_lowerCamelCase						)
							@require_torch
							def lowerCAmelCase_ (     self:      Any						)		->		Union[str, Any]:
											snake_case__									=     self.tokenizer(
											    self.src_text       ,	text_target=self.tgt_text       ,	padding=_lowerCamelCase       ,	truncation=_lowerCamelCase       ,	max_length=len(self.expected_src_tokens						)       ,	return_tensors='pt'       ,	)
											snake_case__									=     shift_tokens_right(
											    batch['labels']       ,	self.tokenizer.pad_token_id       ,	self.tokenizer.lang_code_to_id['ron_Latn']						)

											self.assertIsInstance(_lowerCamelCase       ,	_lowerCamelCase						)

											self.assertEqual((2, 15)       ,	batch.input_ids.shape						)
											self.assertEqual((2, 15)       ,	batch.attention_mask.shape						)
											snake_case__									=     batch.input_ids.tolist()[0]
											self.assertListEqual(self.expected_src_tokens       ,	_lowerCamelCase						)
											self.assertEqual(_lowerCamelCase       ,	batch.decoder_input_ids[0, 0]						)  # EOS
											# Test that special tokens are reset
											self.assertEqual(self.tokenizer.prefix_tokens       ,	[EN_CODE]						)
											self.assertEqual(self.tokenizer.suffix_tokens       ,	[self.tokenizer.eos_token_id]						)
							def lowerCAmelCase_ (     self:      Any						)		->		Any:
											snake_case__									=     self.tokenizer(self.src_text       ,	padding=_lowerCamelCase       ,	truncation=_lowerCamelCase       ,	max_length=3       ,	return_tensors='pt'						)
											snake_case__									=     self.tokenizer(
											    text_target=self.tgt_text       ,	padding=_lowerCamelCase       ,	truncation=_lowerCamelCase       ,	max_length=10       ,	return_tensors='pt'						)
											snake_case__									=     targets['input_ids']
											snake_case__									=     shift_tokens_right(
											    _lowerCamelCase       ,	self.tokenizer.pad_token_id       ,	decoder_start_token_id=self.tokenizer.lang_code_to_id[self.tokenizer.tgt_lang]       ,	)

											self.assertEqual(batch.input_ids.shape[1]       ,	3						)
											self.assertEqual(batch.decoder_input_ids.shape[1]       ,	10						)
							@require_torch
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		Union[str, Any]:
											snake_case__									=     self.tokenizer._build_translation_inputs(
											    'A test'       ,	return_tensors='pt'       ,	src_lang='eng_Latn'       ,	tgt_lang='fra_Latn'						)

											self.assertEqual(
											    nested_simplify(_lowerCamelCase						)       ,	{
											        # A, test, EOS, en_XX
											        'input_ids': [[25_60_47, 70, 73_56, 2]],
											        'attention_mask': [[1, 1, 1, 1]],
											        # ar_AR
											        'forced_bos_token_id': 25_60_57,
											    }       ,	)


							@require_torch
							def lowerCAmelCase_ (     self:      Tuple						)		->		List[str]:
											snake_case__									=     True
											snake_case__									=     self.tokenizer(
											    'UN Chief says there is no military solution in Syria'       ,	src_lang='eng_Latn'       ,	tgt_lang='fra_Latn'						)
											self.assertEqual(
											    inputs.input_ids       ,	[1_62_97, 13_44_08, 2_56_53, 63_70, 2_48, 2_54, 10_39_29, 9_49_95, 1_08, 4_94_86, 2, 25_60_47]						)

											snake_case__									=     False
											snake_case__									=     self.tokenizer(
											    'UN Chief says there is no military solution in Syria'       ,	src_lang='eng_Latn'       ,	tgt_lang='fra_Latn'						)
											self.assertEqual(
											    inputs.input_ids       ,	[25_60_47, 1_62_97, 13_44_08, 2_56_53, 63_70, 2_48, 2_54, 10_39_29, 9_49_95, 1_08, 4_94_86, 2]						)












import itertools
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Union

import pandas as pd
import pyarrow as pa

import datasets
import datasets.config
from datasets.features.features import require_storage_cast
from datasets.table import table_cast
from datasets.utils.py_utils import Literal


__UpperCamelCase					:		Any	  =						datasets.utils.logging.get_logger(__name__)

__UpperCamelCase					:		Union[str, Any]	  =						["""names""", """prefix"""]
__UpperCamelCase					:		List[str]	  =						["""warn_bad_lines""", """error_bad_lines""", """mangle_dupe_cols"""]
__UpperCamelCase					:		Dict	  =						["""encoding_errors""", """on_bad_lines"""]
__UpperCamelCase					:		Any	  =						["""date_format"""]


@dataclass
class   __SCREAMING_SNAKE_CASE(	datasets.BuilderConfig	):
							_UpperCAmelCase     =       ","
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       "infer"
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       True
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       False
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       True
							_UpperCAmelCase     =       True
							_UpperCAmelCase     =       False
							_UpperCAmelCase     =       True
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       "."
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       '"'
							_UpperCAmelCase     =       0
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       True
							_UpperCAmelCase     =       True
							_UpperCAmelCase     =       0
							_UpperCAmelCase     =       True
							_UpperCAmelCase     =       False
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       1_0_0_0_0
							_UpperCAmelCase     =       None
							_UpperCAmelCase     =       "strict"
							_UpperCAmelCase     =       "error"
							_UpperCAmelCase     =       None
							def lowerCAmelCase_ (     self:      Tuple						)		->		int:
											if self.delimiter is not None:
															snake_case__									=     self.delimiter
											if self.column_names is not None:
															snake_case__									=     self.column_names


							@property
							def lowerCAmelCase_ (     self:      Optional[int]						)		->		List[str]:
											snake_case__									=     {
											    'sep': self.sep,
											    'header': self.header,
											    'names': self.names,
											    'index_col': self.index_col,
											    'usecols': self.usecols,
											    'prefix': self.prefix,
											    'mangle_dupe_cols': self.mangle_dupe_cols,
											    'engine': self.engine,
											    'converters': self.converters,
											    'true_values': self.true_values,
											    'false_values': self.false_values,
											    'skipinitialspace': self.skipinitialspace,
											    'skiprows': self.skiprows,
											    'nrows': self.nrows,
											    'na_values': self.na_values,
											    'keep_default_na': self.keep_default_na,
											    'na_filter': self.na_filter,
											    'verbose': self.verbose,
											    'skip_blank_lines': self.skip_blank_lines,
											    'thousands': self.thousands,
											    'decimal': self.decimal,
											    'lineterminator': self.lineterminator,
											    'quotechar': self.quotechar,
											    'quoting': self.quoting,
											    'escapechar': self.escapechar,
											    'comment': self.comment,
											    'encoding': self.encoding,
											    'dialect': self.dialect,
											    'error_bad_lines': self.error_bad_lines,
											    'warn_bad_lines': self.warn_bad_lines,
											    'skipfooter': self.skipfooter,
											    'doublequote': self.doublequote,
											    'memory_map': self.memory_map,
											    'float_precision': self.float_precision,
											    'chunksize': self.chunksize,
											    'encoding_errors': self.encoding_errors,
											    'on_bad_lines': self.on_bad_lines,
											    'date_format': self.date_format,
											}

											# some kwargs must not be passed if they don't have a default value
											# some others are deprecated and we can also not pass them if they are the default value
											for pd_read_csv_parameter in _PANDAS_READ_CSV_NO_DEFAULT_PARAMETERS + _PANDAS_READ_CSV_DEPRECATED_PARAMETERS:
															if pd_read_csv_kwargs[pd_read_csv_parameter] == getattr(CsvConfig()       ,	UpperCamelCase						):
																			del pd_read_csv_kwargs[pd_read_csv_parameter]

        # Remove 2.0 new arguments
											if not (datasets.config.PANDAS_VERSION.major >= 2):
															for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_2_0_0_PARAMETERS:
																			del pd_read_csv_kwargs[pd_read_csv_parameter]

        # Remove 1.3 new arguments
											if not (datasets.config.PANDAS_VERSION.major >= 1 and datasets.config.PANDAS_VERSION.minor >= 3):
															for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_1_3_0_PARAMETERS:
																			del pd_read_csv_kwargs[pd_read_csv_parameter]

											return pd_read_csv_kwargs


class   __SCREAMING_SNAKE_CASE(	datasets.ArrowBasedBuilder	):
							_UpperCAmelCase     =       CsvConfig
							def lowerCAmelCase_ (     self:      str						)		->		int:
											return datasets.DatasetInfo(features=self.config.features						)
							def lowerCAmelCase_ (     self:      Tuple       ,	UpperCamelCase:      Dict						)		->		int:
											if not self.config.data_files:
															raise ValueError(F'''At least one data file must be specified, but got data_files={self.config.data_files}'''						)
											snake_case__									=     dl_manager.download_and_extract(self.config.data_files						)
											if isinstance(UpperCamelCase       ,	(str, list, tuple)						):
															snake_case__									=     data_files
															if isinstance(UpperCamelCase       ,	UpperCamelCase						):
																			snake_case__									=     [files]
															snake_case__									=     [dl_manager.iter_files(UpperCamelCase						) for file in files]
															return [datasets.SplitGenerator(name=datasets.Split.TRAIN       ,	gen_kwargs={'files': files}						)]
											snake_case__									=     []
											for split_name, files in data_files.items():
															if isinstance(UpperCamelCase       ,	UpperCamelCase						):
																			snake_case__									=     [files]
															snake_case__									=     [dl_manager.iter_files(UpperCamelCase						) for file in files]
															splits.append(datasets.SplitGenerator(name=UpperCamelCase       ,	gen_kwargs={'files': files}						)						)
											return splits
							def lowerCAmelCase_ (     self:      int       ,	UpperCamelCase:      pa.Table						)		->		pa.Table:
											if self.config.features is not None:
															snake_case__									=     self.config.features.arrow_schema
															if all(not require_storage_cast(UpperCamelCase						) for feature in self.config.features.values()						):
																			# cheaper cast
																			snake_case__									=     pa.Table.from_arrays([pa_table[field.name] for field in schema]       ,	schema=UpperCamelCase						)
															else:
																			# more expensive cast; allows str <-> int/float or str to Audio for example
																			snake_case__									=     table_cast(UpperCamelCase       ,	UpperCamelCase						)
											return pa_table


							def lowerCAmelCase_ (     self:      str       ,	UpperCamelCase:      Tuple						)		->		Tuple:
											snake_case__									=     self.config.features.arrow_schema if self.config.features else None
											# dtype allows reading an int column as str
											snake_case__									=     (
											    {
											        name: dtype.to_pandas_dtype() if not require_storage_cast(UpperCamelCase						) else object
											        for name, dtype, feature in zip(schema.names       ,	schema.types       ,	self.config.features.values()						)
											    }
											    if schema is not None
											    else None
											)
											for file_idx, file in enumerate(itertools.chain.from_iterable(UpperCamelCase						)						):
															snake_case__									=     pd.read_csv(UpperCamelCase       ,	iterator=UpperCamelCase       ,	dtype=UpperCamelCase       ,	**self.config.pd_read_csv_kwargs						)
															try:
																			for batch_idx, df in enumerate(UpperCamelCase						):
																							snake_case__									=     pa.Table.from_pandas(UpperCamelCase						)
																							# Uncomment for debugging (will print the Arrow table size and elements)
																							# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
																							# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
																							yield (file_idx, batch_idx), self._cast_table(UpperCamelCase						)
															except ValueError as e:
																			logger.error(F'''Failed to read file \'{file}\' with error {type(UpperCamelCase						)}: {e}'''						)
																			raise




