



"""simple docstring"""
import contextlib
import os
import sqlitea

import pytest

from datasets import Dataset, Features, Value
from datasets.io.sql import SqlDatasetReader, SqlDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases, require_sqlalchemy





def      __magic_name__				(							lowercase							,			lowercase ):
   assert isinstance(lowercase							,			lowercase )
   assert dataset.num_rows == 4
   assert dataset.num_columns == 3
   assert dataset.column_names == ["col_1", "col_2", "col_3"]
   for feature, expected_dtype in expected_features.items():
      assert dataset.features[feature].dtype == expected_dtype





@require_sqlalchemy
@pytest.mark.parametrize("""keep_in_memory"""							,			[False, True] )
def      __magic_name__				(							lowercase							,			lowercase							,			lowercase							,			lowercase ):
   SCREAMING_SNAKE_CASE_: int     			=tmp_path / """cache"""
   SCREAMING_SNAKE_CASE_: int     			={"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
   with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
      SCREAMING_SNAKE_CASE_: str     			=SqlDatasetReader(
          """dataset"""							,			"""sqlite:///""" + sqlite_path							,			cache_dir=lowercase							,			keep_in_memory=lowercase ).read()
   _check_sql_dataset(lowercase							,			lowercase )





@require_sqlalchemy
@pytest.mark.parametrize(
    """features"""							,			[
        None,
        {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""},
        {"""col_1""": """string""", """col_2""": """string""", """col_3""": """string"""},
        {"""col_1""": """int32""", """col_2""": """int32""", """col_3""": """int32"""},
        {"""col_1""": """float32""", """col_2""": """float32""", """col_3""": """float32"""},
    ]							,			)
def      __magic_name__				(							lowercase							,			lowercase							,			lowercase							,			lowercase ):
   SCREAMING_SNAKE_CASE_: Union[str, Any]     			=tmp_path / """cache"""
   SCREAMING_SNAKE_CASE_: Union[str, Any]     			={"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
   SCREAMING_SNAKE_CASE_: int     			=features.copy() if features else default_expected_features
   SCREAMING_SNAKE_CASE_: str     			=(
       Features({feature: Value(lowercase ) for feature, dtype in features.items()} ) if features is not None else None
   )
   SCREAMING_SNAKE_CASE_: Tuple     			=SqlDatasetReader("""dataset"""							,			"""sqlite:///""" + sqlite_path							,			features=lowercase							,			cache_dir=lowercase ).read()
   _check_sql_dataset(lowercase							,			lowercase )





def      __magic_name__				(							lowercase ):
   with contextlib.closing(sqlitea.connect(lowercase ) ) as con:
      SCREAMING_SNAKE_CASE_: Union[str, Any]     			=con.cursor()
      cur.execute("""SELECT * FROM dataset""" )
      for row in cur:
         yield row





@require_sqlalchemy
def      __magic_name__				(							lowercase							,			lowercase							,			lowercase ):
   SCREAMING_SNAKE_CASE_: Optional[int]     			=tmp_path / """cache"""
   SCREAMING_SNAKE_CASE_: List[Any]     			=os.path.join(lowercase							,			"""tmp.sql""" )
   SCREAMING_SNAKE_CASE_: Tuple     			=SqlDatasetReader("""dataset"""							,			"""sqlite:///""" + sqlite_path							,			cache_dir=lowercase ).read()
   SqlDatasetWriter(lowercase							,			"""dataset"""							,			"""sqlite:///""" + output_sqlite_path							,			num_proc=1 ).write()

   SCREAMING_SNAKE_CASE_: Optional[Any]     			=iter_sql_file(lowercase )
   SCREAMING_SNAKE_CASE_: str     			=iter_sql_file(lowercase )

   for rowa, rowa in zip(lowercase							,			lowercase ):
      assert rowa == rowa





@require_sqlalchemy
def      __magic_name__				(							lowercase							,			lowercase							,			lowercase ):
   SCREAMING_SNAKE_CASE_: Optional[Any]     			=tmp_path / """cache"""
   SCREAMING_SNAKE_CASE_: Union[str, Any]     			=os.path.join(lowercase							,			"""tmp.sql""" )
   SCREAMING_SNAKE_CASE_: str     			=SqlDatasetReader("""dataset"""							,			"""sqlite:///""" + sqlite_path							,			cache_dir=lowercase ).read()
   SqlDatasetWriter(lowercase							,			"""dataset"""							,			"""sqlite:///""" + output_sqlite_path							,			num_proc=2 ).write()

   SCREAMING_SNAKE_CASE_: List[str]     			=iter_sql_file(lowercase )
   SCREAMING_SNAKE_CASE_: int     			=iter_sql_file(lowercase )

   for rowa, rowa in zip(lowercase							,			lowercase ):
      assert rowa == rowa





@require_sqlalchemy
def      __magic_name__				(							lowercase							,			lowercase							,			lowercase ):
   SCREAMING_SNAKE_CASE_: List[Any]     			=tmp_path / """cache"""
   SCREAMING_SNAKE_CASE_: Tuple     			=os.path.join(lowercase							,			"""tmp.sql""" )
   SCREAMING_SNAKE_CASE_: int     			=SqlDatasetReader("""dataset"""							,			"""sqlite:///""" + sqlite_path							,			cache_dir=lowercase ).read()
   with pytest.raises(lowercase ):
      SqlDatasetWriter(lowercase							,			"""dataset"""							,			"""sqlite:///""" + output_sqlite_path							,			num_proc=0 ).write()








"""simple docstring"""
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


_UpperCAmelCase     =			{
    """configuration_xlm""": ["""XLM_PRETRAINED_CONFIG_ARCHIVE_MAP""", """XLMConfig""", """XLMOnnxConfig"""],
    """tokenization_xlm""": ["""XLMTokenizer"""],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _UpperCAmelCase     =			[
       """XLM_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """XLMForMultipleChoice""",
       """XLMForQuestionAnswering""",
       """XLMForQuestionAnsweringSimple""",
       """XLMForSequenceClassification""",
       """XLMForTokenClassification""",
       """XLMModel""",
       """XLMPreTrainedModel""",
       """XLMWithLMHeadModel""",
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _UpperCAmelCase     =			[
       """TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """TFXLMForMultipleChoice""",
       """TFXLMForQuestionAnsweringSimple""",
       """TFXLMForSequenceClassification""",
       """TFXLMForTokenClassification""",
       """TFXLMMainLayer""",
       """TFXLMModel""",
       """TFXLMPreTrainedModel""",
       """TFXLMWithLMHeadModel""",
   ]


if TYPE_CHECKING:
   from .configuration_xlm import XLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XLMConfig, XLMOnnxConfig
   from .tokenization_xlm import XLMTokenizer

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_xlm import (
          XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
          XLMForMultipleChoice,
          XLMForQuestionAnswering,
          XLMForQuestionAnsweringSimple,
          XLMForSequenceClassification,
          XLMForTokenClassification,
          XLMModel,
          XLMPreTrainedModel,
          XLMWithLMHeadModel,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_xlm import (
          TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFXLMForMultipleChoice,
          TFXLMForQuestionAnsweringSimple,
          TFXLMForSequenceClassification,
          TFXLMForTokenClassification,
          TFXLMMainLayer,
          TFXLMModel,
          TFXLMPreTrainedModel,
          TFXLMWithLMHeadModel,
      )

else:
   import sys

   _UpperCAmelCase     =			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



