






"""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   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	str:
    """simple docstring"""

    assert isinstance(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE					)
    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   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	str:
    """simple docstring"""

    UpperCamelCase__         =    tmp_path / 'cache'
    UpperCamelCase__         =    {'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__         =    JsonDatasetReader(_SCREAMING_SNAKE_CASE ,	cache_dir=_SCREAMING_SNAKE_CASE ,	keep_in_memory=_SCREAMING_SNAKE_CASE					).read()
    _check_json_dataset(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE					)







@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   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	List[str]:
    """simple docstring"""

    UpperCamelCase__         =    tmp_path / 'cache'
    UpperCamelCase__         =    {'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
    UpperCamelCase__         =    features.copy() if features else default_expected_features
    UpperCamelCase__         =    (
        Features({feature: Value(_SCREAMING_SNAKE_CASE					) for feature, dtype in features.items()}					) if features is not None else None
    )
    UpperCamelCase__         =    JsonDatasetReader(_SCREAMING_SNAKE_CASE ,	features=_SCREAMING_SNAKE_CASE ,	cache_dir=_SCREAMING_SNAKE_CASE					).read()
    _check_json_dataset(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE					)







@pytest.mark.parametrize(
    'features' ,	[
        None,
        {'col_3': 'float64', 'col_1': 'string', 'col_2': 'int64'},
    ] ,	)
def   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	List[Any]:
    """simple docstring"""

    UpperCamelCase__         =    tmp_path / 'cache'
    UpperCamelCase__         =    {'col_3': 'float64', 'col_1': 'string', 'col_2': 'int64'}
    UpperCamelCase__         =    features.copy() if features else default_expected_features
    UpperCamelCase__         =    (
        Features({feature: Value(_SCREAMING_SNAKE_CASE					) for feature, dtype in features.items()}					) if features is not None else None
    )
    UpperCamelCase__         =    JsonDatasetReader(_SCREAMING_SNAKE_CASE ,	features=_SCREAMING_SNAKE_CASE ,	cache_dir=_SCREAMING_SNAKE_CASE					).read()
    assert isinstance(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE					)
    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   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	Tuple:
    """simple docstring"""

    UpperCamelCase__         =    {'col_2': 'int64', 'col_3': 'float64', 'col_1': 'string'}
    UpperCamelCase__         =    features.copy()
    UpperCamelCase__         =    (
        Features({feature: Value(_SCREAMING_SNAKE_CASE					) for feature, dtype in features.items()}					) if features is not None else None
    )
    UpperCamelCase__         =    tmp_path / 'cache'
    UpperCamelCase__         =    JsonDatasetReader(_SCREAMING_SNAKE_CASE ,	features=_SCREAMING_SNAKE_CASE ,	cache_dir=_SCREAMING_SNAKE_CASE					).read()
    assert isinstance(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE					)
    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   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	Optional[int]:
    """simple docstring"""

    UpperCamelCase__         =    tmp_path / 'cache'
    UpperCamelCase__         =    {'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
    UpperCamelCase__         =    JsonDatasetReader(_SCREAMING_SNAKE_CASE ,	cache_dir=_SCREAMING_SNAKE_CASE ,	split=_SCREAMING_SNAKE_CASE					).read()
    _check_json_dataset(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE					)
    assert dataset.split == split if split else "train"







@pytest.mark.parametrize('path_type' ,	[str, list]					)
def   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	List[str]:
    """simple docstring"""

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







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE=("train",)					)					->	int:
    """simple docstring"""

    assert isinstance(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE					)
    for split in splits:
        UpperCamelCase__         =    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   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	Optional[Any]:
    """simple docstring"""

    UpperCamelCase__         =    tmp_path / 'cache'
    UpperCamelCase__         =    {'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__         =    JsonDatasetReader({'train': jsonl_path} ,	cache_dir=_SCREAMING_SNAKE_CASE ,	keep_in_memory=_SCREAMING_SNAKE_CASE					).read()
    _check_json_datasetdict(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE					)







@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   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	Any:
    """simple docstring"""

    UpperCamelCase__         =    tmp_path / 'cache'
    UpperCamelCase__         =    {'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
    UpperCamelCase__         =    features.copy() if features else default_expected_features
    UpperCamelCase__         =    (
        Features({feature: Value(_SCREAMING_SNAKE_CASE					) for feature, dtype in features.items()}					) if features is not None else None
    )
    UpperCamelCase__         =    JsonDatasetReader({'train': jsonl_path} ,	features=_SCREAMING_SNAKE_CASE ,	cache_dir=_SCREAMING_SNAKE_CASE					).read()
    _check_json_datasetdict(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE					)







@pytest.mark.parametrize('split' ,	[None, NamedSplit('train'					), 'train', 'test']					)
def   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	Tuple:
    """simple docstring"""

    if split:
        UpperCamelCase__         =    {split: jsonl_path}
    else:
        UpperCamelCase__         =    'train'
        UpperCamelCase__         =    {'train': jsonl_path, 'test': jsonl_path}
    UpperCamelCase__         =    tmp_path / 'cache'
    UpperCamelCase__         =    {'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
    UpperCamelCase__         =    JsonDatasetReader(_SCREAMING_SNAKE_CASE ,	cache_dir=_SCREAMING_SNAKE_CASE					).read()
    _check_json_datasetdict(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	splits=list(path.keys()					)					)
    assert all(dataset[split].split == split for split in path.keys()					)







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE					)					->	str:
    """simple docstring"""

    return json.load(_SCREAMING_SNAKE_CASE					)







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE					)					->	List[Any]:
    """simple docstring"""

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





class    __lowerCamelCase    :

   '''simple docstring'''





   @pytest.mark.parametrize('lines, load_json_function' ,				[(True, load_json_lines), (False, load_json)]      )
   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_      )		->       Optional[int]:







       with io.BytesIO() as buffer:
           JsonDatasetWriter(snake_case_ ,				snake_case_ ,				lines=snake_case_      ).write()
           buffer.seek(0      )
           UpperCamelCase__         =    load_json_function(snake_case_      )
       assert isinstance(snake_case_ ,				snake_case_      )
       assert isinstance(exported_content[0] ,				snake_case_      )
       assert len(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 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_      )		->       List[str]:







       with io.BytesIO() as buffer:
           JsonDatasetWriter(snake_case_ ,				snake_case_ ,				lines=snake_case_ ,				orient=snake_case_      ).write()
           buffer.seek(0      )
           UpperCamelCase__         =    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]      ) == 10
       else:
           assert len(snake_case_      ) == 10

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







       with io.BytesIO() as buffer:
           JsonDatasetWriter(snake_case_ ,				snake_case_ ,				lines=snake_case_ ,				num_proc=2      ).write()
           buffer.seek(0      )
           UpperCamelCase__         =    load_json_function(snake_case_      )
       assert isinstance(snake_case_ ,				snake_case_      )
       assert isinstance(exported_content[0] ,				snake_case_      )
       assert len(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 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_      )		->       List[str]:







       with io.BytesIO() as buffer:
           JsonDatasetWriter(snake_case_ ,				snake_case_ ,				lines=snake_case_ ,				orient=snake_case_ ,				num_proc=2      ).write()
           buffer.seek(0      )
           UpperCamelCase__         =    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]      ) == 10
       else:
           assert len(snake_case_      ) == 10

   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_      )		->       List[str]:







       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 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_      )		->       Dict:
       UpperCamelCase__         =    tmp_path_factory.mktemp('data'      ) / F'test.json.{extension}'
       UpperCamelCase__         =    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:
           UpperCamelCase__         =    f.read()
       with fsspec.open(snake_case_ ,				'rb' ,				compression='infer'      ) as f:
           UpperCamelCase__         =    f.read()
       assert exported_content == original_content












"""simple docstring"""





def   lowerCAmelCase_( SCREAMING_SNAKE_CASE = 50_00_00_00					)					->	int:
    """simple docstring"""

    UpperCamelCase__         =    set()
    UpperCamelCase__         =    int((limit - 24) ** (1 / 2)					)

    UpperCamelCase__         =    set(range(3 ,	prime_square_limit + 1 ,	2					)					)
    primes.add(2					)
    for p in range(3 ,	prime_square_limit + 1 ,	2					):
        if p not in primes:
            continue
        primes.difference_update(set(range(p * p ,	prime_square_limit + 1 ,	SCREAMING_SNAKE_CASE					)					)					)

    for primea in primes:
        UpperCamelCase__         =    primea * primea
        for primea in primes:
            UpperCamelCase__         =    primea * primea * primea
            if square + cube >= limit - 16:
                break
            for primea in primes:
                UpperCamelCase__         =    primea * primea * primea * primea
                UpperCamelCase__         =    square + cube + tetr
                if total >= limit:
                    break
                ret.add(SCREAMING_SNAKE_CASE					)

    return len(SCREAMING_SNAKE_CASE					)


if __name__ == "__main__":
  print(F"""{solution() = }""")




