


'''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__					(	UpperCAmelCase_    :				Tuple      ,    UpperCAmelCase_    :				Optional[int]							)     ->		Dict:
     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



@pytest.mark.parametrize('keep_in_memory'      ,    [False, True]							)
def 			UpperCAmelCase__					(	UpperCAmelCase_    :				Optional[Any]      ,    UpperCAmelCase_    :				int      ,    UpperCAmelCase_    :				List[Any]							)     ->		int:
     __lowerCamelCase   :	Optional[Any]								=		tmp_path / 'cache'
     __lowerCamelCase   :	List[str]								=		{'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
     with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
          __lowerCamelCase   :	Dict								=		JsonDatasetReader(UpperCAmelCase_      ,    cache_dir=UpperCAmelCase_      ,    keep_in_memory=UpperCAmelCase_							).read()
     _check_json_dataset(UpperCAmelCase_      ,    UpperCAmelCase_							)



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



@pytest.mark.parametrize(
    'features'      ,    [
        None,
        {'col_3': 'float64', 'col_1': 'string', 'col_2': 'int64'},
    ]      ,    )
def 			UpperCAmelCase__					(	UpperCAmelCase_    :				Tuple      ,    UpperCAmelCase_    :				Optional[Any]      ,    UpperCAmelCase_    :				Union[str, Any]							)     ->		Optional[Any]:
     __lowerCamelCase   :	Dict								=		tmp_path / 'cache'
     __lowerCamelCase   :	Optional[Any]								=		{'col_3': 'float64', 'col_1': 'string', 'col_2': 'int64'}
     __lowerCamelCase   :	Optional[Any]								=		features.copy() if features else default_expected_features
     __lowerCamelCase   :	Optional[int]								=		(
         Features({feature: Value(UpperCAmelCase_							) for feature, dtype in features.items()}							) if features is not None else None
     )
     __lowerCamelCase   :	List[str]								=		JsonDatasetReader(UpperCAmelCase_      ,    features=UpperCAmelCase_      ,    cache_dir=UpperCAmelCase_							).read()
     assert isinstance(UpperCAmelCase_      ,    UpperCAmelCase_							)
     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__					(	UpperCAmelCase_    :				List[Any]      ,    UpperCAmelCase_    :				Tuple							)     ->		Optional[int]:
     # jsonl_312_path features are {"col_3": "float64", "col_1": "string", "col_2": "int64"}
     __lowerCamelCase   :	List[Any]								=		{'col_2': 'int64', 'col_3': 'float64', 'col_1': 'string'}
     __lowerCamelCase   :	List[str]								=		features.copy()
     __lowerCamelCase   :	Any								=		(
         Features({feature: Value(UpperCAmelCase_							) for feature, dtype in features.items()}							) if features is not None else None
     )
     __lowerCamelCase   :	List[Any]								=		tmp_path / 'cache'
     __lowerCamelCase   :	Dict								=		JsonDatasetReader(UpperCAmelCase_      ,    features=UpperCAmelCase_      ,    cache_dir=UpperCAmelCase_							).read()
     assert isinstance(UpperCAmelCase_      ,    UpperCAmelCase_							)
     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__					(	UpperCAmelCase_    :				str      ,    UpperCAmelCase_    :				Optional[Any]      ,    UpperCAmelCase_    :				Optional[Any]							)     ->		Optional[int]:
     __lowerCamelCase   :	Optional[Any]								=		tmp_path / 'cache'
     __lowerCamelCase   :	int								=		{'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
     __lowerCamelCase   :	List[str]								=		JsonDatasetReader(UpperCAmelCase_      ,    cache_dir=UpperCAmelCase_      ,    split=UpperCAmelCase_							).read()
     _check_json_dataset(UpperCAmelCase_      ,    UpperCAmelCase_							)
     assert dataset.split == split if split else "train"



@pytest.mark.parametrize('path_type'      ,    [str, list]							)
def 			UpperCAmelCase__					(	UpperCAmelCase_    :				int      ,    UpperCAmelCase_    :				Optional[int]      ,    UpperCAmelCase_    :				Union[str, Any]							)     ->		Optional[Any]:
     if issubclass(UpperCAmelCase_      ,    UpperCAmelCase_							):
          __lowerCamelCase   :	List[str]								=		jsonl_path
     elif issubclass(UpperCAmelCase_      ,    UpperCAmelCase_							):
          __lowerCamelCase   :	Union[str, Any]								=		[jsonl_path]
     __lowerCamelCase   :	str								=		tmp_path / 'cache'
     __lowerCamelCase   :	List[Any]								=		{'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
     __lowerCamelCase   :	Any								=		JsonDatasetReader(UpperCAmelCase_      ,    cache_dir=UpperCAmelCase_							).read()
     _check_json_dataset(UpperCAmelCase_      ,    UpperCAmelCase_							)



def 			UpperCAmelCase__					(	UpperCAmelCase_    :				int      ,    UpperCAmelCase_    :				Any      ,    UpperCAmelCase_    :				Dict=("train",)							)     ->		Optional[Any]:
     assert isinstance(UpperCAmelCase_      ,    UpperCAmelCase_							)
     for split in splits:
          __lowerCamelCase   :	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__					(	UpperCAmelCase_    :				Tuple      ,    UpperCAmelCase_    :				int      ,    UpperCAmelCase_    :				Union[str, Any]							)     ->		int:
     __lowerCamelCase   :	Dict								=		tmp_path / 'cache'
     __lowerCamelCase   :	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():
          __lowerCamelCase   :	Any								=		JsonDatasetReader({'train': jsonl_path}      ,    cache_dir=UpperCAmelCase_      ,    keep_in_memory=UpperCAmelCase_							).read()
     _check_json_datasetdict(UpperCAmelCase_      ,    UpperCAmelCase_							)



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



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



def 			UpperCAmelCase__					(	UpperCAmelCase_    :				List[Any]							)     ->		Any:
     return json.load(UpperCAmelCase_							)



def 			UpperCAmelCase__					(	UpperCAmelCase_    :				Optional[int]							)     ->		Optional[Any]:
     return [json.loads(UpperCAmelCase_							) for line in buffer]





class    UpperCAmelCase_  :





    """simple docstring"""






    @pytest.mark.parametrize('lines, load_json_function'			,     [(True, load_json_lines), (False, load_json)]	)
    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     Dict:
         with io.BytesIO() as buffer:
              JsonDatasetWriter(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     lines=SCREAMING_SNAKE_CASE_	).write()
              buffer.seek(0	)
              __lowerCamelCase   :	Any								=		load_json_function(SCREAMING_SNAKE_CASE_	)
         assert isinstance(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)
         assert isinstance(exported_content[0]			,     SCREAMING_SNAKE_CASE_	)
         assert len(SCREAMING_SNAKE_CASE_	) == 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       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     Optional[int]:
         with io.BytesIO() as buffer:
              JsonDatasetWriter(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     lines=SCREAMING_SNAKE_CASE_			,     orient=SCREAMING_SNAKE_CASE_	).write()
              buffer.seek(0	)
              __lowerCamelCase   :	List[str]								=		load_json(SCREAMING_SNAKE_CASE_	)
         assert isinstance(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)
         if keys:
              if container is dict:
                   assert exported_content.keys() == keys
              else:
                   assert exported_content[0].keys() == keys
         else:
              assert not hasattr(SCREAMING_SNAKE_CASE_			,     'keys'	) and not hasattr(exported_content[0]			,     'keys'	)
         if len_at:
              assert len(exported_content[len_at]	) == 10
         else:
              assert len(SCREAMING_SNAKE_CASE_	) == 10







    @pytest.mark.parametrize('lines, load_json_function'			,     [(True, load_json_lines), (False, load_json)]	)
    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     Optional[int]:
         with io.BytesIO() as buffer:
              JsonDatasetWriter(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     lines=SCREAMING_SNAKE_CASE_			,     num_proc=2	).write()
              buffer.seek(0	)
              __lowerCamelCase   :	Optional[int]								=		load_json_function(SCREAMING_SNAKE_CASE_	)
         assert isinstance(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)
         assert isinstance(exported_content[0]			,     SCREAMING_SNAKE_CASE_	)
         assert len(SCREAMING_SNAKE_CASE_	) == 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       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     int:
         with io.BytesIO() as buffer:
              JsonDatasetWriter(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     lines=SCREAMING_SNAKE_CASE_			,     orient=SCREAMING_SNAKE_CASE_			,     num_proc=2	).write()
              buffer.seek(0	)
              __lowerCamelCase   :	List[str]								=		load_json(SCREAMING_SNAKE_CASE_	)
         assert isinstance(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)
         if keys:
              if container is dict:
                   assert exported_content.keys() == keys
              else:
                   assert exported_content[0].keys() == keys
         else:
              assert not hasattr(SCREAMING_SNAKE_CASE_			,     'keys'	) and not hasattr(exported_content[0]			,     'keys'	)
         if len_at:
              assert len(exported_content[len_at]	) == 10
         else:
              assert len(SCREAMING_SNAKE_CASE_	) == 10







    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_	)				->     List[Any]:
         with pytest.raises(SCREAMING_SNAKE_CASE_	):
              with io.BytesIO() as buffer:
                   JsonDatasetWriter(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     num_proc=0	)







    @pytest.mark.parametrize('compression, extension'			,     [('gzip', 'gz'), ('bz2', 'bz2'), ('xz', 'xz')]	)
    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     Any:
         __lowerCamelCase   :	List[Any]								=		tmp_path_factory.mktemp('data'	) / f'test.json.{extension}'
         __lowerCamelCase   :	Dict								=		str(shared_datadir / f'test_file.json.{extension}'	)
         JsonDatasetWriter(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     compression=SCREAMING_SNAKE_CASE_	).write()

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










'''simple docstring'''



A__		:					Any												=  8.3_1_4_4_6_2  # Unit - J mol-1 K-1



def 			UpperCAmelCase__					(	UpperCAmelCase_    :				float      ,    UpperCAmelCase_    :				float      ,    UpperCAmelCase_    :				float							)     ->		float:
     if moles < 0 or kelvin < 0 or volume < 0:
          raise ValueError('Invalid inputs. Enter positive value.'							)
     return moles * kelvin * UNIVERSAL_GAS_CONSTANT / volume



def 			UpperCAmelCase__					(	UpperCAmelCase_    :				float      ,    UpperCAmelCase_    :				float      ,    UpperCAmelCase_    :				float							)     ->		float:
     if moles < 0 or kelvin < 0 or pressure < 0:
          raise ValueError('Invalid inputs. Enter positive value.'							)
     return moles * kelvin * UNIVERSAL_GAS_CONSTANT / pressure


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

      testmod()






