



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 							a_  (		TensorFormatter[Mapping, np.ndarray, Mapping]				):

						def __init__(    self	:Optional[Any]   ,						_lowercase	:str=None   ,						**_lowercase	:Optional[Any])		->					Optional[Any]:
												super().__init__(features=_lowercase)
												UpperCAmelCase_     							=     np_array_kwargs

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

						def 	__a       (    self	:int   ,						_lowercase	:Optional[int])		->					Any:
												if isinstance(_lowercase   ,						(str, bytes, type(_lowercase))):
																		return value
												elif isinstance(_lowercase   ,						(np.character, np.ndarray)) and np.issubdtype(value.dtype   ,						np.character):
																		return value
												elif isinstance(_lowercase   ,						np.number):
																		return value

												UpperCAmelCase_     							=     {}

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

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

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

						def 	__a       (    self	:Dict   ,						_lowercase	:Union[str, Any])		->					Optional[int]:
												# support for torch, tf, jax etc.
												if config.TORCH_AVAILABLE and "torch" in sys.modules:
																		import torch

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

						def 	__a       (    self	:Tuple   ,						_lowercase	:dict)		->					str:
												return map_nested(self._recursive_tensorize   ,						_lowercase   ,						map_list=_lowercase)

						def 	__a       (    self	:Optional[Any]   ,						_lowercase	:pa.Table)		->					Mapping:
												UpperCAmelCase_     							=     self.numpy_arrow_extractor().extract_row(_lowercase)
												UpperCAmelCase_     							=     self.python_features_decoder.decode_row(_lowercase)
												return self.recursive_tensorize(_lowercase)

						def 	__a       (    self	:Optional[Any]   ,						_lowercase	:pa.Table)		->					np.ndarray:
												UpperCAmelCase_     							=     self.numpy_arrow_extractor().extract_column(_lowercase)
												UpperCAmelCase_     							=     self.python_features_decoder.decode_column(_lowercase   ,						pa_table.column_names[0])
												UpperCAmelCase_     							=     self.recursive_tensorize(_lowercase)
												UpperCAmelCase_     							=     self._consolidate(_lowercase)
												return column




						def 	__a       (    self	:Optional[int]   ,						_lowercase	:pa.Table)		->					Mapping:
												UpperCAmelCase_     							=     self.numpy_arrow_extractor().extract_batch(_lowercase)
												UpperCAmelCase_     							=     self.python_features_decoder.decode_batch(_lowercase)
												UpperCAmelCase_     							=     self.recursive_tensorize(_lowercase)
												for column_name in batch:
																		UpperCAmelCase_     							=     self._consolidate(batch[column_name])
												return batch










def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 9 / 5) + 32							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) + 273.15							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 9 / 5) + 491.67							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) - 32) * 5 / 9							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(((float(__UpperCAmelCase	) - 32) * 5 / 9) + 273.15							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) + 459.67							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) - 273.15							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(((float(__UpperCAmelCase	) - 273.15) * 9 / 5) + 32							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 9 / 5)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) - 491.67) * 5 / 9							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) - 459.67							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 5 / 9)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 1.25 + 273.15)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 2.25 + 32)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 1.25)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 2.25 + 32 + 459.67)							,					__UpperCAmelCase	)


if __name__ == "__main__":
							import doctest

							doctest.testmod()





