




'''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   __UpperCamelCase       ( datasets.BuilderConfig				):
       lowercase	:    Optional[datasets.Features]      						=None





class   __UpperCamelCase       ( datasets.ArrowBasedBuilder				):
       lowercase	:    Optional[int]      						=PandasConfig






       def      lowercase__     (							self  ):



              """simple docstring"""







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






       def      lowercase__     (							self,		lowerCAmelCase  ):



              """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}'''  )
              lowerCamelCase_							=dl_manager.download_and_extract(self.config.data_files  )
              if isinstance(a__,		(str, list, tuple)  ):
                     lowerCamelCase_							=data_files
                     if isinstance(a__,		a__  ):
                            lowerCamelCase_							=[files]
                     # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
                     lowerCamelCase_							=[dl_manager.iter_files(a__  ) for file in files]
                     return [datasets.SplitGenerator(name=datasets.Split.TRAIN,		gen_kwargs={'''files''': files}  )]
              lowerCamelCase_							=[]
              for split_name, files in data_files.items():
                     if isinstance(a__,		a__  ):
                            lowerCamelCase_							=[files]
                     # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
                     lowerCamelCase_							=[dl_manager.iter_files(a__  ) for file in files]
                     splits.append(datasets.SplitGenerator(name=a__,		gen_kwargs={'''files''': files}  )  )
              return splits






       def      lowercase__     (							self,		lowerCAmelCase  ):



              """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
                     lowerCamelCase_							=table_cast(a__,		self.config.features.arrow_schema  )
              return pa_table






       def      lowercase__     (							self,		lowerCAmelCase  ):



              """simple docstring"""







              for i, file in enumerate(itertools.chain.from_iterable(a__  )  ):
                     with open(a__,		'''rb'''  ) as f:
                            lowerCamelCase_							=pa.Table.from_pandas(pd.read_pickle(a__  )  )
                            yield i, self._cast_table(a__  )











import os

import pytest

from transformers.dynamic_module_utils import get_imports


snake_case_				=			'\nimport os\n'

snake_case_				=			'\ndef foo():\n    import os\n    return False\n'

snake_case_				=			'\ndef foo():\n    def bar():\n        if True:\n            import os\n        return False\n    return bar()\n'

snake_case_				=			'\nimport os\n\ntry:\n    import bar\nexcept ImportError:\n    raise ValueError()\n'

snake_case_				=			'\nimport os\n\ndef foo():\n    try:\n        import bar\n    except ImportError:\n        raise ValueError()\n'

snake_case_				=			'\nimport os\n\ntry:\n    import bar\nexcept (ImportError, AttributeError):\n    raise ValueError()\n'

snake_case_				=			'\nimport os\n\ntry:\n    import bar\nexcept ImportError as e:\n    raise ValueError()\n'

snake_case_				=			'\nimport os\n\ntry:\n    import bar\nexcept:\n    raise ValueError()\n'

snake_case_				=			'\nimport os\n\ntry:\n    import bar\n    import baz\nexcept ImportError:\n    raise ValueError()\n'

snake_case_				=			'\nimport os\n\ntry:\n    import bar\n    import baz\nexcept ImportError:\n    x = 1\n    raise ValueError()\n'

snake_case_				=			[
    TOP_LEVEL_IMPORT,
    IMPORT_IN_FUNCTION,
    DEEPLY_NESTED_IMPORT,
    TOP_LEVEL_TRY_IMPORT,
    GENERIC_EXCEPT_IMPORT,
    MULTILINE_TRY_IMPORT,
    MULTILINE_BOTH_IMPORT,
    MULTIPLE_EXCEPTS_IMPORT,
    EXCEPT_AS_IMPORT,
    TRY_IMPORT_IN_FUNCTION,
]






@pytest.mark.parametrize('''case'''       ,      snake_case_       )
def lowerCamelCase__    (							snake_case_	:  str       ,      snake_case_	:  Optional[int]       )      ->				Dict:
   __snake_case							       =   os.path.join(snake_case_       ,      '''test_file.py'''       )
   with open(snake_case_       ,      '''w'''       ) as _tmp_file:
      _tmp_file.write(snake_case_       )

   __snake_case							       =   get_imports(snake_case_       )
   assert parsed_imports == ["os"]

