





import pyarrow.parquet as pq
import pytest

from datasets import Audio, Dataset, DatasetDict, Features, NamedSplit, Sequence, Value, config
from datasets.features.image import Image
from datasets.io.parquet import ParquetDatasetReader, ParquetDatasetWriter, get_writer_batch_size

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases



def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase					)    ->    str:







   """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 	_a						(   UpperCAmelCase      ,  UpperCAmelCase      ,  UpperCAmelCase					)    ->    List[Any]:







   """simple docstring"""
   lowerCamelCase__        =							tmp_path / "cache"
   lowerCamelCase__        =							{"col_1": "string", "col_2": "int64", "col_3": "float64"}
   with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
      lowerCamelCase__        =							ParquetDatasetReader(__SCREAMING_SNAKE_CASE      ,  cache_dir=__SCREAMING_SNAKE_CASE      ,  keep_in_memory=__SCREAMING_SNAKE_CASE					).read()
   _check_parquet_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 	_a						(   UpperCAmelCase      ,  UpperCAmelCase      ,  UpperCAmelCase					)    ->    Dict:







   """simple docstring"""
   lowerCamelCase__        =							tmp_path / "cache"
   lowerCamelCase__        =							{"col_1": "string", "col_2": "int64", "col_3": "float64"}
   lowerCamelCase__        =							features.copy() if features else default_expected_features
   lowerCamelCase__        =							(
       Features({feature: Value(__SCREAMING_SNAKE_CASE					) for feature, dtype in features.items()}					) if features is not None else None
   )
   lowerCamelCase__        =							ParquetDatasetReader(__SCREAMING_SNAKE_CASE      ,  features=__SCREAMING_SNAKE_CASE      ,  cache_dir=__SCREAMING_SNAKE_CASE					).read()
   _check_parquet_dataset(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE					)



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







   """simple docstring"""
   lowerCamelCase__        =							tmp_path / "cache"
   lowerCamelCase__        =							{"col_1": "string", "col_2": "int64", "col_3": "float64"}
   lowerCamelCase__        =							ParquetDatasetReader(__SCREAMING_SNAKE_CASE      ,  cache_dir=__SCREAMING_SNAKE_CASE      ,  split=__SCREAMING_SNAKE_CASE					).read()
   _check_parquet_dataset(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE					)
   assert dataset.split == split if split else "train"



@pytest.mark.parametrize('''path_type'''      ,  [str, list]					)
def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase      ,  UpperCAmelCase					)    ->    Any:







   """simple docstring"""
   if issubclass(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE					):
      lowerCamelCase__        =							parquet_path
   elif issubclass(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE					):
      lowerCamelCase__        =							[parquet_path]
   lowerCamelCase__        =							tmp_path / "cache"
   lowerCamelCase__        =							{"col_1": "string", "col_2": "int64", "col_3": "float64"}
   lowerCamelCase__        =							ParquetDatasetReader(__SCREAMING_SNAKE_CASE      ,  cache_dir=__SCREAMING_SNAKE_CASE					).read()
   _check_parquet_dataset(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE					)



def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase      ,  UpperCAmelCase=("train",)					)    ->    int:







   """simple docstring"""
   assert isinstance(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE					)
   for split in splits:
      lowerCamelCase__        =							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						(   UpperCAmelCase      ,  UpperCAmelCase      ,  UpperCAmelCase					)    ->    str:







   """simple docstring"""
   lowerCamelCase__        =							tmp_path / "cache"
   lowerCamelCase__        =							{"col_1": "string", "col_2": "int64", "col_3": "float64"}
   with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
      lowerCamelCase__        =							ParquetDatasetReader(
          {'''train''': parquet_path}      ,  cache_dir=__SCREAMING_SNAKE_CASE      ,  keep_in_memory=__SCREAMING_SNAKE_CASE					).read()
   _check_parquet_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 	_a						(   UpperCAmelCase      ,  UpperCAmelCase      ,  UpperCAmelCase					)    ->    Any:







   """simple docstring"""
   lowerCamelCase__        =							tmp_path / "cache"
   lowerCamelCase__        =							{"col_1": "string", "col_2": "int64", "col_3": "float64"}
   lowerCamelCase__        =							features.copy() if features else default_expected_features
   lowerCamelCase__        =							(
       Features({feature: Value(__SCREAMING_SNAKE_CASE					) for feature, dtype in features.items()}					) if features is not None else None
   )
   lowerCamelCase__        =							ParquetDatasetReader({'''train''': parquet_path}      ,  features=__SCREAMING_SNAKE_CASE      ,  cache_dir=__SCREAMING_SNAKE_CASE					).read()
   _check_parquet_datasetdict(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE					)



@pytest.mark.parametrize('''split'''      ,  [None, NamedSplit('''train'''					), '''train''', '''test''']					)
def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase      ,  UpperCAmelCase					)    ->    str:







   """simple docstring"""
   if split:
      lowerCamelCase__        =							{split: parquet_path}
   else:
      lowerCamelCase__        =							"train"
      lowerCamelCase__        =							{"train": parquet_path, "test": parquet_path}
   lowerCamelCase__        =							tmp_path / "cache"
   lowerCamelCase__        =							{"col_1": "string", "col_2": "int64", "col_3": "float64"}
   lowerCamelCase__        =							ParquetDatasetReader(__SCREAMING_SNAKE_CASE      ,  cache_dir=__SCREAMING_SNAKE_CASE					).read()
   _check_parquet_datasetdict(__SCREAMING_SNAKE_CASE      ,  __SCREAMING_SNAKE_CASE      ,  splits=list(path.keys()					)					)
   assert all(dataset[split].split == split for split in path.keys()					)



def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase					)    ->    Any:







   """simple docstring"""
   lowerCamelCase__        =							ParquetDatasetWriter(__SCREAMING_SNAKE_CASE      ,  tmp_path / '''foo.parquet'''					)
   assert writer.write() > 0
   lowerCamelCase__        =							pq.ParquetFile(tmp_path / '''foo.parquet'''					)
   lowerCamelCase__        =							pf.read()
   assert dataset.data.table == output_table



def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase					)    ->    str:







   """simple docstring"""
   lowerCamelCase__        =							str(shared_datadir / '''test_image_rgb.jpg'''					)
   lowerCamelCase__        =							{"image": [image_path]}
   lowerCamelCase__        =							Features({'''image''': Image()}					)
   lowerCamelCase__        =							Dataset.from_dict(__SCREAMING_SNAKE_CASE      ,  features=__SCREAMING_SNAKE_CASE					)
   lowerCamelCase__        =							ParquetDatasetWriter(__SCREAMING_SNAKE_CASE      ,  tmp_path / '''foo.parquet'''					)
   assert writer.write() > 0

   lowerCamelCase__        =							Dataset.from_parquet(str(tmp_path / '''foo.parquet'''					)					)
   assert dataset.features == reloaded_dataset.features

   lowerCamelCase__        =							ParquetDatasetReader(str(tmp_path / '''foo.parquet'''					)      ,  streaming=__SCREAMING_SNAKE_CASE					).read()
   assert dataset.features == reloaded_iterable_dataset.features




@pytest.mark.parametrize(
    '''feature, expected'''      ,  [
        (Features({'''foo''': Value('''int32'''					)}					), None),
        (Features({'''image''': Image(), '''foo''': Value('''int32'''					)}					), config.PARQUET_ROW_GROUP_SIZE_FOR_IMAGE_DATASETS),
        (Features({'''nested''': Sequence(Audio()					)}					), config.PARQUET_ROW_GROUP_SIZE_FOR_AUDIO_DATASETS),
    ]      ,  )
def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase					)    ->    Union[str, Any]:







   """simple docstring"""
   assert get_writer_batch_size(__SCREAMING_SNAKE_CASE					) == expected










def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase					)    ->    Dict:







   """simple docstring"""
   if b == 0:
      return 1
   if (b % 2) == 0:
      return actual_power(UpperCAmelCase      ,  int(b / 2					)					) * actual_power(UpperCAmelCase      ,  int(b / 2					)					)
   else:
      return a * actual_power(UpperCAmelCase      ,  int(b / 2					)					) * actual_power(UpperCAmelCase      ,  int(b / 2					)					)



def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase					)    ->    float:







   """simple docstring"""
   if b < 0:
      return 1 / actual_power(UpperCAmelCase      ,  UpperCAmelCase					)
   return actual_power(UpperCAmelCase      ,  UpperCAmelCase					)


if __name__ == "__main__":
       print(power(-2, -3))



