'''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 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase      )						->					Tuple:

   '''simple docstring'''







   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 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )						->					Union[str, Any]:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       tmp_path / """cache"""
   __SCREAMING_SNAKE_CASE      							=       {"""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      							=       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 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )						->					Optional[int]:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       tmp_path / """cache"""
   __SCREAMING_SNAKE_CASE      							=       {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
   __SCREAMING_SNAKE_CASE      							=       features.copy() if features else default_expected_features
   __SCREAMING_SNAKE_CASE      							=       (
       Features({feature: Value(UpperCAmelCase__      ) for feature, dtype in features.items()}      ) if features is not None else None
   )
   __SCREAMING_SNAKE_CASE      							=       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 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )						->					str:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       tmp_path / """cache"""
   __SCREAMING_SNAKE_CASE      							=       {"""col_3""": """float64""", """col_1""": """string""", """col_2""": """int64"""}
   __SCREAMING_SNAKE_CASE      							=       features.copy() if features else default_expected_features
   __SCREAMING_SNAKE_CASE      							=       (
       Features({feature: Value(UpperCAmelCase__      ) for feature, dtype in features.items()}      ) if features is not None else None
   )
   __SCREAMING_SNAKE_CASE      							=       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 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase      )						->					str:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       {"""col_2""": """int64""", """col_3""": """float64""", """col_1""": """string"""}
   __SCREAMING_SNAKE_CASE      							=       features.copy()
   __SCREAMING_SNAKE_CASE      							=       (
       Features({feature: Value(UpperCAmelCase__      ) for feature, dtype in features.items()}      ) if features is not None else None
   )
   __SCREAMING_SNAKE_CASE      							=       tmp_path / """cache"""
   __SCREAMING_SNAKE_CASE      							=       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 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )						->					Union[str, Any]:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       tmp_path / """cache"""
   __SCREAMING_SNAKE_CASE      							=       {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
   __SCREAMING_SNAKE_CASE      							=       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 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )						->					str:

   '''simple docstring'''







   if issubclass(UpperCAmelCase__							,	UpperCAmelCase__      ):
      __SCREAMING_SNAKE_CASE      							=       jsonl_path
   elif issubclass(UpperCAmelCase__							,	UpperCAmelCase__      ):
      __SCREAMING_SNAKE_CASE      							=       [jsonl_path]
   __SCREAMING_SNAKE_CASE      							=       tmp_path / """cache"""
   __SCREAMING_SNAKE_CASE      							=       {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
   __SCREAMING_SNAKE_CASE      							=       JsonDatasetReader(UpperCAmelCase__							,	cache_dir=UpperCAmelCase__      ).read()
   _check_json_dataset(UpperCAmelCase__							,	UpperCAmelCase__      )

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase=("train",)      )						->					Union[str, Any]:

   '''simple docstring'''







   assert isinstance(UpperCAmelCase__							,	UpperCAmelCase__      )
   for split in splits:
      __SCREAMING_SNAKE_CASE      							=       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 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )						->					Optional[Any]:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       tmp_path / """cache"""
   __SCREAMING_SNAKE_CASE      							=       {"""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      							=       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 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )						->					Any:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       tmp_path / """cache"""
   __SCREAMING_SNAKE_CASE      							=       {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
   __SCREAMING_SNAKE_CASE      							=       features.copy() if features else default_expected_features
   __SCREAMING_SNAKE_CASE      							=       (
       Features({feature: Value(UpperCAmelCase__      ) for feature, dtype in features.items()}      ) if features is not None else None
   )
   __SCREAMING_SNAKE_CASE      							=       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 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )						->					Any:

   '''simple docstring'''







   if split:
      __SCREAMING_SNAKE_CASE      							=       {split: jsonl_path}
   else:
      __SCREAMING_SNAKE_CASE      							=       """train"""
      __SCREAMING_SNAKE_CASE      							=       {"""train""": jsonl_path, """test""": jsonl_path}
   __SCREAMING_SNAKE_CASE      							=       tmp_path / """cache"""
   __SCREAMING_SNAKE_CASE      							=       {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
   __SCREAMING_SNAKE_CASE      							=       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 						__magic_name__       (							__UpperCAmelCase      )						->					Tuple:

   '''simple docstring'''







   return json.load(UpperCAmelCase__      )

def 						__magic_name__       (							__UpperCAmelCase      )						->					Union[str, Any]:

   '''simple docstring'''







   return [json.loads(UpperCAmelCase__      ) for line in buffer]







class __a :





   @pytest.mark.parametrize("""lines, load_json_function"""				,[(True, load_json_lines), (False, load_json)]    )
   def      UpperCAmelCase__     (					self				:			Dict				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Any				,lowerCamelCase				:			Dict    ):

      '''simple docstring'''

      with io.BytesIO() as buffer:
         JsonDatasetWriter(_A				,_A				,lines=_A    ).write()
         buffer.seek(0    )
         __SCREAMING_SNAKE_CASE      							=       load_json_function(_A    )
      assert isinstance(_A				,_A    )
      assert isinstance(exported_content[0]				,_A    )
      assert len(_A    ) == 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      UpperCAmelCase__     (					self				:			List[Any]				,lowerCamelCase				:			Dict				,lowerCamelCase				:			Dict				,lowerCamelCase				:			List[str]				,lowerCamelCase				:			Tuple				,lowerCamelCase				:			List[str]    ):

      '''simple docstring'''

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





   @pytest.mark.parametrize("""lines, load_json_function"""				,[(True, load_json_lines), (False, load_json)]    )
   def      UpperCAmelCase__     (					self				:			Optional[Any]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			int				,lowerCamelCase				:			Union[str, Any]    ):

      '''simple docstring'''

      with io.BytesIO() as buffer:
         JsonDatasetWriter(_A				,_A				,lines=_A				,num_proc=2    ).write()
         buffer.seek(0    )
         __SCREAMING_SNAKE_CASE      							=       load_json_function(_A    )
      assert isinstance(_A				,_A    )
      assert isinstance(exported_content[0]				,_A    )
      assert len(_A    ) == 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      UpperCAmelCase__     (					self				:			List[Any]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			Dict				,lowerCamelCase				:			str				,lowerCamelCase				:			Tuple				,lowerCamelCase				:			str    ):

      '''simple docstring'''

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





   def      UpperCAmelCase__     (					self				:			str				,lowerCamelCase				:			Dict    ):

      '''simple docstring'''

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





   @pytest.mark.parametrize("""compression, extension"""				,[("""gzip""", """gz"""), ("""bz2""", """bz2"""), ("""xz""", """xz""")]    )
   def      UpperCAmelCase__     (					self				:			str				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Union[str, Any]				,lowerCamelCase				:			List[str]				,lowerCamelCase				:			Optional[int]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       tmp_path_factory.mktemp("""data"""    ) / f"""test.json.{extension}"""
      __SCREAMING_SNAKE_CASE      							=       str(shared_datadir / f"""test_file.json.{extension}"""    )
      JsonDatasetWriter(_A				,_A				,compression=_A    ).write()

      with fsspec.open(_A				,"""rb"""				,compression="""infer"""    ) as f:
         __SCREAMING_SNAKE_CASE      							=       f.read()
      with fsspec.open(_A				,"""rb"""				,compression="""infer"""    ) as f:
         __SCREAMING_SNAKE_CASE      							=       f.read()
      assert exported_content == original_content












'''simple docstring'''

import requests
from bsa import BeautifulSoup

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase      )						->					str:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       BeautifulSoup(requests.get(__UpperCAmelCase							,	params=__UpperCAmelCase      ).content							,	"""html.parser"""      )
   __SCREAMING_SNAKE_CASE      							=       soup.find("""div"""							,	attrs={"""class""": """gs_ri"""}      )
   __SCREAMING_SNAKE_CASE      							=       div.find("""div"""							,	attrs={"""class""": """gs_fl"""}      ).find_all("""a"""      )
   return anchors[2].get_text()


if __name__ == "__main__":
    a        =						{
        "title": (
            "Precisely geometry controlled microsupercapacitors for ultrahigh areal "
            "capacitance, volumetric capacitance, and energy density"
        ),
        "journal": "Chem. Mater.",
        "volume": 30,
        "pages": "3979-3990",
        "year": 2018,
        "hl": "en",
    }
    print(get_citation("https://scholar.google.com/scholar_lookup", params=params))





