

import pytest

from datasets.parallel import ParallelBackendConfig, parallel_backend
from datasets.utils.py_utils import map_nested

from .utils import require_dill_gt_0_3_2, require_joblibspark, require_not_windows


def 							__lowerCAmelCase     (							_UpperCamelCase		:	List[str]						)		->				Any:  # picklable for multiprocessing
 '''simple docstring'''


 return i + 1


@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 							__lowerCAmelCase     (							)		->				Any:
 '''simple docstring'''


 with parallel_backend('spark'						):
  assert ParallelBackendConfig.backend_name == "spark"

 SCREAMING_SNAKE_CASE		    =      [1, 2, 3]
 with pytest.raises(_UpperCamelCase						):
  with parallel_backend('unsupported backend'						):
   map_nested(_UpperCamelCase		,				_UpperCamelCase		,				num_proc=2						)

 with pytest.raises(_UpperCamelCase						):
  with parallel_backend('unsupported backend'						):
   map_nested(_UpperCamelCase		,				_UpperCamelCase		,				num_proc=-1						)




@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize('num_proc'		,				[2, -1]						)
def 							__lowerCAmelCase     (							_UpperCamelCase		:	Tuple						)		->				Dict:
 '''simple docstring'''


 SCREAMING_SNAKE_CASE		    =      [1, 2]
 SCREAMING_SNAKE_CASE		    =      {'a': 1, 'b': 2}
 SCREAMING_SNAKE_CASE		    =      {'a': [1, 2], 'b': [3, 4]}
 SCREAMING_SNAKE_CASE		    =      {'a': {'1': 1}, 'b': 2}
 SCREAMING_SNAKE_CASE		    =      {'a': 1, 'b': 2, 'c': 3, 'd': 4}
 SCREAMING_SNAKE_CASE		    =      [2, 3]
 SCREAMING_SNAKE_CASE		    =      {'a': 2, 'b': 3}
 SCREAMING_SNAKE_CASE		    =      {'a': [2, 3], 'b': [4, 5]}
 SCREAMING_SNAKE_CASE		    =      {'a': {'1': 2}, 'b': 3}
 SCREAMING_SNAKE_CASE		    =      {'a': 2, 'b': 3, 'c': 4, 'd': 5}

 with parallel_backend('spark'						):
  assert map_nested(_UpperCamelCase		,				_UpperCamelCase		,				num_proc=_UpperCamelCase						) == expected_map_nested_sa
  assert map_nested(_UpperCamelCase		,				_UpperCamelCase		,				num_proc=_UpperCamelCase						) == expected_map_nested_sa
  assert map_nested(_UpperCamelCase		,				_UpperCamelCase		,				num_proc=_UpperCamelCase						) == expected_map_nested_sa
  assert map_nested(_UpperCamelCase		,				_UpperCamelCase		,				num_proc=_UpperCamelCase						) == expected_map_nested_sa
  assert map_nested(_UpperCamelCase		,				_UpperCamelCase		,				num_proc=_UpperCamelCase						) == expected_map_nested_sa




from graphs.minimum_spanning_tree_kruskal import kruskal


def 							__lowerCAmelCase     (							)		->				Optional[Any]:
 '''simple docstring'''


 SCREAMING_SNAKE_CASE		    =      9
 SCREAMING_SNAKE_CASE		    =      [
     [0, 1, 4],
     [0, 7, 8],
     [1, 2, 8],
     [7, 8, 7],
     [7, 6, 1],
     [2, 8, 2],
     [8, 6, 6],
     [2, 3, 7],
     [2, 5, 4],
     [6, 5, 2],
     [3, 5, 14],
     [3, 4, 9],
     [5, 4, 10],
     [1, 7, 11],
 ]

 SCREAMING_SNAKE_CASE		    =      kruskal(_UpperCamelCase		,				_UpperCamelCase						)

 SCREAMING_SNAKE_CASE		    =      [
     [7, 6, 1],
     [2, 8, 2],
     [6, 5, 2],
     [0, 1, 4],
     [2, 5, 4],
     [2, 3, 7],
     [0, 7, 8],
     [3, 4, 9],
 ]

 assert sorted(_UpperCamelCase						) == sorted(_UpperCamelCase						)

