


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 						_A						(						_lowercase			,       _lowercase				)			->				Optional[Any]:


     """simple docstring"""


     assert isinstance(_lowercase			,       _lowercase				)
     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 						_A						(						_lowercase			,       _lowercase			,       _lowercase				)			->				List[str]:


     """simple docstring"""


     __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(_lowercase			,       cache_dir=_lowercase			,       keep_in_memory=_lowercase				).read()
     _check_csv_dataset(_lowercase			,       _lowercase				)






@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 						_A						(						_lowercase			,       _lowercase			,       _lowercase				)			->				int:


     """simple docstring"""


     __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(_lowercase				) for feature, dtype in features.items()}				) if features is not None else None
     )
     __UpperCamelCase				=	CsvDatasetReader(_lowercase			,       features=_lowercase			,       cache_dir=_lowercase				).read()
     _check_csv_dataset(_lowercase			,       _lowercase				)






@pytest.mark.parametrize('split'			,       [None, NamedSplit('train'				), 'train', 'test']				)
def 						_A						(						_lowercase			,       _lowercase			,       _lowercase				)			->				Optional[Any]:


     """simple docstring"""


     __UpperCamelCase				=	tmp_path / """cache"""
     __UpperCamelCase				=	{"""col_1""": """int64""", """col_2""": """int64""", """col_3""": """float64"""}
     __UpperCamelCase				=	CsvDatasetReader(_lowercase			,       cache_dir=_lowercase			,       split=_lowercase				).read()
     _check_csv_dataset(_lowercase			,       _lowercase				)
     assert dataset.split == split if split else "train"






@pytest.mark.parametrize('path_type'			,       [str, list]				)
def 						_A						(						_lowercase			,       _lowercase			,       _lowercase				)			->				Optional[Any]:


     """simple docstring"""


     if issubclass(_lowercase			,       _lowercase				):
          __UpperCamelCase				=	csv_path
     elif issubclass(_lowercase			,       _lowercase				):
          __UpperCamelCase				=	[csv_path]
     __UpperCamelCase				=	tmp_path / """cache"""
     __UpperCamelCase				=	{"""col_1""": """int64""", """col_2""": """int64""", """col_3""": """float64"""}
     __UpperCamelCase				=	CsvDatasetReader(_lowercase			,       cache_dir=_lowercase				).read()
     _check_csv_dataset(_lowercase			,       _lowercase				)






def 						_A						(						_lowercase			,       _lowercase			,       _lowercase=("train",)				)			->				Tuple:


     """simple docstring"""


     assert isinstance(_lowercase			,       _lowercase				)
     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 						_A						(						_lowercase			,       _lowercase			,       _lowercase				)			->				Any:


     """simple docstring"""


     __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=_lowercase			,       keep_in_memory=_lowercase				).read()
     _check_csv_datasetdict(_lowercase			,       _lowercase				)






@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 						_A						(						_lowercase			,       _lowercase			,       _lowercase				)			->				int:


     """simple docstring"""


     __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(_lowercase				) for feature, dtype in features.items()}				) if features is not None else None
     )
     __UpperCamelCase				=	CsvDatasetReader({'train': csv_path}			,       features=_lowercase			,       cache_dir=_lowercase				).read()
     _check_csv_datasetdict(_lowercase			,       _lowercase				)






@pytest.mark.parametrize('split'			,       [None, NamedSplit('train'				), 'train', 'test']				)
def 						_A						(						_lowercase			,       _lowercase			,       _lowercase				)			->				Any:


     """simple docstring"""


     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(_lowercase			,       cache_dir=_lowercase				).read()
     _check_csv_datasetdict(_lowercase			,       _lowercase			,       splits=list(path.keys()				)				)
     assert all(dataset[split].split == split for split in path.keys()				)






def 						_A						(						_lowercase				)			->				Union[str, Any]:


     """simple docstring"""


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






def 						_A						(						_lowercase			,       _lowercase				)			->				Dict:


     """simple docstring"""


     __UpperCamelCase				=	tmp_path / """cache"""
     __UpperCamelCase				=	os.path.join(_lowercase			,       'tmp.csv'				)
     __UpperCamelCase				=	CsvDatasetReader({'train': csv_path}			,       cache_dir=_lowercase				).read()
     CsvDatasetWriter(dataset['train']			,       _lowercase			,       num_proc=1				).write()

     __UpperCamelCase				=	iter_csv_file(_lowercase				)
     __UpperCamelCase				=	iter_csv_file(_lowercase				)

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






def 						_A						(						_lowercase			,       _lowercase				)			->				Union[str, Any]:


     """simple docstring"""


     __UpperCamelCase				=	tmp_path / """cache"""
     __UpperCamelCase				=	os.path.join(_lowercase			,       'tmp.csv'				)
     __UpperCamelCase				=	CsvDatasetReader({'train': csv_path}			,       cache_dir=_lowercase				).read()
     CsvDatasetWriter(dataset['train']			,       _lowercase			,       num_proc=2				).write()

     __UpperCamelCase				=	iter_csv_file(_lowercase				)
     __UpperCamelCase				=	iter_csv_file(_lowercase				)

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






def 						_A						(						_lowercase			,       _lowercase				)			->				Dict:


     """simple docstring"""


     __UpperCamelCase				=	tmp_path / """cache"""
     __UpperCamelCase				=	os.path.join(_lowercase			,       'tmp.csv'				)
     __UpperCamelCase				=	CsvDatasetReader({'train': csv_path}			,       cache_dir=_lowercase				).read()
     with pytest.raises(_lowercase				):
          CsvDatasetWriter(dataset['train']			,       _lowercase			,       num_proc=0				)






import math






def 						_A						(						_lowercase				)			->				bool:


     """simple docstring"""


     if 1 < number < 4:
          # 2 and 3 are primes
          return True
     elif number < 2 or number % 2 == 0 or number % 3 == 0:
          # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
          return False

     # All primes number are in format of 6k +/- 1
     for i in range(5			,       int(math.sqrt(_lowercase				) + 1				)			,       6				):
          if number % i == 0 or number % (i + 2) == 0:
               return False
     return True






def 						_A						(						_lowercase = 2_00_00_00				)			->				int:


     """simple docstring"""


     return sum(num for num in range(3			,       _lowercase			,       2				) if is_prime(_lowercase				)				) + 2 if n > 2 else 0


if __name__ == "__main__":
    print(f"""{solution() = }""")


