


'''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       a_				(	UpperCamelCase_						,  UpperCamelCase_ ):
							assert isinstance(UpperCamelCase_						,  UpperCamelCase_ )
							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       a_				(	UpperCamelCase_						,  UpperCamelCase_						,  UpperCamelCase_						,  UpperCamelCase_ ):
							A_			    =		tmp_path / "cache"
							A_			    =		{"col_1": "string", "col_2": "int64", "col_3": "float64"}
							with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
														A_			    =		SqlDatasetReader(
														    "dataset"						,  "sqlite:///" + sqlite_path						,  cache_dir=UpperCamelCase_						,  keep_in_memory=UpperCamelCase_ ).read()
							_check_sql_dataset(UpperCamelCase_						,  UpperCamelCase_ )







@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       a_				(	UpperCamelCase_						,  UpperCamelCase_						,  UpperCamelCase_						,  UpperCamelCase_ ):
							A_			    =		tmp_path / "cache"
							A_			    =		{"col_1": "string", "col_2": "int64", "col_3": "float64"}
							A_			    =		features.copy() if features else default_expected_features
							A_			    =		(
							    Features({feature: Value(UpperCamelCase_ ) for feature, dtype in features.items()} ) if features is not None else None
							)
							A_			    =		SqlDatasetReader("dataset"						,  "sqlite:///" + sqlite_path						,  features=UpperCamelCase_						,  cache_dir=UpperCamelCase_ ).read()
							_check_sql_dataset(UpperCamelCase_						,  UpperCamelCase_ )







def       a_				(	UpperCamelCase_ ):
							with contextlib.closing(sqlitea.connect(UpperCamelCase_ ) ) as con:
														A_			    =		con.cursor()
														cur.execute("SELECT * FROM dataset" )
														for row in cur:
																					yield row







@require_sqlalchemy
def       a_				(	UpperCamelCase_						,  UpperCamelCase_						,  UpperCamelCase_ ):
							A_			    =		tmp_path / "cache"
							A_			    =		os.path.join(UpperCamelCase_						,  "tmp.sql" )
							A_			    =		SqlDatasetReader("dataset"						,  "sqlite:///" + sqlite_path						,  cache_dir=UpperCamelCase_ ).read()
							SqlDatasetWriter(UpperCamelCase_						,  "dataset"						,  "sqlite:///" + output_sqlite_path						,  num_proc=1 ).write()

							A_			    =		iter_sql_file(UpperCamelCase_ )
							A_			    =		iter_sql_file(UpperCamelCase_ )

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







@require_sqlalchemy
def       a_				(	UpperCamelCase_						,  UpperCamelCase_						,  UpperCamelCase_ ):
							A_			    =		tmp_path / "cache"
							A_			    =		os.path.join(UpperCamelCase_						,  "tmp.sql" )
							A_			    =		SqlDatasetReader("dataset"						,  "sqlite:///" + sqlite_path						,  cache_dir=UpperCamelCase_ ).read()
							SqlDatasetWriter(UpperCamelCase_						,  "dataset"						,  "sqlite:///" + output_sqlite_path						,  num_proc=2 ).write()

							A_			    =		iter_sql_file(UpperCamelCase_ )
							A_			    =		iter_sql_file(UpperCamelCase_ )

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







@require_sqlalchemy
def       a_				(	UpperCamelCase_						,  UpperCamelCase_						,  UpperCamelCase_ ):
							A_			    =		tmp_path / "cache"
							A_			    =		os.path.join(UpperCamelCase_						,  "tmp.sql" )
							A_			    =		SqlDatasetReader("dataset"						,  "sqlite:///" + sqlite_path						,  cache_dir=UpperCamelCase_ ).read()
							with pytest.raises(UpperCamelCase_ ):
														SqlDatasetWriter(UpperCamelCase_						,  "dataset"						,  "sqlite:///" + output_sqlite_path						,  num_proc=0 ).write()









'''simple docstring'''
import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
							import jax

							from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
							from transformers.models.bert.modeling_flax_bert import FlaxBertModel
							from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel






@require_flax
class 					__lowerCAmelCase   (   unittest.TestCase						):

						"""simple docstring"""






						@slow
						def 				_UpperCAmelCase       (  self							:      Dict	):
													for model_name in ["bert-base-cased", "bert-large-uncased"]:
																				with self.subTest(lowerCAmelCase	):
																											A_			    =		AutoConfig.from_pretrained(lowerCAmelCase	)
																											self.assertIsNotNone(lowerCAmelCase	)
																											self.assertIsInstance(lowerCAmelCase ,  lowerCAmelCase	)

																											A_			    =		FlaxAutoModel.from_pretrained(lowerCAmelCase	)
																											self.assertIsNotNone(lowerCAmelCase	)
																											self.assertIsInstance(lowerCAmelCase ,  lowerCAmelCase	)






						@slow
						def 				_UpperCAmelCase       (  self							:      Union[str, Any]	):
													for model_name in ["roberta-base", "roberta-large"]:
																				with self.subTest(lowerCAmelCase	):
																											A_			    =		AutoConfig.from_pretrained(lowerCAmelCase	)
																											self.assertIsNotNone(lowerCAmelCase	)
																											self.assertIsInstance(lowerCAmelCase ,  lowerCAmelCase	)

																											A_			    =		FlaxAutoModel.from_pretrained(lowerCAmelCase	)
																											self.assertIsNotNone(lowerCAmelCase	)
																											self.assertIsInstance(lowerCAmelCase ,  lowerCAmelCase	)






						@slow
						def 				_UpperCAmelCase       (  self							:      List[Any]	):
													for model_name in ["bert-base-cased", "bert-large-uncased"]:
																				A_			    =		AutoTokenizer.from_pretrained(lowerCAmelCase	)
																				A_			    =		FlaxBertModel.from_pretrained(lowerCAmelCase	)
																				A_			    =		tokenizer("Do you support jax jitted function?" ,  return_tensors=TensorType.JAX	)

																				@jax.jit
																				def eval(**lowerCAmelCase							:      Tuple	):
																											return model(**lowerCAmelCase	)

																				eval(**lowerCAmelCase	).block_until_ready()






						@slow
						def 				_UpperCAmelCase       (  self							:      str	):
													for model_name in ["roberta-base", "roberta-large"]:
																				A_			    =		AutoTokenizer.from_pretrained(lowerCAmelCase	)
																				A_			    =		FlaxRobertaModel.from_pretrained(lowerCAmelCase	)
																				A_			    =		tokenizer("Do you support jax jitted function?" ,  return_tensors=TensorType.JAX	)

																				@jax.jit
																				def eval(**lowerCAmelCase							:      Any	):
																											return model(**lowerCAmelCase	)

																				eval(**lowerCAmelCase	).block_until_ready()






						def 				_UpperCAmelCase       (  self							:      List[Any]	):
													with self.assertRaisesRegex(
													    lowerCAmelCase ,  "bert-base is not a local folder and is not a valid model identifier"	):
																				A_			    =		FlaxAutoModel.from_pretrained("bert-base"	)






						def 				_UpperCAmelCase       (  self							:      Any	):
													with self.assertRaisesRegex(
													    lowerCAmelCase ,  r"aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"	):
																				A_			    =		FlaxAutoModel.from_pretrained(lowerCAmelCase ,  revision="aaaaaa"	)






						def 				_UpperCAmelCase       (  self							:      Dict	):
													with self.assertRaisesRegex(
													    lowerCAmelCase ,  "hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack" ,  ):
																				A_			    =		FlaxAutoModel.from_pretrained("hf-internal-testing/config-no-model"	)






						def 				_UpperCAmelCase       (  self							:      Any	):
													with self.assertRaisesRegex(lowerCAmelCase ,  "Use `from_pt=True` to load this model"	):
																				A_			    =		FlaxAutoModel.from_pretrained("hf-internal-testing/tiny-bert-pt-only"	)





