
"""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    UpperCamelCase						(					UpperCAmelCase     )						->List[str]:

   """simple docstring"""



   a_						   =     tmp_path / "file.jsonl"
   a_						   =     textwrap.dedent(
       "\\n        {\"col_1\": -1}\n        {\"col_1\": 1, \"col_2\": 2}\n        {\"col_1\": 10, \"col_2\": 20}\n        "     )
   with open(UpperCAmelCase ,   "w"     ) as f:
      f.write(UpperCAmelCase     )
   return str(UpperCAmelCase     )
@pytest.fixture
def    UpperCamelCase						(					UpperCAmelCase     )						->str:

   """simple docstring"""



   a_						   =     tmp_path / "file_utf16_encoded.jsonl"
   a_						   =     textwrap.dedent(
       "\\n        {\"col_1\": -1}\n        {\"col_1\": 1, \"col_2\": 2}\n        {\"col_1\": 10, \"col_2\": 20}\n        "     )
   with open(UpperCAmelCase ,   "w" ,   encoding="utf-16"     ) as f:
      f.write(UpperCAmelCase     )
   return str(UpperCAmelCase     )
@pytest.fixture
def    UpperCamelCase						(					UpperCAmelCase     )						->Any:

   """simple docstring"""



   a_						   =     tmp_path / "file_with_list_of_dicts.json"
   a_						   =     textwrap.dedent(
       "\\n        [\n            {\"col_1\": -1},\n            {\"col_1\": 1, \"col_2\": 2},\n            {\"col_1\": 10, \"col_2\": 20}\n        ]\n        "     )
   with open(UpperCAmelCase ,   "w"     ) as f:
      f.write(UpperCAmelCase     )
   return str(UpperCAmelCase     )
@pytest.fixture
def    UpperCamelCase						(					UpperCAmelCase     )						->int:

   """simple docstring"""



   a_						   =     tmp_path / "file_with_list_of_dicts_field.json"
   a_						   =     textwrap.dedent(
       "\\n        {\n            \"field1\": 1,\n            \"field2\": \"aabb\",\n            \"field3\": [\n                {\"col_1\": -1},\n                {\"col_1\": 1, \"col_2\": 2},\n                {\"col_1\": 10, \"col_2\": 20}\n            ]\n        }\n        "     )
   with open(UpperCAmelCase ,   "w"     ) as f:
      f.write(UpperCAmelCase     )
   return str(UpperCAmelCase     )
@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    UpperCamelCase						(					UpperCAmelCase ,   UpperCAmelCase ,   UpperCAmelCase     )						->Optional[Any]:

   """simple docstring"""



   a_						   =     Json(**UpperCAmelCase     )
   a_						   =     json._generate_tables([[request.getfixturevalue(UpperCAmelCase     )]]     )
   a_						   =     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    UpperCamelCase						(					UpperCAmelCase ,   UpperCAmelCase ,   UpperCAmelCase     )						->Tuple:

   """simple docstring"""



   a_						   =     Json(**UpperCAmelCase     )
   a_						   =     json._generate_tables([[request.getfixturevalue(UpperCAmelCase     )]]     )
   a_						   =     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"""






def    UpperCamelCase						(					UpperCAmelCase ,   UpperCAmelCase = 1_000     )						->str:

   """simple docstring"""



   if (not isinstance(UpperCAmelCase ,   UpperCAmelCase     )) or (digit_position <= 0):
      raise ValueError("Digit position must be a positive integer"     )
   elif (not isinstance(UpperCAmelCase ,   UpperCAmelCase     )) or (precision < 0):
      raise ValueError("Precision must be a nonnegative integer"     )

   # compute an approximation of (16 ** (n - 1)) * pi whose fractional part is mostly
   # accurate
   a_						   =     (
       4 * _subsum(UpperCAmelCase ,   1 ,   UpperCAmelCase     )
       - 2 * _subsum(UpperCAmelCase ,   4 ,   UpperCAmelCase     )
       - _subsum(UpperCAmelCase ,   5 ,   UpperCAmelCase     )
       - _subsum(UpperCAmelCase ,   6 ,   UpperCAmelCase     )
   )

   # return the first hex digit of the fractional part of the result
   return hex(int((sum_result % 1) * 16     )     )[2:]
def    UpperCamelCase						(					UpperCAmelCase ,   UpperCAmelCase ,   UpperCAmelCase     )						->float:

   """simple docstring"""



   a_						   =     0.0
   for sum_index in range(digit_pos_to_extract + precision     ):
      a_						   =     8 * sum_index + denominator_addend
      if sum_index < digit_pos_to_extract:
         # if the exponential term is an integer and we mod it by the denominator
         # before dividing, only the integer part of the sum will change;
         # the fractional part will not
         a_						   =     pow(
             16 ,   digit_pos_to_extract - 1 - sum_index ,   UpperCAmelCase     )
      else:
         a_						   =     pow(16 ,   digit_pos_to_extract - 1 - sum_index     )
      total += exponential_term / denominator
   return total


if __name__ == "__main__":
      import doctest

      doctest.testmod()