



"""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 	__lowerCAmelCase						(		__UpperCamelCase      :			Optional[Any]					, __UpperCamelCase      :			int    ):


      '''simple docstring'''






      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      :			Any					, __UpperCamelCase      :			Any					, __UpperCamelCase      :			Optional[int]    ):


      '''simple docstring'''






      snake_case_   : str						=			tmp_path / """cache"""
      snake_case_   : Any						=			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
      with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
            snake_case_   : int						=			ParquetDatasetReader(__UpperCamelCase					, cache_dir=__UpperCamelCase					, keep_in_memory=__UpperCamelCase    ).read()
      _check_parquet_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      :			Optional[Any]					, __UpperCamelCase      :			Optional[Any]					, __UpperCamelCase      :			Tuple    ):


      '''simple docstring'''






      snake_case_   : Any						=			tmp_path / """cache"""
      snake_case_   : Optional[int]						=			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
      snake_case_   : Optional[Any]						=			features.copy() if features else default_expected_features
      snake_case_   : Any						=			(
          Features({feature: Value(__UpperCamelCase    ) for feature, dtype in features.items()}    ) if features is not None else None
      )
      snake_case_   : Optional[Any]						=			ParquetDatasetReader(__UpperCamelCase					, features=__UpperCamelCase					, cache_dir=__UpperCamelCase    ).read()
      _check_parquet_dataset(__UpperCamelCase					, __UpperCamelCase    )
@pytest.mark.parametrize("""split"""					, [None, NamedSplit("""train"""    ), """train""", """test"""]    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			str					, __UpperCamelCase      :			str					, __UpperCamelCase      :			int    ):


      '''simple docstring'''






      snake_case_   : int						=			tmp_path / """cache"""
      snake_case_   : Any						=			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
      snake_case_   : List[Any]						=			ParquetDatasetReader(__UpperCamelCase					, cache_dir=__UpperCamelCase					, split=__UpperCamelCase    ).read()
      _check_parquet_dataset(__UpperCamelCase					, __UpperCamelCase    )
      assert dataset.split == split if split else "train"
@pytest.mark.parametrize("""path_type"""					, [str, list]    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			str					, __UpperCamelCase      :			Optional[Any]					, __UpperCamelCase      :			int    ):


      '''simple docstring'''






      if issubclass(__UpperCamelCase					, __UpperCamelCase    ):
            snake_case_   : List[Any]						=			parquet_path
      elif issubclass(__UpperCamelCase					, __UpperCamelCase    ):
            snake_case_   : Optional[int]						=			[parquet_path]
      snake_case_   : Union[str, Any]						=			tmp_path / """cache"""
      snake_case_   : List[str]						=			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
      snake_case_   : Optional[Any]						=			ParquetDatasetReader(__UpperCamelCase					, cache_dir=__UpperCamelCase    ).read()
      _check_parquet_dataset(__UpperCamelCase					, __UpperCamelCase    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			List[Any]					, __UpperCamelCase      :			str					, __UpperCamelCase      :			Dict=("train",)    ):


      '''simple docstring'''






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


      '''simple docstring'''






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


      '''simple docstring'''






      snake_case_   : Any						=			tmp_path / """cache"""
      snake_case_   : Tuple						=			{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
      snake_case_   : Dict						=			features.copy() if features else default_expected_features
      snake_case_   : Tuple						=			(
          Features({feature: Value(__UpperCamelCase    ) for feature, dtype in features.items()}    ) if features is not None else None
      )
      snake_case_   : Optional[Any]						=			ParquetDatasetReader({"""train""": parquet_path}					, features=__UpperCamelCase					, cache_dir=__UpperCamelCase    ).read()
      _check_parquet_datasetdict(__UpperCamelCase					, __UpperCamelCase    )
@pytest.mark.parametrize("""split"""					, [None, NamedSplit("""train"""    ), """train""", """test"""]    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			Optional[Any]					, __UpperCamelCase      :			Tuple					, __UpperCamelCase      :			List[Any]    ):


      '''simple docstring'''






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


      '''simple docstring'''






      snake_case_   : Union[str, Any]						=			ParquetDatasetWriter(__UpperCamelCase					, tmp_path / """foo.parquet"""    )
      assert writer.write() > 0
      snake_case_   : List[Any]						=			pq.ParquetFile(tmp_path / """foo.parquet"""    )
      snake_case_   : Union[str, Any]						=			pf.read()
      assert dataset.data.table == output_table
def 	__lowerCAmelCase						(		__UpperCamelCase      :			Dict					, __UpperCamelCase      :			Optional[int]    ):


      '''simple docstring'''






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

      snake_case_   : str						=			Dataset.from_parquet(str(tmp_path / """foo.parquet"""    )    )
      assert dataset.features == reloaded_dataset.features

      snake_case_   : Any						=			ParquetDatasetReader(str(tmp_path / """foo.parquet"""    )					, streaming=__UpperCamelCase    ).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 	__lowerCAmelCase						(		__UpperCamelCase      :			str					, __UpperCamelCase      :			int    ):


      '''simple docstring'''






      assert get_writer_batch_size(__UpperCamelCase    ) == expected






"""simple docstring"""





def 	__lowerCAmelCase						(		__UpperCamelCase      :			Union[str, Any]    ):


						'''simple docstring'''






						snake_case_   : int						=			[0] * len(__UpperCamelCase    )
						snake_case_   : List[str]						=			[]
						snake_case_   : Any						=			[1] * len(__UpperCamelCase    )

						for values in graph.values():
												for i in values:
																		indegree[i] += 1

						for i in range(len(__UpperCamelCase    )    ):
												if indegree[i] == 0:
																		queue.append(__UpperCamelCase    )

						while queue:
												snake_case_   : Optional[int]						=			queue.pop(0    )
												for x in graph[vertex]:
																		indegree[x] -= 1

																		if long_dist[vertex] + 1 > long_dist[x]:
																								snake_case_   : Union[str, Any]						=			long_dist[vertex] + 1

																		if indegree[x] == 0:
																								queue.append(__UpperCamelCase    )

						print(max(__UpperCamelCase    )    )


# Adjacency list of Graph
__lowerCAmelCase       :					str      					=					{0: [2, 3, 4], 1: [2, 7], 2: [5], 3: [5, 7], 4: [7], 5: [6], 6: [7], 7: []}






longest_distance(graph)

