




import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter





class  lowerCamelCase_							(   TensorFormatter[Mapping, np.ndarray, Mapping]      ):


 '''simple docstring'''







 def __init__(							self						:	List[Any]       ,       _lowerCAmelCase						:	Union[str, Any]=None       ,       **_lowerCAmelCase						:	str		):
       super().__init__(features=_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_					=    np_array_kwargs



 def    lowerCAmelCase_						(							self						:	List[str]       ,       _lowerCAmelCase						:	Any		):
       if isinstance(_lowerCAmelCase       ,       _lowerCAmelCase		):
             if column and all(
                 isinstance(_lowerCAmelCase       ,       np.ndarray		) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column		):
                   return np.stack(_lowerCAmelCase		)
             else:
                   # don't use np.array(column, dtype=object)
                   # since it fails in certain cases
                   # see https://stackoverflow.com/q/51005699
                   SCREAMING_SNAKE_CASE_					=    np.empty(len(_lowerCAmelCase		)       ,       dtype=_lowerCAmelCase		)
                   SCREAMING_SNAKE_CASE_					=    column
                   return out
       return column



 def    lowerCAmelCase_						(							self						:	int       ,       _lowerCAmelCase						:	Dict		):
       if isinstance(_lowerCAmelCase       ,       (str, bytes, type(_lowerCAmelCase		))		):
             return value
       elif isinstance(_lowerCAmelCase       ,       (np.character, np.ndarray)		) and np.issubdtype(value.dtype       ,       np.character		):
             return value
       elif isinstance(_lowerCAmelCase       ,       np.number		):
             return value

       SCREAMING_SNAKE_CASE_					=    {}

       if isinstance(_lowerCAmelCase       ,       np.ndarray		) and np.issubdtype(value.dtype       ,       np.integer		):
             SCREAMING_SNAKE_CASE_					=    {'dtype': np.intaa}
       elif isinstance(_lowerCAmelCase       ,       np.ndarray		) and np.issubdtype(value.dtype       ,       np.floating		):
             SCREAMING_SNAKE_CASE_					=    {'dtype': np.floataa}
       elif config.PIL_AVAILABLE and "PIL" in sys.modules:
             import PIL.Image

             if isinstance(_lowerCAmelCase       ,       PIL.Image.Image		):
                   return np.asarray(_lowerCAmelCase       ,       **self.np_array_kwargs		)

       return np.asarray(_lowerCAmelCase       ,       **{**default_dtype, **self.np_array_kwargs}		)



 def    lowerCAmelCase_						(							self						:	str       ,       _lowerCAmelCase						:	Dict		):
       # support for torch, tf, jax etc.
       if config.TORCH_AVAILABLE and "torch" in sys.modules:
             import torch

             if isinstance(_lowerCAmelCase       ,       torch.Tensor		):
                   return self._tensorize(data_struct.detach().cpu().numpy()[()]		)
       if hasattr(_lowerCAmelCase       ,       '__array__'		) and not isinstance(_lowerCAmelCase       ,       (np.ndarray, np.character, np.number)		):
             SCREAMING_SNAKE_CASE_					=    data_struct.__array__()
       # support for nested types like struct of list of struct
       if isinstance(_lowerCAmelCase       ,       np.ndarray		):
             if data_struct.dtype == object:
                   return self._consolidate([self.recursive_tensorize(_lowerCAmelCase		) for substruct in data_struct]		)
       if isinstance(_lowerCAmelCase       ,       (list, tuple)		):
             return self._consolidate([self.recursive_tensorize(_lowerCAmelCase		) for substruct in data_struct]		)
       return self._tensorize(_lowerCAmelCase		)



 def    lowerCAmelCase_						(							self						:	Any       ,       _lowerCAmelCase						:	dict		):
       return map_nested(self._recursive_tensorize       ,       _lowerCAmelCase       ,       map_list=_lowerCAmelCase		)



 def    lowerCAmelCase_						(							self						:	Optional[Any]       ,       _lowerCAmelCase						:	pa.Table		):
       SCREAMING_SNAKE_CASE_					=    self.numpy_arrow_extractor().extract_row(_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_					=    self.python_features_decoder.decode_row(_lowerCAmelCase		)
       return self.recursive_tensorize(_lowerCAmelCase		)



 def    lowerCAmelCase_						(							self						:	List[str]       ,       _lowerCAmelCase						:	pa.Table		):
       SCREAMING_SNAKE_CASE_					=    self.numpy_arrow_extractor().extract_column(_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_					=    self.python_features_decoder.decode_column(_lowerCAmelCase       ,       pa_table.column_names[0]		)
       SCREAMING_SNAKE_CASE_					=    self.recursive_tensorize(_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_					=    self._consolidate(_lowerCAmelCase		)
       return column




 def    lowerCAmelCase_						(							self						:	Optional[int]       ,       _lowerCAmelCase						:	pa.Table		):
       SCREAMING_SNAKE_CASE_					=    self.numpy_arrow_extractor().extract_batch(_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_					=    self.python_features_decoder.decode_batch(_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_					=    self.recursive_tensorize(_lowerCAmelCase		)
       for column_name in batch:
             SCREAMING_SNAKE_CASE_					=    self._consolidate(batch[column_name]		)
       return batch





def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round((float(__UpperCAmelCase							) * 9 / 5) + 32    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round(float(__UpperCAmelCase							) + 2_7_3.1_5    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round((float(__UpperCAmelCase							) * 9 / 5) + 4_9_1.6_7    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round((float(__UpperCAmelCase							) - 32) * 5 / 9    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round(((float(__UpperCAmelCase							) - 32) * 5 / 9) + 2_7_3.1_5    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round(float(__UpperCAmelCase							) + 4_5_9.6_7    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round(float(__UpperCAmelCase							) - 2_7_3.1_5    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round(((float(__UpperCAmelCase							) - 2_7_3.1_5) * 9 / 5) + 32    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round((float(__UpperCAmelCase							) * 9 / 5)    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round((float(__UpperCAmelCase							) - 4_9_1.6_7) * 5 / 9    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round(float(__UpperCAmelCase							) - 4_5_9.6_7    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round((float(__UpperCAmelCase							) * 5 / 9)    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round((float(__UpperCAmelCase							) * 1.2_5 + 2_7_3.1_5)    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round((float(__UpperCAmelCase							) * 2.2_5 + 32)    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round((float(__UpperCAmelCase							) * 1.2_5)    ,    __UpperCAmelCase							)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			float    ,    __UpperCAmelCase		:			int = 2							)      ->				float:
      return round((float(__UpperCAmelCase							) * 2.2_5 + 32 + 4_5_9.6_7)    ,    __UpperCAmelCase							)


if __name__ == "__main__":
   import doctest

   doctest.testmod()