'''simple docstring'''

import importlib
import shutil
import threading
import warnings
from typing import List

import fsspec
import fsspec.asyn

from . import compression
from .hffilesystem import HfFileSystem


_A			:      Optional[int]					      =				importlib.util.find_spec('''s3fs''') is not None

if _has_safs:
 from .safilesystem import SaFileSystem  # noqa: F401

_A			:      List[compression.BaseCompressedFileFileSystem]					      =				[
    compression.BzaFileSystem,
    compression.GzipFileSystem,
    compression.LzaFileSystem,
    compression.XzFileSystem,
    compression.ZstdFileSystem,
]

# Register custom filesystems
for fs_class in COMPRESSION_FILESYSTEMS + [HfFileSystem]:
 if fs_class.protocol in fsspec.registry and fsspec.registry[fs_class.protocol] is not fs_class:
  warnings.warn(f'A filesystem protocol was already set for {fs_class.protocol} and will be overwritten.')
 fsspec.register_implementation(fs_class.protocol, fs_class, clobber=True)







def      UpperCamelCase_						(					snake_case_       :       str      )					->     str:






 '''simple docstring'''

 if "://" in dataset_path:
  __lowerCAmelCase											=						dataset_path.split("""://"""      )[1]
 return dataset_path







def      UpperCamelCase_						(					snake_case_       :       fsspec.AbstractFileSystem      )					->     bool:






 '''simple docstring'''

 if fs is not None and fs.protocol != "file":
  return True
 else:
  return False







def      UpperCamelCase_						(					snake_case_       :       fsspec.AbstractFileSystem						,		snake_case_       :       str						,		snake_case_       :       str      )					->     Optional[Any]:






 '''simple docstring'''

 __lowerCAmelCase											=						not is_remote_filesystem(snake_case_      )
 if is_local:
  # LocalFileSystem.mv does copy + rm, it is more efficient to simply move a local directory
  shutil.move(fs._strip_protocol(snake_case_      )						,		fs._strip_protocol(snake_case_      )      )
 else:
  fs.mv(snake_case_						,		snake_case_						,		recursive=snake_case_      )







def      UpperCamelCase_						(					)					->     None:






 '''simple docstring'''

 if hasattr(fsspec.asyn						,		"""reset_lock"""      ):
  # for future fsspec>2022.05.0
  fsspec.asyn.reset_lock()
 else:
  __lowerCAmelCase											=						None
  __lowerCAmelCase											=						None
  __lowerCAmelCase											=						threading.Lock()







'''simple docstring'''

from unittest import TestCase

from datasets import Sequence, Value
from datasets.arrow_dataset import Dataset







class 				_lowercase     (				UpperCAmelCase__			):


 '''simple docstring'''






 def a					(      self   :	int							)  ->    Optional[Any]:
  return [
      {"col_1": 3, "col_2": "a"},
      {"col_1": 2, "col_2": "b"},
      {"col_1": 1, "col_2": "c"},
      {"col_1": 0, "col_2": "d"},
  ]
 def a					(      self   :	List[Any]							)  ->    Any:
  __lowerCAmelCase											=						{"""col_1""": [3, 2, 1, 0], """col_2""": ["""a""", """b""", """c""", """d"""]}
  return Dataset.from_dict(SCREAMING_SNAKE_CASE__							)
 def a					(      self   :	List[Any]							)  ->    Tuple:
  __lowerCAmelCase											=						self._create_example_records()
  __lowerCAmelCase											=						Dataset.from_list(SCREAMING_SNAKE_CASE__							)
  self.assertListEqual(dset.column_names      ,       ["""col_1""", """col_2"""]							)
  for i, r in enumerate(SCREAMING_SNAKE_CASE__							):
   self.assertDictEqual(SCREAMING_SNAKE_CASE__      ,       example_records[i]							)
 def a					(      self   :	Tuple							)  ->    List[str]:
  __lowerCAmelCase											=						self._create_example_records()
  __lowerCAmelCase											=						Dataset.from_list(SCREAMING_SNAKE_CASE__							)
  __lowerCAmelCase											=						Dataset.from_dict({k: [r[k] for r in example_records] for k in example_records[0]}							)
  self.assertEqual(dset.info      ,       dset_from_dict.info							)
 def a					(      self   :	List[str]							)  ->    List[str]:  # checks what happens with missing columns
  __lowerCAmelCase											=						[{"""col_1""": 1}, {"""col_2""": """x"""}]
  __lowerCAmelCase											=						Dataset.from_list(SCREAMING_SNAKE_CASE__							)
  self.assertDictEqual(dset[0]      ,       {"""col_1""": 1}							)
  self.assertDictEqual(dset[1]      ,       {"""col_1""": None}							)  # NB: first record is used for columns
 def a					(      self   :	Dict							)  ->    Optional[int]:  # checks if the type can be inferred from the second record
  __lowerCAmelCase											=						[{"""col_1""": []}, {"""col_1""": [1, 2]}]
  __lowerCAmelCase											=						Dataset.from_list(SCREAMING_SNAKE_CASE__							)
  self.assertEqual(dset.info.features["""col_1"""]      ,       Sequence(Value("""int64"""							)							)							)





 def a					(      self   :	Optional[Any]							)  ->    Tuple:
  __lowerCAmelCase											=						Dataset.from_list([]							)
  self.assertEqual(len(SCREAMING_SNAKE_CASE__							)      ,       0							)
  self.assertListEqual(dset.column_names      ,       []							)






