

"""simple docstring"""





import csv
import os

import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.csv import CsvDatasetReader, CsvDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases



def 							_lowerCAmelCase   (    UpperCAmelCase  :				int   ,				UpperCAmelCase  :				int					):


					'''simple docstring'''






					assert isinstance(UpperCAmelCase   ,				UpperCAmelCase					)
					assert dataset.num_rows == 4
					assert dataset.num_columns == 3
					assert dataset.column_names == ["col_1", "col_2", "col_3"]
					for feature, expected_dtype in expected_features.items():
										assert dataset.features[feature].dtype == expected_dtype



@pytest.mark.parametrize('''keep_in_memory'''   ,				[False, True]					)
def 							_lowerCAmelCase   (    UpperCAmelCase  :				Union[str, Any]   ,				UpperCAmelCase  :				List[Any]   ,				UpperCAmelCase  :				Union[str, Any]					):


					'''simple docstring'''






					UpperCamelCase__		:     int								=tmp_path / '''cache'''
					UpperCamelCase__		:     Optional[int]								={'''col_1''': '''int64''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
					with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
										UpperCamelCase__		:     Dict								=CsvDatasetReader(UpperCAmelCase   ,				cache_dir=UpperCAmelCase   ,				keep_in_memory=UpperCAmelCase					).read()
					_check_csv_dataset(UpperCAmelCase   ,				UpperCAmelCase					)



@pytest.mark.parametrize(
    '''features'''   ,				[
        None,
        {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''},
        {'''col_1''': '''string''', '''col_2''': '''string''', '''col_3''': '''string'''},
        {'''col_1''': '''int32''', '''col_2''': '''int32''', '''col_3''': '''int32'''},
        {'''col_1''': '''float32''', '''col_2''': '''float32''', '''col_3''': '''float32'''},
    ]   ,				)
def 							_lowerCAmelCase   (    UpperCAmelCase  :				List[Any]   ,				UpperCAmelCase  :				Tuple   ,				UpperCAmelCase  :				List[str]					):


					'''simple docstring'''






					UpperCamelCase__		:     Optional[Any]								=tmp_path / '''cache'''
					# CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
					UpperCamelCase__		:     Union[str, Any]								={'''col_1''': '''int64''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
					UpperCamelCase__		:     Optional[Any]								=features.copy() if features else default_expected_features
					UpperCamelCase__		:     Union[str, Any]								=(
					    Features({feature: Value(UpperCAmelCase					) for feature, dtype in features.items()}					) if features is not None else None
					)
					UpperCamelCase__		:     Optional[int]								=CsvDatasetReader(UpperCAmelCase   ,				features=UpperCAmelCase   ,				cache_dir=UpperCAmelCase					).read()
					_check_csv_dataset(UpperCAmelCase   ,				UpperCAmelCase					)



@pytest.mark.parametrize('''split'''   ,				[None, NamedSplit('''train'''					), '''train''', '''test''']					)
def 							_lowerCAmelCase   (    UpperCAmelCase  :				List[Any]   ,				UpperCAmelCase  :				Optional[int]   ,				UpperCAmelCase  :				Any					):


					'''simple docstring'''






					UpperCamelCase__		:     int								=tmp_path / '''cache'''
					UpperCamelCase__		:     Dict								={'''col_1''': '''int64''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
					UpperCamelCase__		:     str								=CsvDatasetReader(UpperCAmelCase   ,				cache_dir=UpperCAmelCase   ,				split=UpperCAmelCase					).read()
					_check_csv_dataset(UpperCAmelCase   ,				UpperCAmelCase					)
					assert dataset.split == split if split else "train"



@pytest.mark.parametrize('''path_type'''   ,				[str, list]					)
def 							_lowerCAmelCase   (    UpperCAmelCase  :				Optional[Any]   ,				UpperCAmelCase  :				Any   ,				UpperCAmelCase  :				Optional[Any]					):


					'''simple docstring'''






					if issubclass(UpperCAmelCase   ,				UpperCAmelCase					):
										UpperCamelCase__		:     Union[str, Any]								=csv_path
					elif issubclass(UpperCAmelCase   ,				UpperCAmelCase					):
										UpperCamelCase__		:     Tuple								=[csv_path]
					UpperCamelCase__		:     Any								=tmp_path / '''cache'''
					UpperCamelCase__		:     Tuple								={'''col_1''': '''int64''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
					UpperCamelCase__		:     Union[str, Any]								=CsvDatasetReader(UpperCAmelCase   ,				cache_dir=UpperCAmelCase					).read()
					_check_csv_dataset(UpperCAmelCase   ,				UpperCAmelCase					)



def 							_lowerCAmelCase   (    UpperCAmelCase  :				List[Any]   ,				UpperCAmelCase  :				Optional[int]   ,				UpperCAmelCase  :				Any=("train",)					):


					'''simple docstring'''






					assert isinstance(UpperCAmelCase   ,				UpperCAmelCase					)
					for split in splits:
										UpperCamelCase__		:     Tuple								=dataset_dict[split]
										assert dataset.num_rows == 4
										assert dataset.num_columns == 3
										assert dataset.column_names == ["col_1", "col_2", "col_3"]
										for feature, expected_dtype in expected_features.items():
															assert dataset.features[feature].dtype == expected_dtype



@pytest.mark.parametrize('''keep_in_memory'''   ,				[False, True]					)
def 							_lowerCAmelCase   (    UpperCAmelCase  :				Optional[int]   ,				UpperCAmelCase  :				Optional[Any]   ,				UpperCAmelCase  :				int					):


					'''simple docstring'''






					UpperCamelCase__		:     Dict								=tmp_path / '''cache'''
					UpperCamelCase__		:     Dict								={'''col_1''': '''int64''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
					with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
										UpperCamelCase__		:     List[str]								=CsvDatasetReader({'''train''': csv_path}   ,				cache_dir=UpperCAmelCase   ,				keep_in_memory=UpperCAmelCase					).read()
					_check_csv_datasetdict(UpperCAmelCase   ,				UpperCAmelCase					)



@pytest.mark.parametrize(
    '''features'''   ,				[
        None,
        {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''},
        {'''col_1''': '''string''', '''col_2''': '''string''', '''col_3''': '''string'''},
        {'''col_1''': '''int32''', '''col_2''': '''int32''', '''col_3''': '''int32'''},
        {'''col_1''': '''float32''', '''col_2''': '''float32''', '''col_3''': '''float32'''},
    ]   ,				)
def 							_lowerCAmelCase   (    UpperCAmelCase  :				Optional[int]   ,				UpperCAmelCase  :				str   ,				UpperCAmelCase  :				Tuple					):


					'''simple docstring'''






					UpperCamelCase__		:     List[Any]								=tmp_path / '''cache'''
					# CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
					UpperCamelCase__		:     Optional[Any]								={'''col_1''': '''int64''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
					UpperCamelCase__		:     Union[str, Any]								=features.copy() if features else default_expected_features
					UpperCamelCase__		:     List[str]								=(
					    Features({feature: Value(UpperCAmelCase					) for feature, dtype in features.items()}					) if features is not None else None
					)
					UpperCamelCase__		:     List[str]								=CsvDatasetReader({'''train''': csv_path}   ,				features=UpperCAmelCase   ,				cache_dir=UpperCAmelCase					).read()
					_check_csv_datasetdict(UpperCAmelCase   ,				UpperCAmelCase					)



@pytest.mark.parametrize('''split'''   ,				[None, NamedSplit('''train'''					), '''train''', '''test''']					)
def 							_lowerCAmelCase   (    UpperCAmelCase  :				Any   ,				UpperCAmelCase  :				int   ,				UpperCAmelCase  :				Optional[int]					):


					'''simple docstring'''






					if split:
										UpperCamelCase__		:     Any								={split: csv_path}
					else:
										UpperCamelCase__		:     Optional[Any]								={'''train''': csv_path, '''test''': csv_path}
					UpperCamelCase__		:     Optional[Any]								=tmp_path / '''cache'''
					UpperCamelCase__		:     Dict								={'''col_1''': '''int64''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
					UpperCamelCase__		:     Optional[int]								=CsvDatasetReader(UpperCAmelCase   ,				cache_dir=UpperCAmelCase					).read()
					_check_csv_datasetdict(UpperCAmelCase   ,				UpperCAmelCase   ,				splits=list(path.keys()					)					)
					assert all(dataset[split].split == split for split in path.keys()					)



def 							_lowerCAmelCase   (    UpperCAmelCase  :				List[str]					):


					'''simple docstring'''






					with open(UpperCAmelCase   ,				encoding='''utf-8'''					) as csvfile:
										yield from csv.reader(UpperCAmelCase					)



def 							_lowerCAmelCase   (    UpperCAmelCase  :				str   ,				UpperCAmelCase  :				Optional[Any]					):


					'''simple docstring'''






					UpperCamelCase__		:     int								=tmp_path / '''cache'''
					UpperCamelCase__		:     Optional[int]								=os.path.join(UpperCAmelCase   ,				'''tmp.csv'''					)
					UpperCamelCase__		:     str								=CsvDatasetReader({'''train''': csv_path}   ,				cache_dir=UpperCAmelCase					).read()
					CsvDatasetWriter(dataset['''train''']   ,				UpperCAmelCase   ,				num_proc=1					).write()

					UpperCamelCase__		:     List[str]								=iter_csv_file(UpperCAmelCase					)
					UpperCamelCase__		:     List[Any]								=iter_csv_file(UpperCAmelCase					)

					for rowa, rowa in zip(UpperCAmelCase   ,				UpperCAmelCase					):
										assert rowa == rowa



def 							_lowerCAmelCase   (    UpperCAmelCase  :				str   ,				UpperCAmelCase  :				Optional[int]					):


					'''simple docstring'''






					UpperCamelCase__		:     str								=tmp_path / '''cache'''
					UpperCamelCase__		:     Any								=os.path.join(UpperCAmelCase   ,				'''tmp.csv'''					)
					UpperCamelCase__		:     Union[str, Any]								=CsvDatasetReader({'''train''': csv_path}   ,				cache_dir=UpperCAmelCase					).read()
					CsvDatasetWriter(dataset['''train''']   ,				UpperCAmelCase   ,				num_proc=2					).write()

					UpperCamelCase__		:     Dict								=iter_csv_file(UpperCAmelCase					)
					UpperCamelCase__		:     Tuple								=iter_csv_file(UpperCAmelCase					)

					for rowa, rowa in zip(UpperCAmelCase   ,				UpperCAmelCase					):
										assert rowa == rowa







def 							_lowerCAmelCase   (    UpperCAmelCase  :				Union[str, Any]   ,				UpperCAmelCase  :				List[Any]					):


					'''simple docstring'''






					UpperCamelCase__		:     Optional[int]								=tmp_path / '''cache'''
					UpperCamelCase__		:     Union[str, Any]								=os.path.join(UpperCAmelCase   ,				'''tmp.csv'''					)
					UpperCamelCase__		:     str								=CsvDatasetReader({'''train''': csv_path}   ,				cache_dir=UpperCAmelCase					).read()
					with pytest.raises(UpperCAmelCase					):
										CsvDatasetWriter(dataset['''train''']   ,				UpperCAmelCase   ,				num_proc=0					)





"""simple docstring"""





from __future__ import annotations



def 							_lowerCAmelCase   (    UpperCAmelCase  :				list[int]   ,				UpperCAmelCase  :				int					):


					'''simple docstring'''






					UpperCamelCase__		:     dict[int, int]								={}
					for index, val in enumerate(UpperCAmelCase					):
										UpperCamelCase__		:     List[Any]								=target - val
										if compl in chk_map:
															return [chk_map[compl], index]
										UpperCamelCase__		:     Any								=index
					return []


if __name__ == "__main__":
				import doctest

				doctest.testmod()
				print(F'''{two_sum([2, 7, 1_1, 1_5], 9) = }''')


