





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_       ,		UpperCamelCase_	)  ->		Tuple:
       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_       ,		UpperCamelCase_       ,		UpperCamelCase_	)  ->		int:
       UpperCamelCase_ 							=	tmp_path / "cache"
       UpperCamelCase_ 							=	{"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_ 							=	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_       ,		UpperCamelCase_       ,		UpperCamelCase_	)  ->		str:
       UpperCamelCase_ 							=	tmp_path / "cache"
       # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
       UpperCamelCase_ 							=	{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
       UpperCamelCase_ 							=	features.copy() if features else default_expected_features
       UpperCamelCase_ 							=	(
           Features({feature: Value(UpperCamelCase_	) for feature, dtype in features.items()}	) if features is not None else None
       )
       UpperCamelCase_ 							=	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_       ,		UpperCamelCase_       ,		UpperCamelCase_	)  ->		Union[str, Any]:
       UpperCamelCase_ 							=	tmp_path / "cache"
       UpperCamelCase_ 							=	{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
       UpperCamelCase_ 							=	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_       ,		UpperCamelCase_       ,		UpperCamelCase_	)  ->		List[str]:
       if issubclass(UpperCamelCase_       ,		UpperCamelCase_	):
              UpperCamelCase_ 							=	csv_path
       elif issubclass(UpperCamelCase_       ,		UpperCamelCase_	):
              UpperCamelCase_ 							=	[csv_path]
       UpperCamelCase_ 							=	tmp_path / "cache"
       UpperCamelCase_ 							=	{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
       UpperCamelCase_ 							=	CsvDatasetReader(UpperCamelCase_       ,		cache_dir=UpperCamelCase_	).read()
       _check_csv_dataset(UpperCamelCase_       ,		UpperCamelCase_	)




def 			lowerCAmelCase_			(				UpperCamelCase_       ,		UpperCamelCase_       ,		UpperCamelCase_=("train",)	)  ->		int:
       assert isinstance(UpperCamelCase_       ,		UpperCamelCase_	)
       for split in splits:
              UpperCamelCase_ 							=	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_       ,		UpperCamelCase_       ,		UpperCamelCase_	)  ->		int:
       UpperCamelCase_ 							=	tmp_path / "cache"
       UpperCamelCase_ 							=	{"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_ 							=	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_       ,		UpperCamelCase_       ,		UpperCamelCase_	)  ->		List[str]:
       UpperCamelCase_ 							=	tmp_path / "cache"
       # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
       UpperCamelCase_ 							=	{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
       UpperCamelCase_ 							=	features.copy() if features else default_expected_features
       UpperCamelCase_ 							=	(
           Features({feature: Value(UpperCamelCase_	) for feature, dtype in features.items()}	) if features is not None else None
       )
       UpperCamelCase_ 							=	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_       ,		UpperCamelCase_       ,		UpperCamelCase_	)  ->		Optional[int]:
       if split:
              UpperCamelCase_ 							=	{split: csv_path}
       else:
              UpperCamelCase_ 							=	{"train": csv_path, "test": csv_path}
       UpperCamelCase_ 							=	tmp_path / "cache"
       UpperCamelCase_ 							=	{"col_1": "int64", "col_2": "int64", "col_3": "float64"}
       UpperCamelCase_ 							=	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_	)  ->		Any:
       with open(UpperCamelCase_       ,		encoding="utf-8"	) as csvfile:
              yield from csv.reader(UpperCamelCase_	)




def 			lowerCAmelCase_			(				UpperCamelCase_       ,		UpperCamelCase_	)  ->		Union[str, Any]:
       UpperCamelCase_ 							=	tmp_path / "cache"
       UpperCamelCase_ 							=	os.path.join(UpperCamelCase_       ,		"tmp.csv"	)
       UpperCamelCase_ 							=	CsvDatasetReader({"train": csv_path}       ,		cache_dir=UpperCamelCase_	).read()
       CsvDatasetWriter(dataset["train"]       ,		UpperCamelCase_       ,		num_proc=1	).write()

       UpperCamelCase_ 							=	iter_csv_file(UpperCamelCase_	)
       UpperCamelCase_ 							=	iter_csv_file(UpperCamelCase_	)

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




def 			lowerCAmelCase_			(				UpperCamelCase_       ,		UpperCamelCase_	)  ->		Optional[Any]:
       UpperCamelCase_ 							=	tmp_path / "cache"
       UpperCamelCase_ 							=	os.path.join(UpperCamelCase_       ,		"tmp.csv"	)
       UpperCamelCase_ 							=	CsvDatasetReader({"train": csv_path}       ,		cache_dir=UpperCamelCase_	).read()
       CsvDatasetWriter(dataset["train"]       ,		UpperCamelCase_       ,		num_proc=2	).write()

       UpperCamelCase_ 							=	iter_csv_file(UpperCamelCase_	)
       UpperCamelCase_ 							=	iter_csv_file(UpperCamelCase_	)

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







def 			lowerCAmelCase_			(				UpperCamelCase_       ,		UpperCamelCase_	)  ->		Any:
       UpperCamelCase_ 							=	tmp_path / "cache"
       UpperCamelCase_ 							=	os.path.join(UpperCamelCase_       ,		"tmp.csv"	)
       UpperCamelCase_ 							=	CsvDatasetReader({"train": csv_path}       ,		cache_dir=UpperCamelCase_	).read()
       with pytest.raises(UpperCamelCase_	):
              CsvDatasetWriter(dataset["train"]       ,		UpperCamelCase_       ,		num_proc=0	)



from __future__ import annotations


def  A			(   lowercase       ,			lowercase					)  ->    int:
		'''simple docstring'''

		UpperCamelCase      ,    UpperCamelCase            =	0, len(lowercase					) - 1
		while start_ind <= end_ind:
				if array[start_ind] == search_item:
						return start_ind
				elif array[end_ind] == search_item:
						return end_ind
				else:
						start_ind += 1
						end_ind -= 1
    # returns -1 if search_item is not found in array
		return -1


if __name__ == "__main__":
					print(double_linear_search(list(range(100)), 40))
