





'''simple docstring'''




import importlib.metadata
import operator
import re
import sys
from typing import Optional

from packaging import version


lowercase__    :      str						=    {
    '''<''': operator.lt,
    '''<=''': operator.le,
    '''==''': operator.eq,
    '''!=''': operator.ne,
    '''>=''': operator.ge,
    '''>''': operator.gt,
}






def        _lowerCAmelCase			(  __snake_case  : Optional[Any] ,							__snake_case  : Any ,							__snake_case  : Dict ,							__snake_case  : str ,							__snake_case  : List[Any] ,							__snake_case  : str			)     ->     Any:
     if got_ver is None or want_ver is None:
          raise ValueError(
              f'Unable to compare versions for {requirement}: need={want_ver} found={got_ver}. This is unusual. Consider'
              f' reinstalling {pkg}.'			)
     if not ops[op](version.parse(__snake_case			) ,							version.parse(__snake_case			)			):
          raise ImportError(
              f'{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}'			)






def        _lowerCAmelCase			(  __snake_case  : str ,							__snake_case  : Optional[str] = None			)     ->     None:
     __A						: List[str]      =       f'\n{hint}' if hint is not None else ''

     # non-versioned check
     if re.match(r'^[\w_\-\d]+$' ,							__snake_case			):
          __A ,__A ,__A						: Union[str, Any]      =       requirement, None, None
     else:
          __A						: Union[str, Any]      =       re.findall(r'^([^!=<>\s]+)([\s!=<>]{1,2}.+)' ,							__snake_case			)
          if not match:
               raise ValueError(
                   'requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but'
                   f' got {requirement}'			)
          __A ,__A						: Dict      =       match[0]
          __A						: Any      =       want_full.split(','			)  # there could be multiple requirements
          __A						: str      =       {}
          for w in want_range:
               __A						: Tuple      =       re.findall(r'^([\s!=<>]{1,2})(.+)' ,							__snake_case			)
               if not match:
                    raise ValueError(
                        'requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23,'
                        f' but got {requirement}'			)
               __A ,__A						: List[str]      =       match[0]
               __A						: int      =       want_ver
               if op not in ops:
                    raise ValueError(f'{requirement}: need one of {list(ops.keys()			)}, but got {op}'			)

    # special case
     if pkg == "python":
          __A						: Union[str, Any]      =       '.'.join([str(__snake_case			) for x in sys.version_info[:3]]			)
          for op, want_ver in wanted.items():
               _compare_versions(__snake_case ,							__snake_case ,							__snake_case ,							__snake_case ,							__snake_case ,							__snake_case			)
          return

     # check if any version is installed
     try:
          __A						: Union[str, Any]      =       importlib.metadata.version(__snake_case			)
     except importlib.metadata.PackageNotFoundError:
          raise importlib.metadata.PackageNotFoundError(
              f'The \'{requirement}\' distribution was not found and is required by this application. {hint}'			)

     # check that the right version is installed if version number or a range was provided
     if want_ver is not None:
          for op, want_ver in wanted.items():
               _compare_versions(__snake_case ,							__snake_case ,							__snake_case ,							__snake_case ,							__snake_case ,							__snake_case			)







def        _lowerCAmelCase			(  __snake_case  : Union[str, Any]			)     ->     Optional[int]:
     __A						: Any      =       'Try: pip install transformers -U or pip install -e \'.[dev]\' if you\'re working with git main'
     return require_version(__snake_case ,							__snake_case			)






'''simple docstring'''




import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast


@dataclass
class  SCREAMING_SNAKE_CASE    (datasets.BuilderConfig							):
     lowerCAmelCase					=       None




class  SCREAMING_SNAKE_CASE    (datasets.ArrowBasedBuilder							):
     lowerCAmelCase					=       PandasConfig


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return datasets.DatasetInfo(features=self.config.features)


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase):

          '''simple docstring'''






          if not self.config.data_files:
               raise ValueError(F'At least one data file must be specified, but got data_files={self.config.data_files}')
          __A						: Dict      =       dl_manager.download_and_extract(self.config.data_files)
          if isinstance(_UpperCAmelCase						,	(str, list, tuple)):
               __A						: Union[str, Any]      =       data_files
               if isinstance(_UpperCAmelCase						,	_UpperCAmelCase):
                    __A						: Optional[int]      =       [files]
               # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
               __A						: Optional[Any]      =       [dl_manager.iter_files(_UpperCAmelCase) for file in files]
               return [datasets.SplitGenerator(name=datasets.Split.TRAIN						,	gen_kwargs={'files': files})]
          __A						: Tuple      =       []
          for split_name, files in data_files.items():
               if isinstance(_UpperCAmelCase						,	_UpperCAmelCase):
                    __A						: Dict      =       [files]
               # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
               __A						: Optional[Any]      =       [dl_manager.iter_files(_UpperCAmelCase) for file in files]
               splits.append(datasets.SplitGenerator(name=_UpperCAmelCase						,	gen_kwargs={'files': files}))
          return splits


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase):

          '''simple docstring'''






          if self.config.features is not None:
               # more expensive cast to support nested features with keys in a different order
               # allows str <-> int/float or str to Audio for example
               __A						: List[str]      =       table_cast(_UpperCAmelCase						,	self.config.features.arrow_schema)
          return pa_table


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase):

          '''simple docstring'''






          for i, file in enumerate(itertools.chain.from_iterable(_UpperCAmelCase)):
               with open(_UpperCAmelCase						,	'rb') as f:
                    __A						: Optional[int]      =       pa.Table.from_pandas(pd.read_pickle(_UpperCAmelCase))
                    yield i, self._cast_table(_UpperCAmelCase)