
import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


__lowerCAmelCase					:			str			      =		False
try:
 __lowerCAmelCase					:			Dict			      =		_is_package_available("google.colab")
except ModuleNotFoundError:
 pass


@input.register
class 						__lowerCAmelCase	:



      """simple docstring"""







      def __init__(      self		:       int				,       _snake_case		:       str = None				,       _snake_case		:       list = []				):
          __lowercase		:			str	    =       0
          __lowercase		:			str	    =       choices
          __lowercase		:			Optional[Any]	    =       prompt
          if sys.platform == "win32":
              __lowercase		:			Any	    =       '''*'''
          else:
              __lowercase		:			str	    =       '''➔ '''




      def 		snake_case_			(      self		:       Tuple				,       _snake_case		:       Optional[Any]				,       _snake_case		:       str = ""				):
          if sys.platform != "win32":
              writeColor(self.choices[index]				,       32				,       _snake_case				)
          else:
              forceWrite(self.choices[index]				,       _snake_case				)




      def 		snake_case_			(      self		:       Tuple				,       _snake_case		:       int				):
          if index == self.position:
              forceWrite(F' {self.arrow_char} '				)
              self.write_choice(_snake_case				)
          else:
              forceWrite(F'    {self.choices[index]}'				)
          reset_cursor()




      def 		snake_case_			(      self		:       Dict				,       _snake_case		:       Direction				,       _snake_case		:       int = 1				):
          __lowercase		:			Dict	    =       self.position
          if direction == Direction.DOWN:
              if self.position + 1 >= len(self.choices				):
                  return
              self.position += num_spaces
          else:
              if self.position - 1 < 0:
                  return
              self.position -= num_spaces
          clear_line()
          self.print_choice(_snake_case				)
          move_cursor(_snake_case				,       direction.name				)
          self.print_choice(self.position				)




      @input.mark(KEYMAP['''up''']				)
      def 		snake_case_			(      self		:       List[str]				):
          self.move_direction(Direction.UP				)




      @input.mark(KEYMAP['''down''']				)
      def 		snake_case_			(      self		:       Union[str, Any]				):
          self.move_direction(Direction.DOWN				)




      @input.mark(KEYMAP['''newline''']				)
      def 		snake_case_			(      self		:       int				):
          move_cursor(len(self.choices				) - self.position				,       '''DOWN'''				)
          return self.position




      @input.mark(KEYMAP['''interrupt''']				)
      def 		snake_case_			(      self		:       List[str]				):
          move_cursor(len(self.choices				) - self.position				,       '''DOWN'''				)
          raise KeyboardInterrupt




      @input.mark_multiple(*[KEYMAP[str(_snake_case				)] for number in range(10				)]				)
      def 		snake_case_			(      self		:       Tuple				):
          __lowercase		:			Any	    =       int(chr(self.current_selection				)				)
          __lowercase		:			str	    =       index - self.position
          if index == self.position:
              return
          if index < len(self.choices				):
              if self.position > index:
                  self.move_direction(Direction.UP				,       -movement				)
              elif self.position < index:
                  self.move_direction(Direction.DOWN				,       _snake_case				)
              else:
                  return
          else:
              return




      def 		snake_case_			(      self		:       Optional[int]				,       _snake_case		:       int = 0				):
          if self.prompt:
              linebreak()
              forceWrite(self.prompt				,       '''\n'''				)
              if in_colab:
                  forceWrite('''Please input a choice index (starting from 0), and press enter'''				,       '''\n'''				)
              else:
                  forceWrite('''Please select a choice using the arrow or number keys, and selecting with enter'''				,       '''\n'''				)
          __lowercase		:			Any	    =       default_choice
          for i in range(len(self.choices				)				):
              self.print_choice(_snake_case				)
              forceWrite('''\n'''				)
          move_cursor(len(self.choices				) - self.position				,       '''UP'''				)
          with cursor.hide():
              while True:
                  if in_colab:
                      try:
                          __lowercase		:			Tuple	    =       int(builtins.input()				)
                      except ValueError:
                          __lowercase		:			int	    =       default_choice
                  else:
                      __lowercase		:			int	    =       self.handle_input()
                  if choice is not None:
                      reset_cursor()
                      for _ in range(len(self.choices				) + 1				):
                          move_cursor(1				,       '''UP'''				)
                          clear_line()
                      self.write_choice(_snake_case				,       '''\n'''				)
                      return choice


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 						__lowerCAmelCase	(	datasets.BuilderConfig      ):



      """simple docstring"""







      A__	:			Optional[datasets.Features]        =    None






class 						__lowerCAmelCase	(	datasets.ArrowBasedBuilder      ):



      """simple docstring"""







      A__	:			List[str]        =    PandasConfig




      def 		snake_case_			(      self		:       int				):
          return datasets.DatasetInfo(features=self.config.features				)




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




      def 		snake_case_			(      self		:       Optional[int]				,       _snake_case		:       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
              __lowercase		:			List[str]	    =       table_cast(_snake_case				,       self.config.features.arrow_schema				)
          return pa_table




      def 		snake_case_			(      self		:       int				,       _snake_case		:       Union[str, Any]				):
          for i, file in enumerate(itertools.chain.from_iterable(_snake_case				)				):
              with open(_snake_case				,       '''rb'''				) as f:
                  __lowercase		:			Dict	    =       pa.Table.from_pandas(pd.read_pickle(_snake_case				)				)
                  yield i, self._cast_table(_snake_case				)


