




'''simple docstring'''






import textwrap

import pyarrow as pa
import pytest

from datasets import Features, Value
from datasets.packaged_modules.json.json import Json




@pytest.fixture
def 		a_( lowerCamelCase      )				->str:






       '''simple docstring'''




       lowercase  :		str						=      tmp_path / '''file.jsonl'''
       lowercase  :		str						=      textwrap.dedent(
           '''\
        {"col_1": -1}
        {"col_1": 1, "col_2": 2}
        {"col_1": 10, "col_2": 20}
        '''      )
       with open(lowerCamelCase   ,				'''w'''      ) as f:
              f.write(lowerCamelCase      )
       return str(lowerCamelCase      )




@pytest.fixture
def 		a_( lowerCamelCase      )				->Optional[int]:






       '''simple docstring'''




       lowercase  :		Tuple						=      tmp_path / '''file_utf16_encoded.jsonl'''
       lowercase  :		Optional[Any]						=      textwrap.dedent(
           '''\
        {"col_1": -1}
        {"col_1": 1, "col_2": 2}
        {"col_1": 10, "col_2": 20}
        '''      )
       with open(lowerCamelCase   ,				'''w'''   ,				encoding='''utf-16'''      ) as f:
              f.write(lowerCamelCase      )
       return str(lowerCamelCase      )




@pytest.fixture
def 		a_( lowerCamelCase      )				->Union[str, Any]:






       '''simple docstring'''




       lowercase  :		int						=      tmp_path / '''file_with_list_of_dicts.json'''
       lowercase  :		List[str]						=      textwrap.dedent(
           '''\
        [
            {"col_1": -1},
            {"col_1": 1, "col_2": 2},
            {"col_1": 10, "col_2": 20}
        ]
        '''      )
       with open(lowerCamelCase   ,				'''w'''      ) as f:
              f.write(lowerCamelCase      )
       return str(lowerCamelCase      )




@pytest.fixture
def 		a_( lowerCamelCase      )				->Dict:






       '''simple docstring'''




       lowercase  :		List[Any]						=      tmp_path / '''file_with_list_of_dicts_field.json'''
       lowercase  :		Union[str, Any]						=      textwrap.dedent(
           '''\
        {
            "field1": 1,
            "field2": "aabb",
            "field3": [
                {"col_1": -1},
                {"col_1": 1, "col_2": 2},
                {"col_1": 10, "col_2": 20}
            ]
        }
        '''      )
       with open(lowerCamelCase   ,				'''w'''      ) as f:
              f.write(lowerCamelCase      )
       return str(lowerCamelCase      )




@pytest.mark.parametrize(
    '''file_fixture, config_kwargs'''   ,				[
        ('''jsonl_file''', {}),
        ('''jsonl_file_utf16_encoded''', {'''encoding''': '''utf-16'''}),
        ('''json_file_with_list_of_dicts''', {}),
        ('''json_file_with_list_of_dicts_field''', {'''field''': '''field3'''}),
    ]   ,				)
def 		a_( lowerCamelCase   ,				lowerCamelCase   ,				lowerCamelCase      )				->str:






       '''simple docstring'''




       lowercase  :		Dict						=      Json(**lowerCamelCase      )
       lowercase  :		str						=      json._generate_tables([[request.getfixturevalue(lowerCamelCase      )]]      )
       lowercase  :		Tuple						=      pa.concat_tables([table for _, table in generator]      )
       assert pa_table.to_pydict() == {"col_1": [-1, 1, 10], "col_2": [None, 2, 20]}





@pytest.mark.parametrize(
    '''file_fixture, config_kwargs'''   ,				[
        (
            '''jsonl_file''',
            {'''features''': Features({'''col_1''': Value('''int64'''      ), '''col_2''': Value('''int64'''      ), '''missing_col''': Value('''string'''      )}      )},
        ),
        (
            '''json_file_with_list_of_dicts''',
            {'''features''': Features({'''col_1''': Value('''int64'''      ), '''col_2''': Value('''int64'''      ), '''missing_col''': Value('''string'''      )}      )},
        ),
        (
            '''json_file_with_list_of_dicts_field''',
            {
                '''field''': '''field3''',
                '''features''': Features(
                    {'''col_1''': Value('''int64'''      ), '''col_2''': Value('''int64'''      ), '''missing_col''': Value('''string'''      )}      ),
            },
        ),
    ]   ,				)
def 		a_( lowerCamelCase   ,				lowerCamelCase   ,				lowerCamelCase      )				->Optional[int]:






       '''simple docstring'''




       lowercase  :		List[str]						=      Json(**lowerCamelCase      )
       lowercase  :		List[Any]						=      json._generate_tables([[request.getfixturevalue(lowerCamelCase      )]]      )
       lowercase  :		str						=      pa.concat_tables([table for _, table in generator]      )
       assert pa_table.to_pydict() == {"col_1": [-1, 1, 10], "col_2": [None, 2, 20], "missing_col": [None, None, None]}










'''simple docstring'''






import math
from timeit import timeit




def 		a_( lowerCamelCase      )				->int:






       '''simple docstring'''




       lowercase  :		Dict						=      0
       lowercase  :		Union[str, Any]						=      abs(lowerCamelCase      )
       while True:
              lowercase  :		List[Any]						=      n // 10
              digits += 1
              if n == 0:
                     break
       return digits




def 		a_( lowerCamelCase      )				->int:






       '''simple docstring'''




       return 1 if n == 0 else math.floor(math.log(abs(lowerCamelCase      )   ,				10      ) + 1      )




def 		a_( lowerCamelCase      )				->int:






       '''simple docstring'''




       return len(str(abs(lowerCamelCase      )      )      )




def 		a_( )				->None:






       '''simple docstring'''




       from collections.abc import Callable

       def benchmark_a_function(lowerCamelCase   ,				lowerCamelCase      ) -> None:
              lowercase  :		str						=      f"""{func.__name__}({value})"""
              lowercase  :		Optional[Any]						=      timeit(f"""__main__.{call}"""   ,				setup='''import __main__'''      )
              print(f"""{call}: {func(lowerCamelCase      )} -- {timing} seconds"""      )

       for value in (26_2144, 1125_8999_0684_2624, 126_7650_6002_2822_9401_4967_0320_5376):
              for func in (num_digits, num_digits_fast, num_digits_faster):
                     benchmark_a_function(lowerCamelCase   ,				lowerCamelCase      )
              print()


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      benchmark()




