




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

					def __init__(							self					,			__lowercase=None					,			**__lowercase   ):







						'''simple docstring'''




						super().__init__(features=__lowercase   )
						lowerCamelCase_				:						Dict				  =				np_array_kwargs

					def       lowercase_				(							self					,			__lowercase   ):







						'''simple docstring'''




						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
								lowerCamelCase_				:						List[Any]				  =				np.empty(len(__lowercase   )					,			dtype=__lowercase   )
								lowerCamelCase_				:						str				  =				column
								return out
						return column

					def       lowercase_				(							self					,			__lowercase   ):







						'''simple docstring'''




						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

						lowerCamelCase_				:						int				  =				{}

						if isinstance(__lowercase					,			np.ndarray   ) and np.issubdtype(value.dtype					,			np.integer   ):
							lowerCamelCase_				:						Optional[Any]				  =				{'dtype': np.intaa}
						elif isinstance(__lowercase					,			np.ndarray   ) and np.issubdtype(value.dtype					,			np.floating   ):
							lowerCamelCase_				:						Any				  =				{'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       lowercase_				(							self					,			__lowercase   ):







						'''simple docstring'''




						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)   ):
							lowerCamelCase_				:						Optional[Any]				  =				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       lowercase_				(							self					,			__lowercase   ):







						'''simple docstring'''




						return map_nested(self._recursive_tensorize					,			__lowercase					,			map_list=__lowercase   )

					def       lowercase_				(							self					,			__lowercase   ):







						'''simple docstring'''




						lowerCamelCase_				:						Tuple				  =				self.numpy_arrow_extractor().extract_row(__lowercase   )
						lowerCamelCase_				:						int				  =				self.python_features_decoder.decode_row(__lowercase   )
						return self.recursive_tensorize(__lowercase   )

					def       lowercase_				(							self					,			__lowercase   ):







						'''simple docstring'''




						lowerCamelCase_				:						Optional[Any]				  =				self.numpy_arrow_extractor().extract_column(__lowercase   )
						lowerCamelCase_				:						int				  =				self.python_features_decoder.decode_column(__lowercase					,			pa_table.column_names[0]   )
						lowerCamelCase_				:						int				  =				self.recursive_tensorize(__lowercase   )
						lowerCamelCase_				:						List[Any]				  =				self._consolidate(__lowercase   )
						return column





					def       lowercase_				(							self					,			__lowercase   ):







						'''simple docstring'''




						lowerCamelCase_				:						int				  =				self.numpy_arrow_extractor().extract_batch(__lowercase   )
						lowerCamelCase_				:						int				  =				self.python_features_decoder.decode_batch(__lowercase   )
						lowerCamelCase_				:						List[str]				  =				self.recursive_tensorize(__lowercase   )
						for column_name in batch:
							lowerCamelCase_				:						int				  =				self._consolidate(batch[column_name]   )
						return batch

"""simple docstring"""

import json

import requests

from .fetch_github_info import AUTHENTICATED_USER_ENDPOINT, fetch_github_info


def    lowerCAmelCase			(__UpperCamelCase							:    Optional[Any]			):
							"""simple docstring"""


							class 		_lowercase :



													"""simple docstring"""




													def __init__(				self							:    int     , UpperCamelCase__							:    Union[str, Any]				)				->				None:
																				'''simple docstring'''



																				assert isinstance(UpperCamelCase__     , (bytes, str)				)
																				__UpperCamelCase							=content





													def   UpperCAmelCase_ (				self							:    Dict				)				->				Any:
																				'''simple docstring'''



																				return json.loads(self.content				)

							def mock_response(*__UpperCamelCase							:    Any							,					**__UpperCamelCase							:    Union[str, Any]			):
														assert args[0] == AUTHENTICATED_USER_ENDPOINT
														assert "Authorization" in kwargs["headers"]
														assert kwargs["headers"]["Authorization"].startswith('''token '''			)
														assert "Accept" in kwargs["headers"]
														return FakeResponse(b'''{"login":"test","id":1}'''			)

							monkeypatch.setattr(__UpperCamelCase							,					'''get'''							,					__UpperCamelCase			)
							__UpperCamelCase							=fetch_github_info('''token'''			)
							assert result["login"] == "test"
							assert result["id"] == 1



