





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] ):





					"""simple docstring"""


					def __init__(			self						,	_lowerCAmelCase=None						,	**_lowerCAmelCase						):
										super().__init__(features=_lowerCAmelCase						)
										lowerCamelCase__      =							np_array_kwargs





					def        __magic_name__			(			self						,	_lowerCAmelCase						):
										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
																				lowerCamelCase__      =							np.empty(len(_lowerCAmelCase						)						,	dtype=_lowerCAmelCase						)
																				lowerCamelCase__      =							column
																				return out
										return column





					def        __magic_name__			(			self						,	_lowerCAmelCase						):
										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

										lowerCamelCase__      =							{}

										if isinstance(_lowerCAmelCase						,	np.ndarray						) and np.issubdtype(value.dtype						,	np.integer						):
															lowerCamelCase__      =							{"dtype": np.intaa}
										elif isinstance(_lowerCAmelCase						,	np.ndarray						) and np.issubdtype(value.dtype						,	np.floating						):
															lowerCamelCase__      =							{"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        __magic_name__			(			self						,	_lowerCAmelCase						):
										# 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)						):
															lowerCamelCase__      =							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        __magic_name__			(			self						,	_lowerCAmelCase						):
										return map_nested(self._recursive_tensorize						,	_lowerCAmelCase						,	map_list=_lowerCAmelCase						)





					def        __magic_name__			(			self						,	_lowerCAmelCase						):
										lowerCamelCase__      =							self.numpy_arrow_extractor().extract_row(_lowerCAmelCase						)
										lowerCamelCase__      =							self.python_features_decoder.decode_row(_lowerCAmelCase						)
										return self.recursive_tensorize(_lowerCAmelCase						)





					def        __magic_name__			(			self						,	_lowerCAmelCase						):
										lowerCamelCase__      =							self.numpy_arrow_extractor().extract_column(_lowerCAmelCase						)
										lowerCamelCase__      =							self.python_features_decoder.decode_column(_lowerCAmelCase						,	pa_table.column_names[0]						)
										lowerCamelCase__      =							self.recursive_tensorize(_lowerCAmelCase						)
										lowerCamelCase__      =							self._consolidate(_lowerCAmelCase						)
										return column






					def        __magic_name__			(			self						,	_lowerCAmelCase						):
										lowerCamelCase__      =							self.numpy_arrow_extractor().extract_batch(_lowerCAmelCase						)
										lowerCamelCase__      =							self.python_features_decoder.decode_batch(_lowerCAmelCase						)
										lowerCamelCase__      =							self.recursive_tensorize(_lowerCAmelCase						)
										for column_name in batch:
															lowerCamelCase__      =							self._consolidate(batch[column_name]						)
										return batch








import enum
import inspect
import warnings
from functools import wraps
from typing import Callable, Optional

from .logging import get_logger


A_        =  set()
A_        =  get_logger(__name__)





def  __UpperCamelCase   (     a = None)			->str:

					def decorator(a):
										global _emitted_deprecation_warnings

										if inspect.isclass(a):
															lowerCamelCase__      =							deprecated_class_or_function.__init__
															lowerCamelCase__      =							deprecated_class_or_function.__name__
										else:
															lowerCamelCase__      =							deprecated_class_or_function
															lowerCamelCase__      =							deprecated_function.__name__
															# Support deprecating __init__ class method: class name instead
															lowerCamelCase__      =							name if name != "__init__" else deprecated_function.__qualname__.split(".")[-2]

										lowerCamelCase__      =							(
										    f"{name} is deprecated and will be removed in the next major version of datasets." + f" {help_message}"
										    if help_message
										    else ""
										)

										@wraps(a)
										def wrapper(*a,  **a):
															lowerCamelCase__      =							hash(a)
															if func_hash not in _emitted_deprecation_warnings:
																				warnings.warn(a,  category=a,  stacklevel=2)
																				_emitted_deprecation_warnings.add(a)
															return deprecated_function(*a,  **a)

										lowerCamelCase__      =							"deprecated"

										if inspect.isclass(a):
															lowerCamelCase__      =							wrapper
															return deprecated_class_or_function
										else:
															return wrapper

					return decorator

class SCREAMING_SNAKE_CASE_			(       enum.EnumMeta ):





					"""simple docstring"""


					def __getattribute__(			cls						,	_lowerCAmelCase						):
										lowerCamelCase__      =							super().__getattribute__(_lowerCAmelCase						)
										if isinstance(_lowerCAmelCase						,	enum.Enum						) and obj._on_access:
															obj._on_access()
										return obj





					def __getitem__(			cls						,	_lowerCAmelCase						):
										lowerCamelCase__      =							super().__getitem__(_lowerCAmelCase						)
										if member._on_access:
															member._on_access()
										return member






					def __call__(			cls						,	_lowerCAmelCase						,	_lowerCAmelCase=None						,	*, _lowerCAmelCase=None						,	_lowerCAmelCase=None						,	_lowerCAmelCase=None						,	_lowerCAmelCase=1						):
										lowerCamelCase__      =							super().__call__(_lowerCAmelCase						,	_lowerCAmelCase						,	module=_lowerCAmelCase						,	qualname=_lowerCAmelCase						,	type=_lowerCAmelCase						,	start=_lowerCAmelCase						)
										if isinstance(_lowerCAmelCase						,	enum.Enum						) and obj._on_access:
															obj._on_access()
										return obj

class SCREAMING_SNAKE_CASE_			(       enum.Enum				,							metaclass=lowercase_ ):





					"""simple docstring"""


					def __new__(			cls						,	_lowerCAmelCase						):
										lowerCamelCase__      =							object.__new__(cls						)
										lowerCamelCase__      =							value
										lowerCamelCase__      =							member.deprecate
										return member





					@property
					def        __magic_name__			(			self						):
										return ""






					def        __magic_name__			(			self						):
										lowerCamelCase__      =							F" {self.help_message}" if self.help_message else ""
										warnings.warn(
										    F"'{self.__objclass__.__name__}' is deprecated and will be removed in the next major version of datasets."
										    + help_message						,	_lowerCAmelCase						,	stacklevel=3						,	)

