

'''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 					_SCREAMING_SNAKE_CASE		(						snake_case_	):
	_lowercase							=     tmp_path / """file.jsonl"""
	_lowercase							=     textwrap.dedent(
	    """\
        {\"col_1\": -1}
        {\"col_1\": 1, \"col_2\": 2}
        {\"col_1\": 10, \"col_2\": 20}
        """	)
	with open(snake_case_							,       """w"""	) as f:
		f.write(snake_case_	)
	return str(snake_case_	)






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






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






@pytest.fixture
def 					_SCREAMING_SNAKE_CASE		(						snake_case_	):
	_lowercase							=     tmp_path / """file_with_list_of_dicts_field.json"""
	_lowercase							=     textwrap.dedent(
	    """\
        {
            \"field1\": 1,
            \"field2\": \"aabb\",
            \"field3\": [
                {\"col_1\": -1},
                {\"col_1\": 1, \"col_2\": 2},
                {\"col_1\": 10, \"col_2\": 20}
            ]
        }
        """	)
	with open(snake_case_							,       """w"""	) as f:
		f.write(snake_case_	)
	return str(snake_case_	)






@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 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_							,       snake_case_	):
	_lowercase							=     Json(**snake_case_	)
	_lowercase							=     json._generate_tables([[request.getfixturevalue(snake_case_	)]]	)
	_lowercase							=     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 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_							,       snake_case_	):
	_lowercase							=     Json(**snake_case_	)
	_lowercase							=     json._generate_tables([[request.getfixturevalue(snake_case_	)]]	)
	_lowercase							=     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'''







from collections import namedtuple

_lowerCamelCase    =  namedtuple('from_to', 'from_ to')

_lowerCamelCase    =  {
    'millimeter': 'mm',
    'centimeter': 'cm',
    'meter': 'm',
    'kilometer': 'km',
    'inch': 'in',
    'inche': 'in',  # Trailing 's' has been stripped off
    'feet': 'ft',
    'foot': 'ft',
    'yard': 'yd',
    'mile': 'mi',
}

_lowerCamelCase    =  {
    'mm': from_to(0.001, 1_0_0_0),
    'cm': from_to(0.01, 1_0_0),
    'm': from_to(1, 1),
    'km': from_to(1_0_0_0, 0.001),
    'in': from_to(0.0254, 39.3701),
    'ft': from_to(0.3048, 3.2_8084),
    'yd': from_to(0.9144, 1.0_9361),
    'mi': from_to(1609.34, 0.0_0062_1371),
}






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_							,       snake_case_	):
	_lowercase							=     from_type.lower().rstrip("""s"""	)
	_lowercase							=     TYPE_CONVERSION.get(snake_case_							,       snake_case_	)
	_lowercase							=     to_type.lower().rstrip("""s"""	)
	_lowercase							=     TYPE_CONVERSION.get(snake_case_							,       snake_case_	)
	if new_from not in METRIC_CONVERSION:
		_lowercase							=     (
		    F"""Invalid 'from_type' value: {from_type!r}.\n"""
		    F"""Conversion abbreviations are: {", ".join(snake_case_	)}"""
		)
		raise ValueError(snake_case_	)
	if new_to not in METRIC_CONVERSION:
		_lowercase							=     (
		    F"""Invalid 'to_type' value: {to_type!r}.\n"""
		    F"""Conversion abbreviations are: {", ".join(snake_case_	)}"""
		)
		raise ValueError(snake_case_	)
	return value * METRIC_CONVERSION[new_from].from_ * METRIC_CONVERSION[new_to].to


if __name__ == "__main__":
							import doctest

							doctest.testmod()




