





"""simple docstring"""



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 						__lowercase	(  snake_case_    :    List[str]							,snake_case_    :    Tuple		)  ->Dict:



    '''simple docstring'''







    assert isinstance(snake_case_							,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 						__lowercase	(  snake_case_    :    int							,snake_case_    :    Optional[Any]							,snake_case_    :    Optional[int]		)  ->Dict:



    '''simple docstring'''







    __A       :		List[Any]							=	tmp_path / '''cache'''
    __A       :		Dict							=	{'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
    with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
        __A       :		List[Any]							=	ParquetDatasetReader(snake_case_							,cache_dir=snake_case_							,keep_in_memory=snake_case_		).read()
    _check_parquet_dataset(snake_case_							,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 						__lowercase	(  snake_case_    :    List[Any]							,snake_case_    :    int							,snake_case_    :    int		)  ->Dict:



    '''simple docstring'''







    __A       :		List[Any]							=	tmp_path / '''cache'''
    __A       :		List[str]							=	{'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
    __A       :		Tuple							=	features.copy() if features else default_expected_features
    __A       :		Dict							=	(
        Features({feature: Value(snake_case_		) for feature, dtype in features.items()}		) if features is not None else None
    )
    __A       :		Optional[int]							=	ParquetDatasetReader(snake_case_							,features=snake_case_							,cache_dir=snake_case_		).read()
    _check_parquet_dataset(snake_case_							,snake_case_		)







@pytest.mark.parametrize('''split'''							,[None, NamedSplit('''train'''		), '''train''', '''test''']		)
def 						__lowercase	(  snake_case_    :    List[str]							,snake_case_    :    Union[str, Any]							,snake_case_    :    List[Any]		)  ->Optional[int]:



    '''simple docstring'''







    __A       :		Dict							=	tmp_path / '''cache'''
    __A       :		Union[str, Any]							=	{'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
    __A       :		Union[str, Any]							=	ParquetDatasetReader(snake_case_							,cache_dir=snake_case_							,split=snake_case_		).read()
    _check_parquet_dataset(snake_case_							,snake_case_		)
    assert dataset.split == split if split else "train"







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



    '''simple docstring'''







    if issubclass(snake_case_							,snake_case_		):
        __A       :		Optional[Any]							=	parquet_path
    elif issubclass(snake_case_							,snake_case_		):
        __A       :		int							=	[parquet_path]
    __A       :		str							=	tmp_path / '''cache'''
    __A       :		Any							=	{'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
    __A       :		int							=	ParquetDatasetReader(snake_case_							,cache_dir=snake_case_		).read()
    _check_parquet_dataset(snake_case_							,snake_case_		)







def 						__lowercase	(  snake_case_    :    Dict							,snake_case_    :    str							,snake_case_    :    str=("train",)		)  ->Optional[Any]:



    '''simple docstring'''







    assert isinstance(snake_case_							,snake_case_		)
    for split in splits:
        __A       :		int							=	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 						__lowercase	(  snake_case_    :    Union[str, Any]							,snake_case_    :    Any							,snake_case_    :    Dict		)  ->Optional[Any]:



    '''simple docstring'''







    __A       :		List[Any]							=	tmp_path / '''cache'''
    __A       :		Dict							=	{'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
    with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
        __A       :		Optional[int]							=	ParquetDatasetReader(
            {'''train''': parquet_path}							,cache_dir=snake_case_							,keep_in_memory=snake_case_		).read()
    _check_parquet_datasetdict(snake_case_							,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 						__lowercase	(  snake_case_    :    Optional[Any]							,snake_case_    :    List[Any]							,snake_case_    :    Optional[int]		)  ->Tuple:



    '''simple docstring'''







    __A       :		List[Any]							=	tmp_path / '''cache'''
    __A       :		Optional[Any]							=	{'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
    __A       :		List[Any]							=	features.copy() if features else default_expected_features
    __A       :		int							=	(
        Features({feature: Value(snake_case_		) for feature, dtype in features.items()}		) if features is not None else None
    )
    __A       :		Tuple							=	ParquetDatasetReader({'''train''': parquet_path}							,features=snake_case_							,cache_dir=snake_case_		).read()
    _check_parquet_datasetdict(snake_case_							,snake_case_		)







@pytest.mark.parametrize('''split'''							,[None, NamedSplit('''train'''		), '''train''', '''test''']		)
def 						__lowercase	(  snake_case_    :    int							,snake_case_    :    int							,snake_case_    :    List[str]		)  ->int:



    '''simple docstring'''







    if split:
        __A       :		Tuple							=	{split: parquet_path}
    else:
        __A       :		str							=	'''train'''
        __A       :		Optional[int]							=	{'''train''': parquet_path, '''test''': parquet_path}
    __A       :		Tuple							=	tmp_path / '''cache'''
    __A       :		List[Any]							=	{'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
    __A       :		Optional[int]							=	ParquetDatasetReader(snake_case_							,cache_dir=snake_case_		).read()
    _check_parquet_datasetdict(snake_case_							,snake_case_							,splits=list(path.keys()		)		)
    assert all(dataset[split].split == split for split in path.keys()		)







def 						__lowercase	(  snake_case_    :    Tuple							,snake_case_    :    int		)  ->List[str]:



    '''simple docstring'''







    __A       :		List[Any]							=	ParquetDatasetWriter(snake_case_							,tmp_path / '''foo.parquet'''		)
    assert writer.write() > 0
    __A       :		Any							=	pq.ParquetFile(tmp_path / '''foo.parquet'''		)
    __A       :		Union[str, Any]							=	pf.read()
    assert dataset.data.table == output_table







def 						__lowercase	(  snake_case_    :    List[str]							,snake_case_    :    Optional[int]		)  ->Union[str, Any]:



    '''simple docstring'''







    __A       :		Any							=	str(shared_datadir / '''test_image_rgb.jpg'''		)
    __A       :		int							=	{'''image''': [image_path]}
    __A       :		str							=	Features({'''image''': Image()}		)
    __A       :		List[Any]							=	Dataset.from_dict(snake_case_							,features=snake_case_		)
    __A       :		Tuple							=	ParquetDatasetWriter(snake_case_							,tmp_path / '''foo.parquet'''		)
    assert writer.write() > 0

    __A       :		List[str]							=	Dataset.from_parquet(str(tmp_path / '''foo.parquet'''		)		)
    assert dataset.features == reloaded_dataset.features

    __A       :		List[Any]							=	ParquetDatasetReader(str(tmp_path / '''foo.parquet'''		)							,streaming=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 						__lowercase	(  snake_case_    :    List[str]							,snake_case_    :    List[str]		)  ->Union[str, Any]:



    '''simple docstring'''







    assert get_writer_batch_size(snake_case_		) == expected











"""simple docstring"""



def 						__lowercase	(  snake_case_    :    int							,snake_case_    :    int		)  ->int:



    '''simple docstring'''







    return int((input_a, input_a).count(0		) == 0		)







def 						__lowercase	(  )  ->None:



    '''simple docstring'''







    assert and_gate(0							,0		) == 0
    assert and_gate(0							,1		) == 0
    assert and_gate(1							,0		) == 0
    assert and_gate(1							,1		) == 1


if __name__ == "__main__":
       test_and_gate()
       print(and_gate(1, 0))
       print(and_gate(0, 0))
       print(and_gate(0, 1))
       print(and_gate(1, 1))




