

'''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			(      SCREAMING_SNAKE_CASE_     :	Any  ,  SCREAMING_SNAKE_CASE_     :	Optional[int]    )							->   Tuple:
      """simple docstring"""

      assert isinstance(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    )
      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			(      SCREAMING_SNAKE_CASE_     :	List[str]  ,  SCREAMING_SNAKE_CASE_     :	Tuple  ,  SCREAMING_SNAKE_CASE_     :	Any    )							->   Dict:
      """simple docstring"""

      SCREAMING_SNAKE_CASE_      :			Dict     =       tmp_path / "cache"
      SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       {"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
            SCREAMING_SNAKE_CASE_      :			str     =       CsvDatasetReader(SCREAMING_SNAKE_CASE_  ,  cache_dir=SCREAMING_SNAKE_CASE_  ,  keep_in_memory=SCREAMING_SNAKE_CASE_    ).read()
      _check_csv_dataset(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    )


@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			(      SCREAMING_SNAKE_CASE_     :	int  ,  SCREAMING_SNAKE_CASE_     :	int  ,  SCREAMING_SNAKE_CASE_     :	List[Any]    )							->   Optional[Any]:
      """simple docstring"""

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


@pytest.mark.parametrize("split"  ,  [None, NamedSplit("train"    ), "train", "test"]    )
def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	Dict  ,  SCREAMING_SNAKE_CASE_     :	int  ,  SCREAMING_SNAKE_CASE_     :	Optional[Any]    )							->   Optional[Any]:
      """simple docstring"""

      SCREAMING_SNAKE_CASE_      :			Union[str, Any]     =       tmp_path / "cache"
      SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       {"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      SCREAMING_SNAKE_CASE_      :			str     =       CsvDatasetReader(SCREAMING_SNAKE_CASE_  ,  cache_dir=SCREAMING_SNAKE_CASE_  ,  split=SCREAMING_SNAKE_CASE_    ).read()
      _check_csv_dataset(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    )
      assert dataset.split == split if split else "train"


@pytest.mark.parametrize("path_type"  ,  [str, list]    )
def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	List[Any]  ,  SCREAMING_SNAKE_CASE_     :	Union[str, Any]  ,  SCREAMING_SNAKE_CASE_     :	List[str]    )							->   Tuple:
      """simple docstring"""

      if issubclass(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    ):
            SCREAMING_SNAKE_CASE_      :			int     =       csv_path
      elif issubclass(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    ):
            SCREAMING_SNAKE_CASE_      :			int     =       [csv_path]
      SCREAMING_SNAKE_CASE_      :			List[Any]     =       tmp_path / "cache"
      SCREAMING_SNAKE_CASE_      :			Optional[int]     =       {"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      SCREAMING_SNAKE_CASE_      :			str     =       CsvDatasetReader(SCREAMING_SNAKE_CASE_  ,  cache_dir=SCREAMING_SNAKE_CASE_    ).read()
      _check_csv_dataset(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    )


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	int  ,  SCREAMING_SNAKE_CASE_     :	List[str]  ,  SCREAMING_SNAKE_CASE_     :	Tuple=("train",)    )							->   Dict:
      """simple docstring"""

      assert isinstance(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    )
      for split in splits:
            SCREAMING_SNAKE_CASE_      :			List[str]     =       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			(      SCREAMING_SNAKE_CASE_     :	Dict  ,  SCREAMING_SNAKE_CASE_     :	Optional[Any]  ,  SCREAMING_SNAKE_CASE_     :	Any    )							->   Dict:
      """simple docstring"""

      SCREAMING_SNAKE_CASE_      :			Optional[int]     =       tmp_path / "cache"
      SCREAMING_SNAKE_CASE_      :			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():
            SCREAMING_SNAKE_CASE_      :			Any     =       CsvDatasetReader({"train": csv_path}  ,  cache_dir=SCREAMING_SNAKE_CASE_  ,  keep_in_memory=SCREAMING_SNAKE_CASE_    ).read()
      _check_csv_datasetdict(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    )


@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			(      SCREAMING_SNAKE_CASE_     :	List[str]  ,  SCREAMING_SNAKE_CASE_     :	List[str]  ,  SCREAMING_SNAKE_CASE_     :	Optional[int]    )							->   int:
      """simple docstring"""

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


@pytest.mark.parametrize("split"  ,  [None, NamedSplit("train"    ), "train", "test"]    )
def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	Union[str, Any]  ,  SCREAMING_SNAKE_CASE_     :	Any  ,  SCREAMING_SNAKE_CASE_     :	Optional[int]    )							->   Optional[Any]:
      """simple docstring"""

      if split:
            SCREAMING_SNAKE_CASE_      :			List[Any]     =       {split: csv_path}
      else:
            SCREAMING_SNAKE_CASE_      :			List[str]     =       {"train": csv_path, "test": csv_path}
      SCREAMING_SNAKE_CASE_      :			Any     =       tmp_path / "cache"
      SCREAMING_SNAKE_CASE_      :			Any     =       {"col_1": "int64", "col_2": "int64", "col_3": "float64"}
      SCREAMING_SNAKE_CASE_      :			str     =       CsvDatasetReader(SCREAMING_SNAKE_CASE_  ,  cache_dir=SCREAMING_SNAKE_CASE_    ).read()
      _check_csv_datasetdict(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_  ,  splits=list(path.keys()    )    )
      assert all(dataset[split].split == split for split in path.keys()    )


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	str    )							->   Optional[Any]:
      """simple docstring"""

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


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	int  ,  SCREAMING_SNAKE_CASE_     :	Dict    )							->   str:
      """simple docstring"""

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

      SCREAMING_SNAKE_CASE_      :			Any     =       iter_csv_file(SCREAMING_SNAKE_CASE_    )
      SCREAMING_SNAKE_CASE_      :			Dict     =       iter_csv_file(SCREAMING_SNAKE_CASE_    )

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


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	Dict  ,  SCREAMING_SNAKE_CASE_     :	Tuple    )							->   List[Any]:
      """simple docstring"""

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

      SCREAMING_SNAKE_CASE_      :			int     =       iter_csv_file(SCREAMING_SNAKE_CASE_    )
      SCREAMING_SNAKE_CASE_      :			List[Any]     =       iter_csv_file(SCREAMING_SNAKE_CASE_    )

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





def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	str  ,  SCREAMING_SNAKE_CASE_     :	Optional[Any]    )							->   Union[str, Any]:
      """simple docstring"""

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









"""simple docstring"""



from doctest import testmod
from math import sqrt


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      int							)->						list:






     '''simple docstring'''



     UpperCAmelCase__		:  list[int]				=				[]
     if num < 1:
          return facs
     facs.append(1							)
     if num == 1:
          return facs
     facs.append(snake_case							)
     for i in range(2       , int(sqrt(snake_case							)							) + 1							):
          if num % i == 0:  # If i is a factor of num
               facs.append(snake_case							)
               UpperCAmelCase__		:  Any				=				num // i  # num//i is the other factor of num
               if d != i:  # If d and i are distinct
                    facs.append(snake_case							)  # we have found another factor
     facs.sort()
     return facs


if __name__ == "__main__":
 testmod(name="""factors_of_a_number""", verbose=True)


