
'''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 						a   (				__magic_name__    ):




				def 	__snake_case							(							self	:				Any      ):
										snake_case       :     Optional[Any] =    pa.array(TypedSequence([1, 2, 3]      )      )
										self.assertEqual(arr.type,    pa.intaa()      )




				def 	__snake_case							(							self	:				Optional[Any]      ):
										with self.assertRaises(SCREAMING_SNAKE_CASE_      ):
																snake_case       :     Dict =    pa.array(TypedSequence([1, 2, 3]      ),    type=pa.intaa()      )




				def 	__snake_case							(							self	:				Union[str, Any]      ):
										with self.assertRaises(SCREAMING_SNAKE_CASE_      ):
																snake_case       :     Any =    pa.array(TypedSequence([1, 2, 3],    try_type=Value('''bool'''      ),    type=Value('''int64'''      )      )      )




				def 	__snake_case							(							self	:				Optional[int]      ):
										snake_case       :     str =    pa.array(TypedSequence([1, 2, 3],    type=Value('''int32'''      )      )      )
										self.assertEqual(arr.type,    pa.intaa()      )




				def 	__snake_case							(							self	:				str      ):
										with self.assertRaises((TypeError, pa.lib.ArrowInvalid)      ):
																snake_case       :     List[str] =    pa.array(TypedSequence(['''foo''', '''bar'''],    type=Value('''int64'''      )      )      )




				def 	__snake_case							(							self	:				int      ):
										snake_case       :     Tuple =    pa.array(TypedSequence([1, 2, 3],    try_type=Value('''int32'''      )      )      )
										self.assertEqual(arr.type,    pa.intaa()      )




				def 	__snake_case							(							self	:				List[Any]      ):
										snake_case       :     Union[str, Any] =    pa.array(TypedSequence(['''foo''', '''bar'''],    try_type=Value('''int64'''      )      )      )
										self.assertEqual(arr.type,    pa.string()      )




				def 	__snake_case							(							self	:				str      ):
										snake_case       :     Union[str, Any] =    pa.array(TypedSequence([[[1, 2, 3]]],    type=ArrayaD((1, 3),    '''int64'''      )      )      )
										self.assertEqual(arr.type,    ArrayaDExtensionType((1, 3),    '''int64'''      )      )




				def 	__snake_case							(							self	:				List[Any]      ):
										with self.assertRaises((TypeError, pa.lib.ArrowInvalid)      ):
																snake_case       :     Dict =    pa.array(TypedSequence(['''foo''', '''bar'''],    type=ArrayaD((1, 3),    '''int64'''      )      )      )




				def 	__snake_case							(							self	:				Tuple      ):
										snake_case       :     Union[str, Any] =    pa.array(TypedSequence([[[1, 2, 3]]],    try_type=ArrayaD((1, 3),    '''int64'''      )      )      )
										self.assertEqual(arr.type,    ArrayaDExtensionType((1, 3),    '''int64'''      )      )




				def 	__snake_case							(							self	:				Dict      ):
										snake_case       :     Tuple =    pa.array(TypedSequence(['''foo''', '''bar'''],    try_type=ArrayaD((1, 3),    '''int64'''      )      )      )
										self.assertEqual(arr.type,    pa.string()      )




				@require_pil
				def 	__snake_case							(							self	:				Union[str, Any]      ):
										import PIL.Image

										snake_case       :     str =    PIL.Image.fromarray(np.arange(10,    dtype=np.uinta      ).reshape(2,    5      )      )
										with patch(
										    '''datasets.arrow_writer.cast_to_python_objects''',    side_effect=SCREAMING_SNAKE_CASE_      ) as mock_cast_to_python_objects:
																snake_case       :     Union[str, Any] =    pa.array(TypedSequence([{'''path''': None, '''bytes''': B'''image_bytes'''}, pil_image],    type=Image()      )      )
																snake_case,					snake_case       :     int =    mock_cast_to_python_objects.call_args_list[-1]
																self.assertIn('''optimize_list_casting''',    SCREAMING_SNAKE_CASE_      )
																self.assertFalse(kwargs['''optimize_list_casting''']      )




def      A (       A_							:					str    ,							A_							:					int       ):
						snake_case       :     List[str] =    pa.BufferReader(A_       ) if isinstance(A_    ,							pa.Buffer       ) else pa.memory_map(A_       )
						snake_case       :     Optional[Any] =    pa.ipc.open_stream(A_       )
						snake_case       :     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, 10]       )
@pytest.mark.parametrize(
    '''fields'''    ,							[None, {'''col_1''': pa.string(), '''col_2''': pa.intaa()}, {'''col_1''': pa.string(), '''col_2''': pa.intaa()}]       )
def      A (       A_							:					Optional[int]    ,							A_							:					str       ):
						snake_case       :     List[str] =    pa.BufferOutputStream()
						snake_case       :     List[Any] =    pa.schema(A_       ) if fields else None
						with ArrowWriter(stream=A_    ,							schema=A_    ,							writer_batch_size=A_       ) as writer:
												writer.write({'''col_1''': '''foo''', '''col_2''': 1}       )
												writer.write({'''col_1''': '''bar''', '''col_2''': 2}       )
												snake_case,					snake_case       :     List[Any] =    writer.finalize()
						assert num_examples == 2
						assert num_bytes > 0
						if not fields:
												snake_case       :     int =    {'''col_1''': pa.string(), '''col_2''': pa.intaa()}
						assert writer._schema == pa.schema(A_    ,							metadata=writer._schema.metadata       )
						_check_output(output.getvalue()    ,							expected_num_chunks=num_examples if writer_batch_size == 1 else 1       )

def      A (       ):
						snake_case       :     int =    pa.BufferOutputStream()
						snake_case       :     Tuple =    Features({'''labels''': ClassLabel(names=['''neg''', '''pos''']       )}       )
						with ArrowWriter(stream=A_    ,							features=A_       ) as writer:
												writer.write({'''labels''': 0}       )
												writer.write({'''labels''': 1}       )
												snake_case,					snake_case       :     Optional[Any] =    writer.finalize()
						assert num_examples == 2
						assert num_bytes > 0
						assert writer._schema == features.arrow_schema
						assert writer._schema.metadata == features.arrow_schema.metadata
						snake_case       :     Optional[int] =    pa.BufferReader(output.getvalue()       )
						snake_case       :     Dict =    pa.ipc.open_stream(A_       )
						snake_case       :     pa.Table =    f.read_all()
						snake_case       :     Optional[Any] =    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(A_       )

@pytest.mark.parametrize('''writer_batch_size'''    ,							[None, 1, 10]       )
def      A (       A_							:					Optional[int]       ):
						snake_case       :     Any =    pa.BufferOutputStream()
						with ArrowWriter(
						    stream=A_    ,							writer_batch_size=A_    ,							hash_salt='''split_name'''    ,							check_duplicates=A_    ,							) as writer:
												with pytest.raises(A_       ):
																		writer.write({'''col_1''': '''foo''', '''col_2''': 1}    ,							key=[1, 2]       )
																		snake_case,					snake_case       :     Optional[int] =    writer.finalize()

@pytest.mark.parametrize('''writer_batch_size'''    ,							[None, 2, 10]       )
def      A (       A_							:					Union[str, Any]       ):
						snake_case       :     Dict =    pa.BufferOutputStream()
						with ArrowWriter(
						    stream=A_    ,							writer_batch_size=A_    ,							hash_salt='''split_name'''    ,							check_duplicates=A_    ,							) as writer:
												with pytest.raises(A_       ):
																		writer.write({'''col_1''': '''foo''', '''col_2''': 1}    ,							key=10       )
																		writer.write({'''col_1''': '''bar''', '''col_2''': 2}    ,							key=10       )
																		snake_case,					snake_case       :     Tuple =    writer.finalize()

@pytest.mark.parametrize('''writer_batch_size'''    ,							[None, 2, 10]       )
def      A (       A_							:					int       ):
						snake_case       :     Tuple =    pa.BufferOutputStream()
						with ArrowWriter(
						    stream=A_    ,							writer_batch_size=A_    ,							hash_salt='''split_name'''    ,							check_duplicates=A_    ,							) as writer:
												writer.write({'''col_1''': '''foo''', '''col_2''': 1}    ,							key=1       )
												writer.write({'''col_1''': '''bar''', '''col_2''': 2}    ,							key=2       )
												snake_case,					snake_case       :     Optional[int] =    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, 10]       )
@pytest.mark.parametrize(
    '''fields'''    ,							[None, {'''col_1''': pa.string(), '''col_2''': pa.intaa()}, {'''col_1''': pa.string(), '''col_2''': pa.intaa()}]       )
def      A (       A_							:					Tuple    ,							A_							:					Tuple       ):
						snake_case       :     Tuple =    pa.BufferOutputStream()
						snake_case       :     Union[str, Any] =    pa.schema(A_       ) if fields else None
						with ArrowWriter(stream=A_    ,							schema=A_    ,							writer_batch_size=A_       ) as writer:
												writer.write_batch({'''col_1''': ['''foo''', '''bar'''], '''col_2''': [1, 2]}       )
												writer.write_batch({'''col_1''': [], '''col_2''': []}       )
												snake_case,					snake_case       :     Union[str, Any] =    writer.finalize()
						assert num_examples == 2
						assert num_bytes > 0
						if not fields:
												snake_case       :     List[str] =    {'''col_1''': pa.string(), '''col_2''': pa.intaa()}
						assert writer._schema == pa.schema(A_    ,							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, 10]       )
@pytest.mark.parametrize(
    '''fields'''    ,							[None, {'''col_1''': pa.string(), '''col_2''': pa.intaa()}, {'''col_1''': pa.string(), '''col_2''': pa.intaa()}]       )
def      A (       A_							:					Tuple    ,							A_							:					int       ):
						snake_case       :     List[Any] =    pa.BufferOutputStream()
						snake_case       :     Any =    pa.schema(A_       ) if fields else None
						with ArrowWriter(stream=A_    ,							schema=A_    ,							writer_batch_size=A_       ) as writer:
												writer.write_table(pa.Table.from_pydict({'''col_1''': ['''foo''', '''bar'''], '''col_2''': [1, 2]}       )       )
												snake_case,					snake_case       :     Optional[int] =    writer.finalize()
						assert num_examples == 2
						assert num_bytes > 0
						if not fields:
												snake_case       :     Union[str, Any] =    {'''col_1''': pa.string(), '''col_2''': pa.intaa()}
						assert writer._schema == pa.schema(A_    ,							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, 10]       )
@pytest.mark.parametrize(
    '''fields'''    ,							[None, {'''col_1''': pa.string(), '''col_2''': pa.intaa()}, {'''col_1''': pa.string(), '''col_2''': pa.intaa()}]       )
def      A (       A_							:					List[str]    ,							A_							:					Tuple       ):
						snake_case       :     List[Any] =    pa.BufferOutputStream()
						snake_case       :     Optional[int] =    pa.schema(A_       ) if fields else None
						with ArrowWriter(stream=A_    ,							schema=A_    ,							writer_batch_size=A_       ) 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]}       )       )
												snake_case,					snake_case       :     str =    writer.finalize()
						assert num_examples == 2
						assert num_bytes > 0
						if not fields:
												snake_case       :     Optional[Any] =    {'''col_1''': pa.string(), '''col_2''': pa.intaa()}
						assert writer._schema == pa.schema(A_    ,							metadata=writer._schema.metadata       )
						_check_output(output.getvalue()    ,							expected_num_chunks=num_examples if writer_batch_size == 1 else 1       )

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

def      A (       A_							:					Optional[Any]       ):
						if pa.types.is_list(A_       ):
												return get_base_dtype(arr_type.value_type       )
						else:
												return arr_type

def      A (       A_							:					Union[str, Any]    ,							A_							:					Union[str, Any]       ):
						if isinstance(lst[0]    ,							A_       ):
												change_first_primitive_element_in_list(lst[0]    ,							A_       )
						else:
												snake_case       :     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      A (       A_							:					int    ,							A_							:					Any    ,							A_							:					List[Any]       ):
						snake_case       :     Union[str, Any] =    pa.array(TypedSequence(A_    ,							optimized_int_type=A_       )       )
						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      A (       A_							:					str    ,							A_							:					Optional[Any]    ,							A_							:					str       ):
						# in range
						snake_case       :     Union[str, Any] =    pa.array(OptimizedTypedSequence(A_    ,							col=A_       )       )
						assert get_base_dtype(arr.type       ) == expected_dtype

						# not in range
						if col != "other":
												# avoids errors due to in-place modifications
												snake_case       :     List[Any] =    copy.deepcopy(A_       )
												snake_case       :     Tuple =    np.iinfo(expected_dtype.to_pandas_dtype()       ).max + 1
												change_first_primitive_element_in_list(A_    ,							A_       )
												snake_case       :     str =    pa.array(OptimizedTypedSequence(A_    ,							col=A_       )       )
												assert get_base_dtype(arr.type       ) == pa.intaa()

@pytest.mark.parametrize('''raise_exception'''    ,							[False, True]       )
def      A (       A_							:					List[Any]    ,							A_							:					Optional[int]       ):
						snake_case       :     str =    str(tmp_path / '''dataset-train.arrow'''       )
						try:
												with ArrowWriter(path=A_       ) as writer:
																		if raise_exception:
																								raise pa.lib.ArrowInvalid()
																		else:
																								writer.stream.close()
						except pa.lib.ArrowInvalid:
												pass
						finally:
												assert writer.stream.closed

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

def      A (       ):
						snake_case       :     Union[str, Any] =    pa.BufferOutputStream()
						with ParquetWriter(stream=A_       ) as writer:
												writer.write({'''col_1''': '''foo''', '''col_2''': 1}       )
												writer.write({'''col_1''': '''bar''', '''col_2''': 2}       )
												snake_case,					snake_case       :     Union[str, Any] =    writer.finalize()
						assert num_examples == 2
						assert num_bytes > 0
						snake_case       :     Union[str, Any] =    pa.BufferReader(output.getvalue()       )
						snake_case       :     pa.Table =    pq.read_table(A_       )
						assert pa_table.to_pydict() == {"col_1": ["foo", "bar"], "col_2": [1, 2]}

@require_pil
@pytest.mark.parametrize('''embed_local_files'''    ,							[False, True]       )
def      A (       A_							:					Optional[int]    ,							A_							:					Optional[Any]       ):
						import PIL.Image

						snake_case       :     List[str] =    str(tmp_path / '''test_image_rgb.jpg'''       )
						PIL.Image.fromarray(np.zeros((5, 5)    ,							dtype=np.uinta       )       ).save(A_    ,							format='''png'''       )
						snake_case       :     Dict =    pa.BufferOutputStream()
						with ParquetWriter(
						    stream=A_    ,							features=Features({'''image''': Image()}       )    ,							embed_local_files=A_       ) as writer:
												writer.write({'''image''': image_path}       )
												writer.finalize()
						snake_case       :     str =    pa.BufferReader(output.getvalue()       )
						snake_case       :     pa.Table =    pq.read_table(A_       )
						snake_case       :     Union[str, Any] =    pa_table.to_pydict()
						if embed_local_files:
												assert isinstance(out['''image'''][0]['''path''']    ,							A_       )
												with open(A_    ,							'''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      A (       ):
						snake_case       :     str =    pa.schema([pa.field('''col_1'''    ,							pa.string()    ,							nullable=A_       )]       )
						snake_case       :     Union[str, Any] =    pa.BufferOutputStream()
						with ArrowWriter(stream=A_       ) as writer:
												writer._build_writer(inferred_schema=A_       )
												assert writer._schema == pa.schema([pa.field('''col_1'''    ,							pa.string()       )]       )



'''simple docstring'''





import contextlib
import csv
import json
import os
import sqlitea
import tarfile
import textwrap
import zipfile

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

import datasets
import datasets.config

@pytest.fixture(scope='''session'''       )
def      A (       ):
						snake_case       :     Dict =    10
						snake_case       :     List[Any] =    datasets.Features(
						    {
						        '''tokens''': datasets.Sequence(datasets.Value('''string'''       )       ),
						        '''labels''': datasets.Sequence(datasets.ClassLabel(names=['''negative''', '''positive''']       )       ),
						        '''answers''': datasets.Sequence(
						            {
						                '''text''': datasets.Value('''string'''       ),
						                '''answer_start''': datasets.Value('''int32'''       ),
						            }       ),
						        '''id''': datasets.Value('''int64'''       ),
						    }       )
						snake_case       :     Dict =    datasets.Dataset.from_dict(
						    {
						        '''tokens''': [['''foo'''] * 5] * n,
						        '''labels''': [[1] * 5] * n,
						        '''answers''': [{'''answer_start''': [97], '''text''': ['''1976''']}] * 10,
						        '''id''': list(range(A_       )       ),
						    }    ,							features=A_    ,							)
						return dataset

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[Any]    ,							A_							:					Optional[Any]       ):
						snake_case       :     Any =    str(tmp_path_factory.mktemp('''data'''       ) / '''file.arrow'''       )
						dataset.map(cache_file_name=A_       )
						return filename


# FILE_CONTENT + files


UpperCAmelCase    					=   "\\n    Text data.\n    Second line of data."

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[str]       ):
						snake_case       :     Any =    tmp_path_factory.mktemp('''data'''       ) / '''file.txt'''
						snake_case       :     Union[str, Any] =    FILE_CONTENT
						with open(A_    ,							'''w'''       ) as f:
												f.write(A_       )
						return filename

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[Any]       ):
						import bza

						snake_case       :     Tuple =    tmp_path_factory.mktemp('''data'''       ) / '''file.txt.bz2'''
						snake_case       :     Union[str, Any] =    bytes(A_    ,							'''utf-8'''       )
						with bza.open(A_    ,							'''wb'''       ) as f:
												f.write(A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[Any]       ):
						import gzip

						snake_case       :     Any =    str(tmp_path_factory.mktemp('''data'''       ) / '''file.txt.gz'''       )
						snake_case       :     Any =    bytes(A_    ,							'''utf-8'''       )
						with gzip.open(A_    ,							'''wb'''       ) as f:
												f.write(A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[int]       ):
						if datasets.config.LZ4_AVAILABLE:
												import lza.frame

												snake_case       :     Union[str, Any] =    tmp_path_factory.mktemp('''data'''       ) / '''file.txt.lz4'''
												snake_case       :     Tuple =    bytes(A_    ,							'''utf-8'''       )
												with lza.frame.open(A_    ,							'''wb'''       ) as f:
																		f.write(A_       )
												return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Union[str, Any]    ,							A_							:					str       ):
						if datasets.config.PY7ZR_AVAILABLE:
												import pyazr

												snake_case       :     Optional[Any] =    tmp_path_factory.mktemp('''data'''       ) / '''file.txt.7z'''
												with pyazr.SevenZipFile(A_    ,							'''w'''       ) as archive:
																		archive.write(A_    ,							arcname=os.path.basename(A_       )       )
												return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[str]    ,							A_							:					Optional[int]       ):
						import tarfile

						snake_case       :     Union[str, Any] =    tmp_path_factory.mktemp('''data'''       ) / '''file.txt.tar'''
						with tarfile.TarFile(A_    ,							'''w'''       ) as f:
												f.add(A_    ,							arcname=os.path.basename(A_       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Any       ):
						import lzma

						snake_case       :     Any =    tmp_path_factory.mktemp('''data'''       ) / '''file.txt.xz'''
						snake_case       :     Union[str, Any] =    bytes(A_    ,							'''utf-8'''       )
						with lzma.open(A_    ,							'''wb'''       ) as f:
												f.write(A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[int]    ,							A_							:					Union[str, Any]       ):
						import zipfile

						snake_case       :     List[str] =    tmp_path_factory.mktemp('''data'''       ) / '''file.txt.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.basename(A_       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[str]       ):
						if datasets.config.ZSTANDARD_AVAILABLE:
												import zstandard as zstd

												snake_case       :     Tuple =    tmp_path_factory.mktemp('''data'''       ) / '''file.txt.zst'''
												snake_case       :     List[str] =    bytes(A_    ,							'''utf-8'''       )
												with zstd.open(A_    ,							'''wb'''       ) as f:
																		f.write(A_       )
												return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					str       ):
						snake_case       :     Optional[int] =    tmp_path_factory.mktemp('''data'''       ) / '''file.xml'''
						snake_case       :     Any =    textwrap.dedent(
						    '''\
    <?xml version="1.0" encoding="UTF-8" ?>
    <tmx version="1.4">
      <header segtype="sentence" srclang="ca" />
      <body>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 1</seg></tuv>
          <tuv xml:lang="en"><seg>Content 1</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 2</seg></tuv>
          <tuv xml:lang="en"><seg>Content 2</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 3</seg></tuv>
          <tuv xml:lang="en"><seg>Content 3</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 4</seg></tuv>
          <tuv xml:lang="en"><seg>Content 4</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 5</seg></tuv>
          <tuv xml:lang="en"><seg>Content 5</seg></tuv>
        </tu>
      </body>
    </tmx>'''       )
						with open(A_    ,							'''w'''       ) as f:
												f.write(A_       )
						return filename


UpperCAmelCase    					=   [
    {"col_1": "0", "col_2": 0, "col_3": 0.0},
    {"col_1": "1", "col_2": 1, "col_3": 1.0},
    {"col_1": "2", "col_2": 2, "col_3": 2.0},
    {"col_1": "3", "col_2": 3, "col_3": 3.0},
]
UpperCAmelCase    					=   [
    {"col_1": "4", "col_2": 4, "col_3": 4.0},
    {"col_1": "5", "col_2": 5, "col_3": 5.0},
]
UpperCAmelCase    					=   {
    "col_1": ["0", "1", "2", "3"],
    "col_2": [0, 1, 2, 3],
    "col_3": [0.0, 1.0, 2.0, 3.0],
}

UpperCAmelCase    					=   [
    {"col_3": 0.0, "col_1": "0", "col_2": 0},
    {"col_3": 1.0, "col_1": "1", "col_2": 1},
]

UpperCAmelCase    					=   [
    {"col_1": "s0", "col_2": 0, "col_3": 0.0},
    {"col_1": "s1", "col_2": 1, "col_3": 1.0},
    {"col_1": "s2", "col_2": 2, "col_3": 2.0},
    {"col_1": "s3", "col_2": 3, "col_3": 3.0},
]

@pytest.fixture(scope='''session'''       )
def      A (       ):
						return DATA_DICT_OF_LISTS

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					str       ):
						snake_case       :     str =    datasets.Dataset.from_dict(A_       )
						snake_case       :     List[Any] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset.arrow'''       )
						dataset.map(cache_file_name=A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					str       ):
						snake_case       :     Optional[int] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset.sqlite'''       )
						with contextlib.closing(sqlitea.connect(A_       )       ) as con:
												snake_case       :     Optional[Any] =    con.cursor()
												cur.execute('''CREATE TABLE dataset(col_1 text, col_2 int, col_3 real)'''       )
												for item in DATA:
																		cur.execute('''INSERT INTO dataset(col_1, col_2, col_3) VALUES (?, ?, ?)'''    ,							tuple(item.values()       )       )
												con.commit()
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[str]       ):
						snake_case       :     Any =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset.csv'''       )
						with open(A_    ,							'''w'''    ,							newline=''''''       ) as f:
												snake_case       :     Optional[int] =    csv.DictWriter(A_    ,							fieldnames=['''col_1''', '''col_2''', '''col_3''']       )
												writer.writeheader()
												for item in DATA:
																		writer.writerow(A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[int]       ):
						snake_case       :     Optional[int] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset2.csv'''       )
						with open(A_    ,							'''w'''    ,							newline=''''''       ) as f:
												snake_case       :     int =    csv.DictWriter(A_    ,							fieldnames=['''col_1''', '''col_2''', '''col_3''']       )
												writer.writeheader()
												for item in DATA:
																		writer.writerow(A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[Any]    ,							A_							:					Optional[int]       ):
						import bza

						snake_case       :     Optional[int] =    tmp_path_factory.mktemp('''data'''       ) / '''dataset.csv.bz2'''
						with open(A_    ,							'''rb'''       ) as f:
												snake_case       :     Any =    f.read()
						# data = bytes(FILE_CONTENT, "utf-8")
						with bza.open(A_    ,							'''wb'''       ) as f:
												f.write(A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					str    ,							A_							:					int    ,							A_							:					List[Any]       ):
						snake_case       :     Optional[Any] =    tmp_path_factory.mktemp('''data'''       ) / '''dataset.csv.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.basename(A_       )       )
												f.write(A_    ,							arcname=os.path.basename(A_       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Dict    ,							A_							:					Optional[Any]    ,							A_							:					Dict       ):
						snake_case       :     str =    tmp_path_factory.mktemp('''data'''       ) / '''dataset.csv.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.basename(csv_path.replace('''.csv'''    ,							'''.CSV'''       )       )       )
												f.write(A_    ,							arcname=os.path.basename(csva_path.replace('''.csv'''    ,							'''.CSV'''       )       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Dict    ,							A_							:					Dict    ,							A_							:					Optional[int]       ):
						snake_case       :     Dict =    tmp_path_factory.mktemp('''data'''       ) / '''dataset_with_dir.csv.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.join('''main_dir'''    ,							os.path.basename(A_       )       )       )
												f.write(A_    ,							arcname=os.path.join('''main_dir'''    ,							os.path.basename(A_       )       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Dict       ):
						snake_case       :     List[str] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset.parquet'''       )
						snake_case       :     Tuple =    pa.schema(
						    {
						        '''col_1''': pa.string(),
						        '''col_2''': pa.intaa(),
						        '''col_3''': pa.floataa(),
						    }       )
						with open(A_    ,							'''wb'''       ) as f:
												snake_case       :     Dict =    pq.ParquetWriter(A_    ,							schema=A_       )
												snake_case       :     str =    pa.Table.from_pydict({k: [DATA[i][k] for i in range(len(A_       )       )] for k in DATA[0]}    ,							schema=A_       )
												writer.write_table(A_       )
												writer.close()
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[str]       ):
						snake_case       :     Any =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset.json'''       )
						snake_case       :     Optional[int] =    {'''data''': DATA}
						with open(A_    ,							'''w'''       ) as f:
												json.dump(A_    ,							A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					str       ):
						snake_case       :     List[str] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset.json'''       )
						snake_case       :     Any =    {'''data''': DATA_DICT_OF_LISTS}
						with open(A_    ,							'''w'''       ) as f:
												json.dump(A_    ,							A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[Any]       ):
						snake_case       :     Optional[Any] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset.jsonl'''       )
						with open(A_    ,							'''w'''       ) as f:
												for item in DATA:
																		f.write(json.dumps(A_       ) + '''\n'''       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[Any]       ):
						snake_case       :     Optional[int] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset2.jsonl'''       )
						with open(A_    ,							'''w'''       ) as f:
												for item in DATA:
																		f.write(json.dumps(A_       ) + '''\n'''       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[Any]       ):
						snake_case       :     Dict =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset_312.jsonl'''       )
						with open(A_    ,							'''w'''       ) as f:
												for item in DATA_312:
																		f.write(json.dumps(A_       ) + '''\n'''       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					int       ):
						snake_case       :     Dict =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset-str.jsonl'''       )
						with open(A_    ,							'''w'''       ) as f:
												for item in DATA_STR:
																		f.write(json.dumps(A_       ) + '''\n'''       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[int]    ,							A_							:					Optional[int]       ):
						import gzip

						snake_case       :     Dict =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset.txt.gz'''       )
						with open(A_    ,							'''rb'''       ) as orig_file:
												with gzip.open(A_    ,							'''wb'''       ) as zipped_file:
																		zipped_file.writelines(A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[int]    ,							A_							:					Any       ):
						import gzip

						snake_case       :     List[Any] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset.jsonl.gz'''       )
						with open(A_    ,							'''rb'''       ) as orig_file:
												with gzip.open(A_    ,							'''wb'''       ) as zipped_file:
																		zipped_file.writelines(A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					str    ,							A_							:					List[str]    ,							A_							:					Optional[int]       ):
						snake_case       :     int =    tmp_path_factory.mktemp('''data'''       ) / '''dataset.jsonl.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.basename(A_       )       )
												f.write(A_    ,							arcname=os.path.basename(A_       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[str]    ,							A_							:					Any    ,							A_							:					Union[str, Any]    ,							A_							:					int       ):
						snake_case       :     List[str] =    tmp_path_factory.mktemp('''data'''       ) / '''dataset_nested.jsonl.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.join('''nested'''    ,							os.path.basename(A_       )       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[str]    ,							A_							:					Dict    ,							A_							:					Any       ):
						snake_case       :     Optional[Any] =    tmp_path_factory.mktemp('''data'''       ) / '''dataset_with_dir.jsonl.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.join('''main_dir'''    ,							os.path.basename(A_       )       )       )
												f.write(A_    ,							arcname=os.path.join('''main_dir'''    ,							os.path.basename(A_       )       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[Any]    ,							A_							:					Tuple    ,							A_							:					List[str]       ):
						snake_case       :     int =    tmp_path_factory.mktemp('''data'''       ) / '''dataset.jsonl.tar'''
						with tarfile.TarFile(A_    ,							'''w'''       ) as f:
												f.add(A_    ,							arcname=os.path.basename(A_       )       )
												f.add(A_    ,							arcname=os.path.basename(A_       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Tuple    ,							A_							:					Any    ,							A_							:					Tuple    ,							A_							:					Optional[Any]       ):
						snake_case       :     List[Any] =    tmp_path_factory.mktemp('''data'''       ) / '''dataset_nested.jsonl.tar'''
						with tarfile.TarFile(A_    ,							'''w'''       ) as f:
												f.add(A_    ,							arcname=os.path.join('''nested'''    ,							os.path.basename(A_       )       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					int       ):
						snake_case       :     int =    ['''0''', '''1''', '''2''', '''3''']
						snake_case       :     Optional[int] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset.txt'''       )
						with open(A_    ,							'''w'''       ) as f:
												for item in data:
																		f.write(item + '''\n'''       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[str]       ):
						snake_case       :     Union[str, Any] =    ['''0''', '''1''', '''2''', '''3''']
						snake_case       :     Optional[int] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset2.txt'''       )
						with open(A_    ,							'''w'''       ) as f:
												for item in data:
																		f.write(item + '''\n'''       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[int]       ):
						snake_case       :     Optional[int] =    ['''0''', '''1''', '''2''', '''3''']
						snake_case       :     str =    tmp_path_factory.mktemp('''data'''       ) / '''dataset.abc'''
						with open(A_    ,							'''w'''       ) as f:
												for item in data:
																		f.write(item + '''\n'''       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[Any]    ,							A_							:					Any    ,							A_							:					Union[str, Any]       ):
						snake_case       :     Dict =    tmp_path_factory.mktemp('''data'''       ) / '''dataset.text.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.basename(A_       )       )
												f.write(A_    ,							arcname=os.path.basename(A_       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					List[str]    ,							A_							:					Union[str, Any]    ,							A_							:					Optional[Any]       ):
						snake_case       :     List[Any] =    tmp_path_factory.mktemp('''data'''       ) / '''dataset_with_dir.text.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.join('''main_dir'''    ,							os.path.basename(A_       )       )       )
												f.write(A_    ,							arcname=os.path.join('''main_dir'''    ,							os.path.basename(A_       )       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Any    ,							A_							:					Union[str, Any]    ,							A_							:					str       ):
						snake_case       :     List[Any] =    tmp_path_factory.mktemp('''data'''       ) / '''dataset.ext.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.basename('''unsupported.ext'''       )       )
												f.write(A_    ,							arcname=os.path.basename('''unsupported_2.ext'''       )       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Union[str, Any]       ):
						snake_case       :     Any =    '''\n'''.join(['''First''', '''Second\u2029with Unicode new line''', '''Third''']       )
						snake_case       :     Optional[int] =    str(tmp_path_factory.mktemp('''data'''       ) / '''dataset_with_unicode_new_lines.txt'''       )
						with open(A_    ,							'''w'''    ,							encoding='''utf-8'''       ) as f:
												f.write(A_       )
						return path

@pytest.fixture(scope='''session'''       )
def      A (       ):
						return os.path.join('''tests'''    ,							'''features'''    ,							'''data'''    ,							'''test_image_rgb.jpg'''       )

@pytest.fixture(scope='''session'''       )
def      A (       ):
						return os.path.join('''tests'''    ,							'''features'''    ,							'''data'''    ,							'''test_audio_44100.wav'''       )

@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[Any]    ,							A_							:					Optional[Any]       ):
						snake_case       :     Union[str, Any] =    tmp_path_factory.mktemp('''data'''       ) / '''dataset.img.zip'''
						with zipfile.ZipFile(A_    ,							'''w'''       ) as f:
												f.write(A_    ,							arcname=os.path.basename(A_       )       )
												f.write(A_    ,							arcname=os.path.basename(A_       ).replace('''.jpg'''    ,							'''2.jpg'''       )       )
						return path





@pytest.fixture(scope='''session'''       )
def      A (       A_							:					Optional[Any]       ):
						snake_case       :     Dict =    tmp_path_factory.mktemp('''data_dir'''       )

						(data_dir / "subdir").mkdir()
						with open(data_dir / '''subdir''' / '''train.txt'''    ,							'''w'''       ) as f:
												f.write('''foo\n''' * 10       )
						with open(data_dir / '''subdir''' / '''test.txt'''    ,							'''w'''       ) as f:
												f.write('''bar\n''' * 10       )
						# hidden file
						with open(data_dir / '''subdir''' / '''.test.txt'''    ,							'''w'''       ) as f:
												f.write('''bar\n''' * 10       )

						# hidden directory
						(data_dir / ".subdir").mkdir()
						with open(data_dir / '''.subdir''' / '''train.txt'''    ,							'''w'''       ) as f:
												f.write('''foo\n''' * 10       )
						with open(data_dir / '''.subdir''' / '''test.txt'''    ,							'''w'''       ) as f:
												f.write('''bar\n''' * 10       )

						return data_dir

