





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     a__ (					lowercase__  ):  # picklable for multiprocessing






   '''simple docstring'''






   return i + 1




@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def     a__ (					):






   '''simple docstring'''






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

   UpperCAmelCase_											=[1, 2, 3]
   with pytest.raises(lowercase__  ):
      with parallel_backend("unsupported backend"  ):
         map_nested(lowercase__  ,    lowercase__  ,    num_proc=2  )

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





@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize("num_proc"  ,    [2, -1]  )
def     a__ (					lowercase__  ):






   '''simple docstring'''






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

   with parallel_backend("spark"  ):
      assert map_nested(lowercase__  ,    lowercase__  ,    num_proc=lowercase__  ) == expected_map_nested_sa
      assert map_nested(lowercase__  ,    lowercase__  ,    num_proc=lowercase__  ) == expected_map_nested_sa
      assert map_nested(lowercase__  ,    lowercase__  ,    num_proc=lowercase__  ) == expected_map_nested_sa
      assert map_nested(lowercase__  ,    lowercase__  ,    num_proc=lowercase__  ) == expected_map_nested_sa
      assert map_nested(lowercase__  ,    lowercase__  ,    num_proc=lowercase__  ) == expected_map_nested_sa











from __future__ import annotations




def     a__ (					lowercase__  ,    lowercase__  ):






   '''simple docstring'''






   UpperCAmelCase_						,       UpperCAmelCase_											=set(lowercase__  ), [start]

   while stack:
      UpperCAmelCase_											=stack.pop()
      explored.add(lowercase__  )
      # Differences from BFS:
      # 1) pop last element instead of first one
      # 2) add adjacent elements to stack without exploring them
      for adj in reversed(graph[v]  ):
         if adj not in explored:
            stack.append(lowercase__  )
   return explored


__lowercase  :   Dict						      ={
    """A""": ["""B""", """C""", """D"""],
    """B""": ["""A""", """D""", """E"""],
    """C""": ["""A""", """F"""],
    """D""": ["""B""", """D"""],
    """E""": ["""B""", """F"""],
    """F""": ["""C""", """E""", """G"""],
    """G""": ["""F"""],
}

if __name__ == "__main__":
     import doctest

     doctest.testmod()
     print(depth_first_search(G, """A"""))




