





'''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:			Tuple						     =   PandasConfig




      def 				lowercase__    (			self			: Optional[Any]  )				->      str:
            return datasets.DatasetInfo(features=self.config.features  )




      def 				lowercase__    (			self			: List[str]			,			__snake_case			: Dict  )				->      int:
            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(__snake_case			,			(str, list, tuple)  ):
                  _lowerCAmelCase							     =							data_files
                  if isinstance(__snake_case			,			__snake_case  ):
                        _lowerCAmelCase							     =							[files]
                  # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
                  _lowerCAmelCase							     =							[dl_manager.iter_files(__snake_case  ) 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(__snake_case			,			__snake_case  ):
                        _lowerCAmelCase							     =							[files]
                  # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
                  _lowerCAmelCase							     =							[dl_manager.iter_files(__snake_case  ) for file in files]
                  splits.append(datasets.SplitGenerator(name=__snake_case			,			gen_kwargs={"""files""": files}  )  )
            return splits




      def 				lowercase__    (			self			: List[Any]			,			__snake_case			: pa.Table  )				->      pa.Table:
            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(__snake_case			,			self.config.features.arrow_schema  )
            return pa_table




      def 				lowercase__    (			self			: Dict			,			__snake_case			: Optional[Any]  )				->      Any:
            for i, file in enumerate(itertools.chain.from_iterable(__snake_case  )  ):
                  with open(__snake_case			,			"""rb"""  ) as f:
                        _lowerCAmelCase							     =							pa.Table.from_pandas(pd.read_pickle(__snake_case  )  )
                        yield i, self._cast_table(__snake_case  )







from functools import lru_cache




@lru_cache
def       _snake_case	(   lowerCAmelCase							:   int	):
		"""simple docstring"""







		if num < 0:
				raise ValueError("Number should not be negative."	)

		return 1 if num in (0, 1) else num * factorial(num - 1	)


if __name__ == "__main__":
		import doctest

		doctest.testmod()
