




'''simple docstring'''


import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, 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


if TYPE_CHECKING:
				import sqlitea

				import sqlalchemy


_snake_case      :      Tuple   							=		datasets.utils.logging.get_logger(__name__)

@dataclass
class 			A    (		datasets.BuilderConfig    ):
							lowercase_							=				None
							lowercase_							=				None
							lowercase_							=				None
							lowercase_							=				True
							lowercase_							=				None
							lowercase_							=				None
							lowercase_							=				None
							lowercase_							=				1_0000
							lowercase_							=				None







							def    __lowerCAmelCase			(  self       :  int					)			->							Union[str, Any]:


														"""simple docstring"""


														if self.sql is None:
																					raise ValueError('''sql must be specified'''					)
														if self.con is None:
																					raise ValueError('''con must be specified'''					)







							def    __lowerCAmelCase			(  self       :  Optional[Any]							,			lowerCAmelCase_       :  dict							,			lowerCAmelCase_       :  Optional[datasets.Features] = None							,			)			->							str:


														"""simple docstring"""


														_a	     =				config_kwargs.copy()
														# We need to stringify the Selectable object to make its hash deterministic

														# The process of stringifying is explained here: http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html
														_a	     =				config_kwargs['''sql''']
														if not isinstance(lowerCAmelCase_							,			lowerCAmelCase_					):
																					if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
																												import sqlalchemy

																												if isinstance(lowerCAmelCase_							,			sqlalchemy.sql.Selectable					):
																																			_a	     =				sqlalchemy.create_engine(config_kwargs['''con'''].split('''://'''					)[0] + '''://'''					)
																																			_a	     =				str(sql.compile(dialect=engine.dialect					)					)
																																			_a	     =				sql_str
																												else:
																																			raise TypeError(
																																			    F'Supported types for \'sql\' are string and sqlalchemy.sql.Selectable but got {type(lowerCAmelCase_					)}: {sql}'					)
																					else:
																												raise TypeError(
																												    F'Supported types for \'sql\' are string and sqlalchemy.sql.Selectable but got {type(lowerCAmelCase_					)}: {sql}'					)
														_a	     =				config_kwargs['''con''']
														if not isinstance(lowerCAmelCase_							,			lowerCAmelCase_					):
																					_a	     =				id(lowerCAmelCase_					)
																					logger.info(
																					    F'SQL connection \'con\' of type {type(lowerCAmelCase_					)} couldn\'t be hashed properly. To enable hashing, specify \'con\' as URI string instead.'					)

														return super().create_config_id(lowerCAmelCase_							,			custom_features=lowerCAmelCase_					)







							@property
							def    __lowerCAmelCase			(  self       :  List[Any]					)			->							Optional[Any]:


														"""simple docstring"""


														_a	     =				{
														    '''index_col''': self.index_col,
														    '''columns''': self.columns,
														    '''params''': self.params,
														    '''coerce_float''': self.coerce_float,
														    '''parse_dates''': self.parse_dates,
														}
														return pd_read_sql_kwargs



class 			A    (		datasets.ArrowBasedBuilder    ):
							lowercase_							=				SqlConfig







							def    __lowerCAmelCase			(  self       :  int					)			->							Optional[Any]:


														"""simple docstring"""


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







							def    __lowerCAmelCase			(  self       :  List[str]							,			lowerCAmelCase_       :  Dict					)			->							List[Any]:


														"""simple docstring"""


														return [datasets.SplitGenerator(name=datasets.Split.TRAIN							,			gen_kwargs={}					)]







							def    __lowerCAmelCase			(  self       :  Union[str, Any]							,			lowerCAmelCase_       :  pa.Table					)			->							pa.Table:


														"""simple docstring"""


														if self.config.features is not None:
																					_a	     =				self.config.features.arrow_schema
																					if all(not require_storage_cast(lowerCAmelCase_					) for feature in self.config.features.values()					):
																												# cheaper cast
																												_a	     =				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
																												_a	     =				table_cast(lowerCAmelCase_							,			lowerCAmelCase_					)
														return pa_table







							def    __lowerCAmelCase			(  self       :  int					)			->							Optional[Any]:


														"""simple docstring"""


														_a	     =				self.config.chunksize
														_a	     =				pd.read_sql(
														    self.config.sql							,			self.config.con							,			chunksize=lowerCAmelCase_							,			**self.config.pd_read_sql_kwargs					)
														_a	     =				[sql_reader] if chunksize is None else sql_reader
														for chunk_idx, df in enumerate(lowerCAmelCase_					):
																					_a	     =				pa.Table.from_pandas(lowerCAmelCase_					)
																					yield chunk_idx, self._cast_table(lowerCAmelCase_					)







'''simple docstring'''


# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


_snake_case      :      Tuple   							=		{
    'configuration_convnextv2': [
        'CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'ConvNextV2Config',
    ]
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_snake_case      :      Tuple   							=		[
				    'CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'ConvNextV2ForImageClassification',
				    'ConvNextV2Model',
				    'ConvNextV2PreTrainedModel',
				    'ConvNextV2Backbone',
				]


if TYPE_CHECKING:
				from .configuration_convnextva import (
				    CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
				    ConvNextVaConfig,
				)

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_convnextva import (
								    CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST,
								    ConvNextVaBackbone,
								    ConvNextVaForImageClassification,
								    ConvNextVaModel,
								    ConvNextVaPreTrainedModel,
								)

else:
				import sys

				_snake_case      :      Any   							=		_LazyModule(__name__, globals()['__file__'], _import_structure)

