






import itertools
from dataclasses import dataclass
from typing import Optional

import pyarrow as pa

import datasets
from datasets.table import table_cast


UpperCAmelCase__            =	datasets.utils.logging.get_logger(__name__)






@dataclass
class 	lowercase_      (			datasets.BuilderConfig     ):






      '''simple docstring'''




      __snake_case  						=						None






class 	lowercase_      (			datasets.ArrowBasedBuilder     ):






      '''simple docstring'''




      __snake_case  						=						ArrowConfig







      def    __lowerCAmelCase      (   self   :		Optional[int]						)					->Optional[int]:




       """simple docstring"""


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







      def    __lowerCAmelCase      (   self   :		List[Any]				,      __UpperCAmelCase   :		Dict						)					->Any:




       """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							=   dl_manager.download_and_extract(self.config.data_files						)
       if isinstance(__UpperCAmelCase				,      (str, list, tuple)						):
        a							=   data_files
        if isinstance(__UpperCAmelCase				,      __UpperCAmelCase						):
         a							=   [files]
        # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
        a							=   [dl_manager.iter_files(__UpperCAmelCase						) for file in files]
        return [datasets.SplitGenerator(name=datasets.Split.TRAIN				,      gen_kwargs={'''files''': files}						)]
       a							=   []
       for split_name, files in data_files.items():
        if isinstance(__UpperCAmelCase				,      __UpperCAmelCase						):
         a							=   [files]
        # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
        a							=   [dl_manager.iter_files(__UpperCAmelCase						) for file in files]
        # Infer features is they are stoed in the arrow schema
        if self.info.features is None:
         for file in itertools.chain.from_iterable(__UpperCAmelCase						):
          with open(__UpperCAmelCase				,      '''rb'''						) as f:
           a							=   datasets.Features.from_arrow_schema(pa.ipc.open_stream(__UpperCAmelCase						).schema						)
          break
        splits.append(datasets.SplitGenerator(name=__UpperCAmelCase				,      gen_kwargs={'''files''': files}						)						)
       return splits







      def    __lowerCAmelCase      (   self   :		Optional[int]				,      __UpperCAmelCase   :		pa.Table						)					->pa.Table:




       """simple docstring"""


       if self.info.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							=   table_cast(__UpperCAmelCase				,      self.info.features.arrow_schema						)
       return pa_table







      def    __lowerCAmelCase      (   self   :		int				,      __UpperCAmelCase   :		Dict						)					->List[str]:




       """simple docstring"""


       for file_idx, file in enumerate(itertools.chain.from_iterable(__UpperCAmelCase						)						):
        with open(__UpperCAmelCase				,      '''rb'''						) as f:
         try:
          for batch_idx, record_batch in enumerate(pa.ipc.open_stream(__UpperCAmelCase						)						):
           a							=   pa.Table.from_batches([record_batch]						)
           # Uncomment for debugging (will print the Arrow table size and elements)
           # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
           # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
           yield F"""{file_idx}_{batch_idx}""", self._cast_table(__UpperCAmelCase						)
         except ValueError as e:
          logger.error(F"""Failed to read file '{file}' with error {type(__UpperCAmelCase						)}: {e}"""						)
          raise










from collections import namedtuple

UpperCAmelCase__            =	namedtuple("from_to", "from_ to")

UpperCAmelCase__            =	{
    "atm": from_to(1, 1),
    "pascal": from_to(0.000_0098, 101325),
    "bar": from_to(0.98_6923, 1.0_1325),
    "kilopascal": from_to(0.0098_6923, 101.325),
    "megapascal": from_to(9.8_6923, 0.10_1325),
    "psi": from_to(0.06_8046, 14.6959),
    "inHg": from_to(0.033_4211, 29.9213),
    "torr": from_to(0.0013_1579, 760),
}
def 		_a					(   a				:float			,							a				:str			,							a				:str				)							->    float:
 if from_type not in PRESSURE_CONVERSION:
  raise ValueError(
      F"""Invalid 'from_type' value: {from_type!r}  Supported values are:\n"""
      + ''', '''.join(a				)				)
 if to_type not in PRESSURE_CONVERSION:
  raise ValueError(
      F"""Invalid 'to_type' value: {to_type!r}.  Supported values are:\n"""
      + ''', '''.join(a				)				)
 return (
     value * PRESSURE_CONVERSION[from_type].from_ * PRESSURE_CONVERSION[to_type].to
 )


if __name__ == "__main__":
     import doctest

     doctest.testmod()


