


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_							,UpperCamelCase_    ):



     """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       UpperCAmelCase__						(UpperCamelCase_							,UpperCamelCase_							,UpperCamelCase_    ):



     """simple docstring"""






     snake_case					=    tmp_path / '''cache'''
     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():
          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       UpperCAmelCase__						(UpperCamelCase_							,UpperCamelCase_							,UpperCamelCase_    ):



     """simple docstring"""






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



     """simple docstring"""






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



     """simple docstring"""






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



     """simple docstring"""






     snake_case					=    tmp_path / '''cache'''
     snake_case					=    {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
     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       UpperCAmelCase__						(UpperCamelCase_							,UpperCamelCase_							,UpperCamelCase_    ):



     """simple docstring"""






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



     """simple docstring"""






     assert isinstance(UpperCamelCase_							,UpperCamelCase_    )
     for split in splits:
          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       UpperCAmelCase__						(UpperCamelCase_							,UpperCamelCase_							,UpperCamelCase_    ):



     """simple docstring"""






     snake_case					=    tmp_path / '''cache'''
     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():
          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       UpperCAmelCase__						(UpperCamelCase_							,UpperCamelCase_							,UpperCamelCase_    ):



     """simple docstring"""






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



     """simple docstring"""






     if split:
          snake_case					=    {split: jsonl_path}
     else:
          snake_case					=    '''train'''
          snake_case					=    {'''train''': jsonl_path, '''test''': jsonl_path}
     snake_case					=    tmp_path / '''cache'''
     snake_case					=    {'''col_1''': '''string''', '''col_2''': '''int64''', '''col_3''': '''float64'''}
     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       UpperCAmelCase__						(UpperCamelCase_    ):



     """simple docstring"""






     return json.load(UpperCamelCase_    )
def       UpperCAmelCase__						(UpperCamelCase_    ):



     """simple docstring"""






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

class   A__ :







    """simple docstring"""

    @pytest.mark.parametrize('''lines, load_json_function'''      , [(True, load_json_lines), (False, load_json)]   )
    def 		a_      (	self      , __snake_case      , __snake_case      , __snake_case   ):
         with io.BytesIO() as buffer:
              JsonDatasetWriter(__snake_case      , __snake_case      , lines=__snake_case   ).write()
              buffer.seek(0   )
              snake_case					=    load_json_function(__snake_case   )
         assert isinstance(__snake_case      , __snake_case   )
         assert isinstance(exported_content[0]      , __snake_case   )
         assert len(__snake_case   ) == 1_0
    @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 		a_      (	self      , __snake_case      , __snake_case      , __snake_case      , __snake_case      , __snake_case   ):
         with io.BytesIO() as buffer:
              JsonDatasetWriter(__snake_case      , __snake_case      , lines=__snake_case      , orient=__snake_case   ).write()
              buffer.seek(0   )
              snake_case					=    load_json(__snake_case   )
         assert isinstance(__snake_case      , __snake_case   )
         if keys:
              if container is dict:
                   assert exported_content.keys() == keys
              else:
                   assert exported_content[0].keys() == keys
         else:
              assert not hasattr(__snake_case      , '''keys'''   ) and not hasattr(exported_content[0]      , '''keys'''   )
         if len_at:
              assert len(exported_content[len_at]   ) == 1_0
         else:
              assert len(__snake_case   ) == 1_0
    @pytest.mark.parametrize('''lines, load_json_function'''      , [(True, load_json_lines), (False, load_json)]   )
    def 		a_      (	self      , __snake_case      , __snake_case      , __snake_case   ):
         with io.BytesIO() as buffer:
              JsonDatasetWriter(__snake_case      , __snake_case      , lines=__snake_case      , num_proc=2   ).write()
              buffer.seek(0   )
              snake_case					=    load_json_function(__snake_case   )
         assert isinstance(__snake_case      , __snake_case   )
         assert isinstance(exported_content[0]      , __snake_case   )
         assert len(__snake_case   ) == 1_0
    @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 		a_      (	self      , __snake_case      , __snake_case      , __snake_case      , __snake_case      , __snake_case   ):
         with io.BytesIO() as buffer:
              JsonDatasetWriter(__snake_case      , __snake_case      , lines=__snake_case      , orient=__snake_case      , num_proc=2   ).write()
              buffer.seek(0   )
              snake_case					=    load_json(__snake_case   )
         assert isinstance(__snake_case      , __snake_case   )
         if keys:
              if container is dict:
                   assert exported_content.keys() == keys
              else:
                   assert exported_content[0].keys() == keys
         else:
              assert not hasattr(__snake_case      , '''keys'''   ) and not hasattr(exported_content[0]      , '''keys'''   )
         if len_at:
              assert len(exported_content[len_at]   ) == 1_0
         else:
              assert len(__snake_case   ) == 1_0
    def 		a_      (	self      , __snake_case   ):
         with pytest.raises(__snake_case   ):
              with io.BytesIO() as buffer:
                   JsonDatasetWriter(__snake_case      , __snake_case      , num_proc=0   )




    @pytest.mark.parametrize('''compression, extension'''      , [('''gzip''', '''gz'''), ('''bz2''', '''bz2'''), ('''xz''', '''xz''')]   )
    def 		a_      (	self      , __snake_case      , __snake_case      , __snake_case      , __snake_case      , __snake_case   ):
         snake_case					=    tmp_path_factory.mktemp('''data'''   ) / F'''test.json.{extension}'''
         snake_case					=    str(shared_datadir / F'''test_file.json.{extension}'''   )
         JsonDatasetWriter(__snake_case      , __snake_case      , compression=__snake_case   ).write()

         with fsspec.open(__snake_case      , '''rb'''      , compression='''infer'''   ) as f:
              snake_case					=    f.read()
         with fsspec.open(__snake_case      , '''rb'''      , compression='''infer'''   ) as f:
              snake_case					=    f.read()
         assert exported_content == original_content








from __future__ import annotations

from collections.abc import Generator

import requests
from bsa import BeautifulSoup

_SCREAMING_SNAKE_CASE      :			str      				=   "https://www.indeed.co.in/jobs?q=mobile+app+development&l="
def       UpperCAmelCase__						(UpperCamelCase_ = "mumbai"    ):



     """simple docstring"""






     snake_case					=    BeautifulSoup(requests.get(url + location    ).content							,'''html.parser'''    )
     # This attribute finds out all the specifics listed in a job
     for job in soup.find_all('''div'''							,attrs={'''data-tn-component''': '''organicJob'''}    ):
          snake_case					=    job.find('''a'''							,attrs={'''data-tn-element''': '''jobTitle'''}    ).text.strip()
          snake_case					=    job.find('''span'''							,{'''class''': '''company'''}    ).text.strip()
          yield job_title, company_name


if __name__ == "__main__":
 for i, job in enumerate(fetch_jobs("Bangalore"), 1):
  print(f'''Job {i:>2} is {job[0]} at {job[1]}''')




