'''simple docstring'''

import io
import json

import fsspec
import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.json import JsonDatasetReader, JsonDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases







def __UpperCamelCase(   _A					:				Tuple  ,			_A					:				Any    ):
   '''simple docstring'''
   assert isinstance(_A  ,			_A    )
   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







@pytest.mark.parametrize('''keep_in_memory'''  ,			[False, True]    )
def __UpperCamelCase(   _A					:				str  ,			_A					:				Tuple  ,			_A					:				Any    ):
   '''simple docstring'''
   UpperCAmelCase__							:				int   				=  tmp_path / '''cache'''
   UpperCAmelCase__							:				Optional[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():
      UpperCAmelCase__							:				List[Any]   				=  JsonDatasetReader(_A  ,			cache_dir=_A  ,			keep_in_memory=_A    ).read()
   _check_json_dataset(_A  ,			_A    )







@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 __UpperCamelCase(   _A					:				str  ,			_A					:				List[Any]  ,			_A					:				Dict    ):
   '''simple docstring'''
   UpperCAmelCase__							:				List[str]   				=  tmp_path / '''cache'''
   UpperCAmelCase__							:				Any   				=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
   UpperCAmelCase__							:				Dict   				=  features.copy() if features else default_expected_features
   UpperCAmelCase__							:				Tuple   				=  (
       Features({feature: Value(_A    ) for feature, dtype in features.items()}    ) if features is not None else None
   )
   UpperCAmelCase__							:				str   				=  JsonDatasetReader(_A  ,			features=_A  ,			cache_dir=_A    ).read()
   _check_json_dataset(_A  ,			_A    )







@pytest.mark.parametrize(
    '''features'''  ,			[
        None,
        {'''col_3''': '''float64''', '''col_1''': '''string''', '''col_2''': '''int64'''},
    ]  ,			)
def __UpperCamelCase(   _A					:				List[Any]  ,			_A					:				Union[str, Any]  ,			_A					:				Optional[int]    ):
   '''simple docstring'''
   UpperCAmelCase__							:				Union[str, Any]   				=  tmp_path / '''cache'''
   UpperCAmelCase__							:				Tuple   				=  {'''col_3''': '''float64''', '''col_1''': '''string''', '''col_2''': '''int64'''}
   UpperCAmelCase__							:				Optional[Any]   				=  features.copy() if features else default_expected_features
   UpperCAmelCase__							:				Tuple   				=  (
       Features({feature: Value(_A    ) for feature, dtype in features.items()}    ) if features is not None else None
   )
   UpperCAmelCase__							:				Optional[Any]   				=  JsonDatasetReader(_A  ,			features=_A  ,			cache_dir=_A    ).read()
   assert isinstance(_A  ,			_A    )
   assert dataset.num_rows == 2
   assert dataset.num_columns == 3
   assert dataset.column_names == ["col_3", "col_1", "col_2"]
   for feature, expected_dtype in expected_features.items():
      assert dataset.features[feature].dtype == expected_dtype







def __UpperCamelCase(   _A					:				str  ,			_A					:				List[str]    ):
   '''simple docstring'''
   # jsonl_312_path features are {"col_3": "float64", "col_1": "string", "col_2": "int64"}
   UpperCAmelCase__							:				List[Any]   				=  {'''col_2''': '''int64''', '''col_3''': '''float64''', '''col_1''': '''string'''}
   UpperCAmelCase__							:				int   				=  features.copy()
   UpperCAmelCase__							:				int   				=  (
       Features({feature: Value(_A    ) for feature, dtype in features.items()}    ) if features is not None else None
   )
   UpperCAmelCase__							:				Optional[Any]   				=  tmp_path / '''cache'''
   UpperCAmelCase__							:				List[str]   				=  JsonDatasetReader(_A  ,			features=_A  ,			cache_dir=_A    ).read()
   assert isinstance(_A  ,			_A    )
   assert dataset.num_rows == 2
   assert dataset.num_columns == 3
   assert dataset.column_names == ["col_2", "col_3", "col_1"]
   for feature, expected_dtype in expected_features.items():
      assert dataset.features[feature].dtype == expected_dtype







@pytest.mark.parametrize('''split'''  ,			[None, NamedSplit('''train'''    ), '''train''', '''test''']    )
def __UpperCamelCase(   _A					:				Optional[int]  ,			_A					:				Optional[Any]  ,			_A					:				Any    ):
   '''simple docstring'''
   UpperCAmelCase__							:				Union[str, Any]   				=  tmp_path / '''cache'''
   UpperCAmelCase__							:				Any   				=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
   UpperCAmelCase__							:				Tuple   				=  JsonDatasetReader(_A  ,			cache_dir=_A  ,			split=_A    ).read()
   _check_json_dataset(_A  ,			_A    )
   assert dataset.split == split if split else "train"







@pytest.mark.parametrize('''path_type'''  ,			[str, list]    )
def __UpperCamelCase(   _A					:				str  ,			_A					:				List[Any]  ,			_A					:				List[str]    ):
   '''simple docstring'''
   if issubclass(_A  ,			_A    ):
      UpperCAmelCase__							:				List[str]   				=  jsonl_path
   elif issubclass(_A  ,			_A    ):
      UpperCAmelCase__							:				Dict   				=  [jsonl_path]
   UpperCAmelCase__							:				Tuple   				=  tmp_path / '''cache'''
   UpperCAmelCase__							:				Any   				=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
   UpperCAmelCase__							:				Optional[Any]   				=  JsonDatasetReader(_A  ,			cache_dir=_A    ).read()
   _check_json_dataset(_A  ,			_A    )







def __UpperCamelCase(   _A					:				List[str]  ,			_A					:				List[Any]  ,			_A					:				Dict=("train",)    ):
   '''simple docstring'''
   assert isinstance(_A  ,			_A    )
   for split in splits:
      UpperCAmelCase__							:				Optional[Any]   				=  dataset_dict[split]
      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







@pytest.mark.parametrize('''keep_in_memory'''  ,			[False, True]    )
def __UpperCamelCase(   _A					:				List[Any]  ,			_A					:				int  ,			_A					:				int    ):
   '''simple docstring'''
   UpperCAmelCase__							:				int   				=  tmp_path / '''cache'''
   UpperCAmelCase__							:				List[Any]   				=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
   with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
      UpperCAmelCase__							:				Optional[int]   				=  JsonDatasetReader({'''train''': jsonl_path}  ,			cache_dir=_A  ,			keep_in_memory=_A    ).read()
   _check_json_datasetdict(_A  ,			_A    )







@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 __UpperCamelCase(   _A					:				Optional[int]  ,			_A					:				Optional[Any]  ,			_A					:				Tuple    ):
   '''simple docstring'''
   UpperCAmelCase__							:				str   				=  tmp_path / '''cache'''
   UpperCAmelCase__							:				List[str]   				=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
   UpperCAmelCase__							:				Dict   				=  features.copy() if features else default_expected_features
   UpperCAmelCase__							:				Union[str, Any]   				=  (
       Features({feature: Value(_A    ) for feature, dtype in features.items()}    ) if features is not None else None
   )
   UpperCAmelCase__							:				int   				=  JsonDatasetReader({'''train''': jsonl_path}  ,			features=_A  ,			cache_dir=_A    ).read()
   _check_json_datasetdict(_A  ,			_A    )







@pytest.mark.parametrize('''split'''  ,			[None, NamedSplit('''train'''    ), '''train''', '''test''']    )
def __UpperCamelCase(   _A					:				Tuple  ,			_A					:				List[str]  ,			_A					:				Any    ):
   '''simple docstring'''
   if split:
      UpperCAmelCase__							:				List[Any]   				=  {split: jsonl_path}
   else:
      UpperCAmelCase__							:				str   				=  '''train'''
      UpperCAmelCase__							:				List[Any]   				=  {'''train''': jsonl_path, '''test''': jsonl_path}
   UpperCAmelCase__							:				Optional[int]   				=  tmp_path / '''cache'''
   UpperCAmelCase__							:				Any   				=  {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
   UpperCAmelCase__							:				int   				=  JsonDatasetReader(_A  ,			cache_dir=_A    ).read()
   _check_json_datasetdict(_A  ,			_A  ,			splits=list(path.keys()    )    )
   assert all(dataset[split].split == split for split in path.keys()    )







def __UpperCamelCase(   _A					:				Union[str, Any]    ):
   '''simple docstring'''
   return json.load(_A    )







def __UpperCamelCase(   _A					:				Dict    ):
   '''simple docstring'''
   return [json.loads(_A    ) for line in buffer]


class 				_lowercase	:
      '''simple docstring'''


      @pytest.mark.parametrize('''lines, load_json_function'''					,[(True, load_json_lines), (False, load_json)]							)
      def 		lowerCAmelCase__					(				self					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_							)			->			List[Any]:



         '''simple docstring'''



         with io.BytesIO() as buffer:
            JsonDatasetWriter(lowerCamelCase_					,lowerCamelCase_					,lines=lowerCamelCase_							).write()
            buffer.seek(0							)
            UpperCAmelCase__							:				List[str]   				=  load_json_function(lowerCamelCase_							)
         assert isinstance(lowerCamelCase_					,lowerCamelCase_							)
         assert isinstance(exported_content[0]					,lowerCamelCase_							)
         assert len(lowerCamelCase_							) == 10




      @pytest.mark.parametrize(
          '''orient, container, keys, len_at'''					,[
              ('''records''', list, {'''tokens''', '''labels''', '''answers''', '''id'''}, None),
              ('''split''', dict, {'''columns''', '''data'''}, '''data'''),
              ('''index''', dict, set('''0123456789'''							), None),
              ('''columns''', dict, {'''tokens''', '''labels''', '''answers''', '''id'''}, '''tokens'''),
              ('''values''', list, None, None),
              ('''table''', dict, {'''schema''', '''data'''}, '''data'''),
          ]					,)
      def 		lowerCAmelCase__					(				self					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_							)			->			int:



         '''simple docstring'''



         with io.BytesIO() as buffer:
            JsonDatasetWriter(lowerCamelCase_					,lowerCamelCase_					,lines=lowerCamelCase_					,orient=lowerCamelCase_							).write()
            buffer.seek(0							)
            UpperCAmelCase__							:				List[Any]   				=  load_json(lowerCamelCase_							)
         assert isinstance(lowerCamelCase_					,lowerCamelCase_							)
         if keys:
            if container is dict:
               assert exported_content.keys() == keys
            else:
               assert exported_content[0].keys() == keys
         else:
            assert not hasattr(lowerCamelCase_					,'''keys'''							) and not hasattr(exported_content[0]					,'''keys'''							)
         if len_at:
            assert len(exported_content[len_at]							) == 10
         else:
            assert len(lowerCamelCase_							) == 10




      @pytest.mark.parametrize('''lines, load_json_function'''					,[(True, load_json_lines), (False, load_json)]							)
      def 		lowerCAmelCase__					(				self					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_							)			->			Any:



         '''simple docstring'''



         with io.BytesIO() as buffer:
            JsonDatasetWriter(lowerCamelCase_					,lowerCamelCase_					,lines=lowerCamelCase_					,num_proc=2							).write()
            buffer.seek(0							)
            UpperCAmelCase__							:				int   				=  load_json_function(lowerCamelCase_							)
         assert isinstance(lowerCamelCase_					,lowerCamelCase_							)
         assert isinstance(exported_content[0]					,lowerCamelCase_							)
         assert len(lowerCamelCase_							) == 10




      @pytest.mark.parametrize(
          '''orient, container, keys, len_at'''					,[
              ('''records''', list, {'''tokens''', '''labels''', '''answers''', '''id'''}, None),
              ('''split''', dict, {'''columns''', '''data'''}, '''data'''),
              ('''index''', dict, set('''0123456789'''							), None),
              ('''columns''', dict, {'''tokens''', '''labels''', '''answers''', '''id'''}, '''tokens'''),
              ('''values''', list, None, None),
              ('''table''', dict, {'''schema''', '''data'''}, '''data'''),
          ]					,)
      def 		lowerCAmelCase__					(				self					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_							)			->			str:



         '''simple docstring'''



         with io.BytesIO() as buffer:
            JsonDatasetWriter(lowerCamelCase_					,lowerCamelCase_					,lines=lowerCamelCase_					,orient=lowerCamelCase_					,num_proc=2							).write()
            buffer.seek(0							)
            UpperCAmelCase__							:				List[Any]   				=  load_json(lowerCamelCase_							)
         assert isinstance(lowerCamelCase_					,lowerCamelCase_							)
         if keys:
            if container is dict:
               assert exported_content.keys() == keys
            else:
               assert exported_content[0].keys() == keys
         else:
            assert not hasattr(lowerCamelCase_					,'''keys'''							) and not hasattr(exported_content[0]					,'''keys'''							)
         if len_at:
            assert len(exported_content[len_at]							) == 10
         else:
            assert len(lowerCamelCase_							) == 10




      def 		lowerCAmelCase__					(				self					,lowerCamelCase_							)			->			Optional[int]:



         '''simple docstring'''



         with pytest.raises(lowerCamelCase_							):
            with io.BytesIO() as buffer:
               JsonDatasetWriter(lowerCamelCase_					,lowerCamelCase_					,num_proc=0							)




      @pytest.mark.parametrize('''compression, extension'''					,[('''gzip''', '''gz'''), ('''bz2''', '''bz2'''), ('''xz''', '''xz''')]							)
      def 		lowerCAmelCase__					(				self					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_							)			->			Optional[Any]:



         '''simple docstring'''



         UpperCAmelCase__							:				Dict   				=  tmp_path_factory.mktemp('''data'''							) / f'''test.json.{extension}'''
         UpperCAmelCase__							:				Optional[int]   				=  str(shared_datadir / f'''test_file.json.{extension}'''							)
         JsonDatasetWriter(lowerCamelCase_					,lowerCamelCase_					,compression=lowerCamelCase_							).write()

         with fsspec.open(lowerCamelCase_					,'''rb'''					,compression='''infer'''							) as f:
            UpperCAmelCase__							:				Union[str, Any]   				=  f.read()
         with fsspec.open(lowerCamelCase_					,'''rb'''					,compression='''infer'''							) as f:
            UpperCAmelCase__							:				List[Any]   				=  f.read()
         assert exported_content == original_content





'''simple docstring'''

import math







def __UpperCamelCase(   _A					:				float  ,			_A					:				float    ):
   '''simple docstring'''
   return math.pow(_A  ,			2    ) - a







def __UpperCamelCase(   _A					:				float    ):
   '''simple docstring'''
   return 2 * x







def __UpperCamelCase(   _A					:				float    ):
   '''simple docstring'''
   UpperCAmelCase__							:				int   				=  2.0

   while start <= a:
      UpperCAmelCase__							:				int   				=  math.pow(_A  ,			2    )

   return start







def __UpperCamelCase(   _A					:				float  ,			_A					:				int = 99_99  ,			_A					:				float = 0.0_0_0_0_0_0_0_0_0_0_0_0_0_1    ):
   '''simple docstring'''

   if a < 0:
      raise ValueError('''math domain error'''    )

   UpperCAmelCase__							:				Any   				=  get_initial_point(_A    )

   for _ in range(_A    ):
      UpperCAmelCase__							:				Optional[Any]   				=  value
      UpperCAmelCase__							:				Tuple   				=  value - fx(_A  ,			_A    ) / fx_derivative(_A    )
      if abs(prev_value - value    ) < tolerance:
         return value

   return value


if __name__ == "__main__":
  from doctest import testmod

  testmod()




