






from typing import Optional

import torch
import torch.utils.checkpoint
from torch import Tensor, nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import (
    BackboneOutput,
    BaseModelOutputWithNoAttention,
    BaseModelOutputWithPoolingAndNoAttention,
    ImageClassifierOutputWithNoAttention,
)
from ...modeling_utils import PreTrainedModel
from ...utils import (
    add_code_sample_docstrings,
    add_start_docstrings,
    add_start_docstrings_to_model_forward,
    logging,
    replace_return_docstrings,
)
from ...utils.backbone_utils import BackboneMixin
from .configuration_resnet import ResNetConfig


__lowerCamelCase   :					List[str]   							=					logging.get_logger(__name__)

# General docstring
__lowerCamelCase   :					List[str]   							=					'''ResNetConfig'''

# Base docstring
__lowerCamelCase   :					List[Any]   							=					'''microsoft/resnet-50'''
__lowerCamelCase   :					Union[str, Any]   							=					[1, 2048, 7, 7]

# Image classification docstring
__lowerCamelCase   :					List[str]   							=					'''microsoft/resnet-50'''
__lowerCamelCase   :					int   							=					'''tiger cat'''

__lowerCamelCase   :					Any   							=					[
    '''microsoft/resnet-50''',
    # See all resnet models at https://huggingface.co/models?filter=resnet
]







class    A_	(nn.Module							):
							"""simple docstring"""




							def __init__(		self			:Any       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:int = 3       ,							lowerCAmelCase__			:int = 1       ,							lowerCAmelCase__			:str = "relu"				)				->  Union[str, Any]:


										'''simple docstring'''




										super().__init__()
										snake_case_				:					Dict   =       nn.Convad(
										    UpperCamelCase_       ,							UpperCamelCase_       ,							kernel_size=UpperCamelCase_       ,							stride=UpperCamelCase_       ,							padding=kernel_size // 2       ,							bias=UpperCamelCase_				)
										snake_case_				:					Tuple   =       nn.BatchNormad(UpperCamelCase_				)
										snake_case_				:					List[str]   =       ACTaFN[activation] if activation is not None else nn.Identity()






							def 							_A	(		self			:Optional[Any]       ,							lowerCAmelCase__			:Tensor				)				->  Union[str, Any]:


										'''simple docstring'''




										snake_case_				:					Tuple   =       self.convolution(UpperCamelCase_				)
										snake_case_				:					Tuple   =       self.normalization(UpperCamelCase_				)
										snake_case_				:					Dict   =       self.activation(UpperCamelCase_				)
										return hidden_state







class    A_	(nn.Module							):
							"""simple docstring"""




							def __init__(		self			:Union[str, Any]       ,							lowerCAmelCase__			:ResNetConfig				)				->  Optional[int]:


										'''simple docstring'''




										super().__init__()
										snake_case_				:					Tuple   =       ResNetConvLayer(
										    config.num_channels       ,							config.embedding_size       ,							kernel_size=7       ,							stride=2       ,							activation=config.hidden_act				)
										snake_case_				:					Tuple   =       nn.MaxPoolad(kernel_size=3       ,							stride=2       ,							padding=1				)
										snake_case_				:					Union[str, Any]   =       config.num_channels






							def 							_A	(		self			:str       ,							lowerCAmelCase__			:Tensor				)				->  Dict:


										'''simple docstring'''




										snake_case_				:					Any   =       pixel_values.shape[1]
										if num_channels != self.num_channels:
													raise ValueError(
													    "Make sure that the channel dimension of the pixel values match with the one set in the configuration."				)
										snake_case_				:					Optional[int]   =       self.embedder(UpperCamelCase_				)
										snake_case_				:					int   =       self.pooler(UpperCamelCase_				)
										return embedding







class    A_	(nn.Module							):
							"""simple docstring"""




							def __init__(		self			:Tuple       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:int = 2				)				->  Optional[Any]:


										'''simple docstring'''




										super().__init__()
										snake_case_				:					str   =       nn.Convad(UpperCamelCase_       ,							UpperCamelCase_       ,							kernel_size=1       ,							stride=UpperCamelCase_       ,							bias=UpperCamelCase_				)
										snake_case_				:					str   =       nn.BatchNormad(UpperCamelCase_				)






							def 							_A	(		self			:int       ,							lowerCAmelCase__			:Tensor				)				->  Any:


										'''simple docstring'''




										snake_case_				:					Tuple   =       self.convolution(UpperCamelCase_				)
										snake_case_				:					Optional[Any]   =       self.normalization(UpperCamelCase_				)
										return hidden_state







class    A_	(nn.Module							):
							"""simple docstring"""




							def __init__(		self			:Optional[Any]       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:int = 1       ,							lowerCAmelCase__			:str = "relu"				)				->  Any:


										'''simple docstring'''




										super().__init__()
										snake_case_				:					Optional[Any]   =       in_channels != out_channels or stride != 1
										snake_case_				:					List[str]   =       (
										    ResNetShortCut(UpperCamelCase_       ,							UpperCamelCase_       ,							stride=UpperCamelCase_				) if should_apply_shortcut else nn.Identity()
										)
										snake_case_				:					Optional[Any]   =       nn.Sequential(
										    ResNetConvLayer(UpperCamelCase_       ,							UpperCamelCase_       ,							stride=UpperCamelCase_				)       ,							ResNetConvLayer(UpperCamelCase_       ,							UpperCamelCase_       ,							activation=UpperCamelCase_				)       ,							)
										snake_case_				:					Any   =       ACTaFN[activation]






							def 							_A	(		self			:str       ,							lowerCAmelCase__			:Tuple				)				->  int:


										'''simple docstring'''




										snake_case_				:					Union[str, Any]   =       hidden_state
										snake_case_				:					str   =       self.layer(UpperCamelCase_				)
										snake_case_				:					Dict   =       self.shortcut(UpperCamelCase_				)
										hidden_state += residual
										snake_case_				:					List[str]   =       self.activation(UpperCamelCase_				)
										return hidden_state







class    A_	(nn.Module							):
							"""simple docstring"""




							def __init__(		self			:Optional[Any]       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:int = 1       ,							lowerCAmelCase__			:str = "relu"       ,							lowerCAmelCase__			:int = 4				)				->  Optional[Any]:


										'''simple docstring'''




										super().__init__()
										snake_case_				:					Optional[int]   =       in_channels != out_channels or stride != 1
										snake_case_				:					Optional[Any]   =       out_channels // reduction
										snake_case_				:					str   =       (
										    ResNetShortCut(UpperCamelCase_       ,							UpperCamelCase_       ,							stride=UpperCamelCase_				) if should_apply_shortcut else nn.Identity()
										)
										snake_case_				:					List[Any]   =       nn.Sequential(
										    ResNetConvLayer(UpperCamelCase_       ,							UpperCamelCase_       ,							kernel_size=1				)       ,							ResNetConvLayer(UpperCamelCase_       ,							UpperCamelCase_       ,							stride=UpperCamelCase_				)       ,							ResNetConvLayer(UpperCamelCase_       ,							UpperCamelCase_       ,							kernel_size=1       ,							activation=UpperCamelCase_				)       ,							)
										snake_case_				:					List[str]   =       ACTaFN[activation]






							def 							_A	(		self			:int       ,							lowerCAmelCase__			:List[str]				)				->  int:


										'''simple docstring'''




										snake_case_				:					Tuple   =       hidden_state
										snake_case_				:					Optional[int]   =       self.layer(UpperCamelCase_				)
										snake_case_				:					Tuple   =       self.shortcut(UpperCamelCase_				)
										hidden_state += residual
										snake_case_				:					str   =       self.activation(UpperCamelCase_				)
										return hidden_state







class    A_	(nn.Module							):
							"""simple docstring"""




							def __init__(		self			:Union[str, Any]       ,							lowerCAmelCase__			:ResNetConfig       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:int = 2       ,							lowerCAmelCase__			:int = 2       ,							)				->  Union[str, Any]:


										'''simple docstring'''




										super().__init__()

										snake_case_				:					Any   =       ResNetBottleNeckLayer if config.layer_type == "bottleneck" else ResNetBasicLayer

										snake_case_				:					List[Any]   =       nn.Sequential(
										    # downsampling is done in the first layer with stride of 2
										    layer(UpperCamelCase_       ,							UpperCamelCase_       ,							stride=UpperCamelCase_       ,							activation=config.hidden_act				)       ,							*[layer(UpperCamelCase_       ,							UpperCamelCase_       ,							activation=config.hidden_act				) for _ in range(depth - 1				)]       ,							)






							def 							_A	(		self			:Any       ,							lowerCAmelCase__			:Tensor				)				->  int:


										'''simple docstring'''




										snake_case_				:					Union[str, Any]   =       input
										for layer in self.layers:
													snake_case_				:					List[Any]   =       layer(UpperCamelCase_				)
										return hidden_state







class    A_	(nn.Module							):
							"""simple docstring"""




							def __init__(		self			:Any       ,							lowerCAmelCase__			:ResNetConfig				)				->  List[str]:


										'''simple docstring'''




										super().__init__()
										snake_case_				:					Any   =       nn.ModuleList([]				)
										# based on `downsample_in_first_stage` the first layer of the first stage may or may not downsample the input
										self.stages.append(
										    ResNetStage(
										        UpperCamelCase_       ,							config.embedding_size       ,							config.hidden_sizes[0]       ,							stride=2 if config.downsample_in_first_stage else 1       ,							depth=config.depths[0]       ,							)				)
										snake_case_				:					str   =       zip(config.hidden_sizes       ,							config.hidden_sizes[1:]				)
										for (in_channels, out_channels), depth in zip(UpperCamelCase_       ,							config.depths[1:]				):
													self.stages.append(ResNetStage(UpperCamelCase_       ,							UpperCamelCase_       ,							UpperCamelCase_       ,							depth=UpperCamelCase_				)				)






							def 							_A	(		self			:Tuple       ,							lowerCAmelCase__			:Tensor       ,							lowerCAmelCase__			:bool = False       ,							lowerCAmelCase__			:bool = True				)				->  str:


										'''simple docstring'''




										snake_case_				:					Optional[Any]   =       () if output_hidden_states else None

										for stage_module in self.stages:
													if output_hidden_states:
																snake_case_				:					Any   =       hidden_states + (hidden_state,)

													snake_case_				:					Any   =       stage_module(UpperCamelCase_				)

										if output_hidden_states:
													snake_case_				:					Any   =       hidden_states + (hidden_state,)

										if not return_dict:
													return tuple(v for v in [hidden_state, hidden_states] if v is not None				)

										return BaseModelOutputWithNoAttention(
										    last_hidden_state=UpperCamelCase_       ,							hidden_states=UpperCamelCase_       ,							)







class    A_	(__lowerCamelCase							):
							"""simple docstring"""




							a__   		=	ResNetConfig
							a__   		=	'resnet'
							a__   		=	'pixel_values'
							a__   		=	True

							def 							_A	(		self			:List[str]       ,							lowerCAmelCase__			:Any				)				->  List[str]:


										'''simple docstring'''




										if isinstance(UpperCamelCase_       ,							nn.Convad				):
													nn.init.kaiming_normal_(module.weight       ,							mode="fan_out"       ,							nonlinearity="relu"				)
										elif isinstance(UpperCamelCase_       ,							(nn.BatchNormad, nn.GroupNorm)				):
													nn.init.constant_(module.weight       ,							1				)
													nn.init.constant_(module.bias       ,							0				)






							def 							_A	(		self			:Union[str, Any]       ,							lowerCAmelCase__			:Tuple       ,							lowerCAmelCase__			:List[str]=False				)				->  str:


										'''simple docstring'''




										if isinstance(UpperCamelCase_       ,							UpperCamelCase_				):
													snake_case_				:					List[str]   =       value
__lowerCamelCase   :					Dict   							=					R'''\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it\n    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`ResNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n'''

__lowerCamelCase   :					str   							=					R'''\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConvNextImageProcessor.__call__`] for details.\n\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'''







@add_start_docstrings(
    '''The bare ResNet model outputting raw features without any specific head on top.'''						,					__lowerCamelCase						,					)
class    A_	(__lowerCamelCase							):
							"""simple docstring"""




							def __init__(		self			:int       ,							lowerCAmelCase__			:Optional[Any]				)				->  List[str]:


										'''simple docstring'''




										super().__init__(UpperCamelCase_				)
										snake_case_				:					str   =       config
										snake_case_				:					Optional[int]   =       ResNetEmbeddings(UpperCamelCase_				)
										snake_case_				:					List[Any]   =       ResNetEncoder(UpperCamelCase_				)
										snake_case_				:					List[str]   =       nn.AdaptiveAvgPoolad((1, 1)				)
										# Initialize weights and apply final processing
										self.post_init()






							@add_start_docstrings_to_model_forward(UpperCamelCase_				)
							@add_code_sample_docstrings(
							    checkpoint=_CHECKPOINT_FOR_DOC       ,							output_type=UpperCamelCase_       ,							config_class=_CONFIG_FOR_DOC       ,							modality="vision"       ,							expected_output=_EXPECTED_OUTPUT_SHAPE       ,							)
							def 							_A	(		self			:Dict       ,							lowerCAmelCase__			:Tensor       ,							lowerCAmelCase__			:Optional[bool] = None       ,							lowerCAmelCase__			:Optional[bool] = None				)				->  Dict:


										'''simple docstring'''




										snake_case_				:					str   =       (
										    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
										)
										snake_case_				:					Dict   =       return_dict if return_dict is not None else self.config.use_return_dict

										snake_case_				:					str   =       self.embedder(UpperCamelCase_				)

										snake_case_				:					int   =       self.encoder(
										    UpperCamelCase_       ,							output_hidden_states=UpperCamelCase_       ,							return_dict=UpperCamelCase_				)

										snake_case_				:					str   =       encoder_outputs[0]

										snake_case_				:					Optional[int]   =       self.pooler(UpperCamelCase_				)

										if not return_dict:
													return (last_hidden_state, pooled_output) + encoder_outputs[1:]

										return BaseModelOutputWithPoolingAndNoAttention(
										    last_hidden_state=UpperCamelCase_       ,							pooler_output=UpperCamelCase_       ,							hidden_states=encoder_outputs.hidden_states       ,							)







@add_start_docstrings(
    '''\n    ResNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    '''						,					__lowerCamelCase						,					)
class    A_	(__lowerCamelCase							):
							"""simple docstring"""




							def __init__(		self			:str       ,							lowerCAmelCase__			:int				)				->  List[Any]:


										'''simple docstring'''




										super().__init__(UpperCamelCase_				)
										snake_case_				:					int   =       config.num_labels
										snake_case_				:					Tuple   =       ResNetModel(UpperCamelCase_				)
										# classification head
										snake_case_				:					Any   =       nn.Sequential(
										    nn.Flatten()       ,							nn.Linear(config.hidden_sizes[-1]       ,							config.num_labels				) if config.num_labels > 0 else nn.Identity()       ,							)
										# initialize weights and apply final processing
										self.post_init()






							@add_start_docstrings_to_model_forward(UpperCamelCase_				)
							@add_code_sample_docstrings(
							    checkpoint=_IMAGE_CLASS_CHECKPOINT       ,							output_type=UpperCamelCase_       ,							config_class=_CONFIG_FOR_DOC       ,							expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT       ,							)
							def 							_A	(		self			:Optional[Any]       ,							lowerCAmelCase__			:Optional[torch.FloatTensor] = None       ,							lowerCAmelCase__			:Optional[torch.LongTensor] = None       ,							lowerCAmelCase__			:Optional[bool] = None       ,							lowerCAmelCase__			:Optional[bool] = None       ,							)				->  int:


										'''simple docstring'''




										snake_case_				:					Union[str, Any]   =       return_dict if return_dict is not None else self.config.use_return_dict

										snake_case_				:					Optional[Any]   =       self.resnet(UpperCamelCase_       ,							output_hidden_states=UpperCamelCase_       ,							return_dict=UpperCamelCase_				)

										snake_case_				:					Optional[Any]   =       outputs.pooler_output if return_dict else outputs[1]

										snake_case_				:					Any   =       self.classifier(UpperCamelCase_				)

										snake_case_				:					Optional[int]   =       None

										if labels is not None:
													if self.config.problem_type is None:
																if self.num_labels == 1:
																			snake_case_				:					Optional[int]   =       "regression"
																elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
																			snake_case_				:					int   =       "single_label_classification"
																else:
																			snake_case_				:					Union[str, Any]   =       "multi_label_classification"
													if self.config.problem_type == "regression":
																snake_case_				:					Tuple   =       MSELoss()
																if self.num_labels == 1:
																			snake_case_				:					List[Any]   =       loss_fct(logits.squeeze()       ,							labels.squeeze()				)
																else:
																			snake_case_				:					Dict   =       loss_fct(UpperCamelCase_       ,							UpperCamelCase_				)
													elif self.config.problem_type == "single_label_classification":
																snake_case_				:					Optional[Any]   =       CrossEntropyLoss()
																snake_case_				:					Optional[int]   =       loss_fct(logits.view(-1       ,							self.num_labels				)       ,							labels.view(-1				)				)
													elif self.config.problem_type == "multi_label_classification":
																snake_case_				:					int   =       BCEWithLogitsLoss()
																snake_case_				:					Optional[int]   =       loss_fct(UpperCamelCase_       ,							UpperCamelCase_				)

										if not return_dict:
													snake_case_				:					Dict   =       (logits,) + outputs[2:]
													return (loss,) + output if loss is not None else output

										return ImageClassifierOutputWithNoAttention(loss=UpperCamelCase_       ,							logits=UpperCamelCase_       ,							hidden_states=outputs.hidden_states				)







@add_start_docstrings(
    '''\n    ResNet backbone, to be used with frameworks like DETR and MaskFormer.\n    '''						,					__lowerCamelCase						,					)
class    A_	(__lowerCamelCase						,					__lowerCamelCase							):
							"""simple docstring"""




							def __init__(		self			:Dict       ,							lowerCAmelCase__			:Optional[Any]				)				->  List[Any]:


										'''simple docstring'''




										super().__init__(UpperCamelCase_				)
										super()._init_backbone(UpperCamelCase_				)

										snake_case_				:					Tuple   =       [config.embedding_size] + config.hidden_sizes
										snake_case_				:					Any   =       ResNetEmbeddings(UpperCamelCase_				)
										snake_case_				:					List[Any]   =       ResNetEncoder(UpperCamelCase_				)

										# initialize weights and apply final processing
										self.post_init()






							@add_start_docstrings_to_model_forward(UpperCamelCase_				)
							@replace_return_docstrings(output_type=UpperCamelCase_       ,							config_class=_CONFIG_FOR_DOC				)
							def 							_A	(		self			:Dict       ,							lowerCAmelCase__			:Tensor       ,							lowerCAmelCase__			:Optional[bool] = None       ,							lowerCAmelCase__			:Optional[bool] = None				)				->  List[str]:


										'''simple docstring'''




										snake_case_				:					Optional[Any]   =       return_dict if return_dict is not None else self.config.use_return_dict
										snake_case_				:					Any   =       (
										    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
										)

										snake_case_				:					str   =       self.embedder(UpperCamelCase_				)

										snake_case_				:					Optional[Any]   =       self.encoder(UpperCamelCase_       ,							output_hidden_states=UpperCamelCase_       ,							return_dict=UpperCamelCase_				)

										snake_case_				:					str   =       outputs.hidden_states

										snake_case_				:					Optional[int]   =       ()
										for idx, stage in enumerate(self.stage_names				):
													if stage in self.out_features:
																feature_maps += (hidden_states[idx],)

										if not return_dict:
													snake_case_				:					Dict   =       (feature_maps,)
													if output_hidden_states:
																output += (outputs.hidden_states,)
													return output

										return BackboneOutput(
										    feature_maps=UpperCamelCase_       ,							hidden_states=outputs.hidden_states if output_hidden_states else None       ,							attentions=UpperCamelCase_       ,							)












'''simple docstring'''




import itertools
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Union

import pandas as pd
import pyarrow as pa

import datasets
import datasets.config
from datasets.features.features import require_storage_cast
from datasets.table import table_cast
from datasets.utils.py_utils import Literal


__lowerCamelCase   :					Optional[Any]   							=					datasets.utils.logging.get_logger(__name__)

__lowerCamelCase   :					List[str]   							=					['''names''', '''prefix''']
__lowerCamelCase   :					int   							=					['''warn_bad_lines''', '''error_bad_lines''', '''mangle_dupe_cols''']
__lowerCamelCase   :					str   							=					['''encoding_errors''', '''on_bad_lines''']
__lowerCamelCase   :					Optional[Any]   							=					['''date_format''']







@dataclass
class    A_	(datasets.BuilderConfig							):
							"""simple docstring"""




							a__   		=	","
							a__   		=	None
							a__   		=	"infer"
							a__   		=	None
							a__   		=	None
							a__   		=	None
							a__   		=	None
							a__   		=	None
							a__   		=	True
							a__   		=	None
							a__   		=	None
							a__   		=	None
							a__   		=	None
							a__   		=	False
							a__   		=	None
							a__   		=	None
							a__   		=	None
							a__   		=	True
							a__   		=	True
							a__   		=	False
							a__   		=	True
							a__   		=	None
							a__   		=	"."
							a__   		=	None
							a__   		=	'"'
							a__   		=	0
							a__   		=	None
							a__   		=	None
							a__   		=	None
							a__   		=	None
							a__   		=	True
							a__   		=	True
							a__   		=	0
							a__   		=	True
							a__   		=	False
							a__   		=	None
							a__   		=	10000
							a__   		=	None
							a__   		=	"strict"
							a__   		=	"error"
							a__   		=	None

							def 							_A	(		self			:List[str]				)				->  Any:


										'''simple docstring'''




										if self.delimiter is not None:
													snake_case_				:					Tuple   =       self.delimiter
										if self.column_names is not None:
													snake_case_				:					List[Any]   =       self.column_names






							@property
							def 							_A	(		self			:Optional[Any]				)				->  int:


										'''simple docstring'''




										snake_case_				:					Optional[int]   =       {
										    "sep": self.sep,
										    "header": self.header,
										    "names": self.names,
										    "index_col": self.index_col,
										    "usecols": self.usecols,
										    "prefix": self.prefix,
										    "mangle_dupe_cols": self.mangle_dupe_cols,
										    "engine": self.engine,
										    "converters": self.converters,
										    "true_values": self.true_values,
										    "false_values": self.false_values,
										    "skipinitialspace": self.skipinitialspace,
										    "skiprows": self.skiprows,
										    "nrows": self.nrows,
										    "na_values": self.na_values,
										    "keep_default_na": self.keep_default_na,
										    "na_filter": self.na_filter,
										    "verbose": self.verbose,
										    "skip_blank_lines": self.skip_blank_lines,
										    "thousands": self.thousands,
										    "decimal": self.decimal,
										    "lineterminator": self.lineterminator,
										    "quotechar": self.quotechar,
										    "quoting": self.quoting,
										    "escapechar": self.escapechar,
										    "comment": self.comment,
										    "encoding": self.encoding,
										    "dialect": self.dialect,
										    "error_bad_lines": self.error_bad_lines,
										    "warn_bad_lines": self.warn_bad_lines,
										    "skipfooter": self.skipfooter,
										    "doublequote": self.doublequote,
										    "memory_map": self.memory_map,
										    "float_precision": self.float_precision,
										    "chunksize": self.chunksize,
										    "encoding_errors": self.encoding_errors,
										    "on_bad_lines": self.on_bad_lines,
										    "date_format": self.date_format,
										}

										# some kwargs must not be passed if they don't have a default value
										# some others are deprecated and we can also not pass them if they are the default value
										for pd_read_csv_parameter in _PANDAS_READ_CSV_NO_DEFAULT_PARAMETERS + _PANDAS_READ_CSV_DEPRECATED_PARAMETERS:
													if pd_read_csv_kwargs[pd_read_csv_parameter] == getattr(CsvConfig()       ,							lowerCAmelCase__				):
																del pd_read_csv_kwargs[pd_read_csv_parameter]

        # Remove 2.0 new arguments
										if not (datasets.config.PANDAS_VERSION.major >= 2):
													for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_2_0_0_PARAMETERS:
																del pd_read_csv_kwargs[pd_read_csv_parameter]

        # Remove 1.3 new arguments
										if not (datasets.config.PANDAS_VERSION.major >= 1 and datasets.config.PANDAS_VERSION.minor >= 3):
													for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_1_3_0_PARAMETERS:
																del pd_read_csv_kwargs[pd_read_csv_parameter]

										return pd_read_csv_kwargs







class    A_	(datasets.ArrowBasedBuilder							):
							"""simple docstring"""




							a__   		=	CsvConfig

							def 							_A	(		self			:Optional[Any]				)				->  Optional[Any]:


										'''simple docstring'''




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

							def 							_A	(		self			:Tuple       ,							lowerCAmelCase__			:Dict				)				->  List[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}'''				)
										snake_case_				:					Optional[Any]   =       dl_manager.download_and_extract(self.config.data_files				)
										if isinstance(lowerCAmelCase__       ,							(str, list, tuple)				):
													snake_case_				:					int   =       data_files
													if isinstance(lowerCAmelCase__       ,							lowerCAmelCase__				):
																snake_case_				:					List[str]   =       [files]
													snake_case_				:					Tuple   =       [dl_manager.iter_files(lowerCAmelCase__				) for file in files]
													return [datasets.SplitGenerator(name=datasets.Split.TRAIN       ,							gen_kwargs={"files": files}				)]
										snake_case_				:					str   =       []
										for split_name, files in data_files.items():
													if isinstance(lowerCAmelCase__       ,							lowerCAmelCase__				):
																snake_case_				:					str   =       [files]
													snake_case_				:					Any   =       [dl_manager.iter_files(lowerCAmelCase__				) for file in files]
													splits.append(datasets.SplitGenerator(name=lowerCAmelCase__       ,							gen_kwargs={"files": files}				)				)
										return splits

							def 							_A	(		self			:List[Any]       ,							lowerCAmelCase__			:pa.Table				)				->  pa.Table:


										'''simple docstring'''




										if self.config.features is not None:
													snake_case_				:					int   =       self.config.features.arrow_schema
													if all(not require_storage_cast(lowerCAmelCase__				) for feature in self.config.features.values()				):
																# cheaper cast
																snake_case_				:					Optional[Any]   =       pa.Table.from_arrays([pa_table[field.name] for field in schema]       ,							schema=lowerCAmelCase__				)
													else:
																# more expensive cast; allows str <-> int/float or str to Audio for example
																snake_case_				:					Dict   =       table_cast(lowerCAmelCase__       ,							lowerCAmelCase__				)
										return pa_table






							def 							_A	(		self			:Dict       ,							lowerCAmelCase__			:Union[str, Any]				)				->  Optional[int]:


										'''simple docstring'''




										snake_case_				:					Tuple   =       self.config.features.arrow_schema if self.config.features else None
										# dtype allows reading an int column as str
										snake_case_				:					str   =       (
										    {
										        name: dtype.to_pandas_dtype() if not require_storage_cast(lowerCAmelCase__				) else object
										        for name, dtype, feature in zip(schema.names       ,							schema.types       ,							self.config.features.values()				)
										    }
										    if schema is not None
										    else None
										)
										for file_idx, file in enumerate(itertools.chain.from_iterable(lowerCAmelCase__				)				):
													snake_case_				:					Tuple   =       pd.read_csv(lowerCAmelCase__       ,							iterator=lowerCAmelCase__       ,							dtype=lowerCAmelCase__       ,							**self.config.pd_read_csv_kwargs				)
													try:
																for batch_idx, df in enumerate(lowerCAmelCase__				):
																			snake_case_				:					Optional[int]   =       pa.Table.from_pandas(lowerCAmelCase__				)
																			# 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 (file_idx, batch_idx), self._cast_table(lowerCAmelCase__				)
													except ValueError as e:
																logger.error(F'''Failed to read file \'{file}\' with error {type(lowerCAmelCase__				)}: {e}'''				)
																raise




