
import pytest

from datasets.splits import SplitDict, SplitInfo
from datasets.utils.py_utils import asdict




@pytest.mark.parametrize(
    """split_dict"""		,   [
        SplitDict(),
        SplitDict({"""train""": SplitInfo(name="""train"""		,   num_bytes=13_37		,   num_examples=42		,   dataset_name="""my_dataset"""       )}       ),
        SplitDict({"""train""": SplitInfo(name="""train"""		,   num_bytes=13_37		,   num_examples=42       )}       ),
        SplitDict({"""train""": SplitInfo()}       ),
    ]		,   )
def 	UpperCamelCase__  (     SCREAMING_SNAKE_CASE_	:	SplitDict       )  ->     Dict:
						_lowercase					       =					split_dict._to_yaml_list()
						assert len(SCREAMING_SNAKE_CASE_       ) == len(SCREAMING_SNAKE_CASE_       )
						_lowercase					       =					SplitDict._from_yaml_list(SCREAMING_SNAKE_CASE_       )
						for split_name, split_info in split_dict.items():
												# dataset_name field is deprecated, and is therefore not part of the YAML dump
												_lowercase					       =					None
												# the split name of split_dict takes over the name of the split info object
												_lowercase					       =					split_name
						assert split_dict == reloaded




@pytest.mark.parametrize(
    """split_info"""		,   [SplitInfo(), SplitInfo(dataset_name=SCREAMING_SNAKE_CASE_       ), SplitInfo(dataset_name="""my_dataset"""       )]       )
def 	UpperCamelCase__  (     SCREAMING_SNAKE_CASE_	:	Optional[Any]       )  ->     Optional[int]:
						# For backward compatibility, we need asdict(split_dict) to return split info dictrionaries with the "dataset_name"
						# field even if it's deprecated. This way old versionso of `datasets` can still reload dataset_infos.json files
						_lowercase					       =					asdict(SplitDict({"""train""": split_info}       )       )
						assert "dataset_name" in split_dict_asdict["train"]
						assert split_dict_asdict["train"]["dataset_name"] == split_info.dataset_name

from __future__ import annotations




def 	UpperCamelCase__  (     SCREAMING_SNAKE_CASE_	:	float		,   SCREAMING_SNAKE_CASE_	:	float		,   SCREAMING_SNAKE_CASE_	:	float		,   )  ->     tuple:
						if (electron_conc, hole_conc, intrinsic_conc).count(0       ) != 1:
												raise ValueError("""You cannot supply more or less than 2 values"""       )
						elif electron_conc < 0:
												raise ValueError("""Electron concentration cannot be negative in a semiconductor"""       )
						elif hole_conc < 0:
												raise ValueError("""Hole concentration cannot be negative in a semiconductor"""       )
						elif intrinsic_conc < 0:
												raise ValueError(
												    """Intrinsic concentration cannot be negative in a semiconductor"""       )
						elif electron_conc == 0:
												return (
												    "electron_conc",
												    intrinsic_conc**2 / hole_conc,
												)
						elif hole_conc == 0:
												return (
												    "hole_conc",
												    intrinsic_conc**2 / electron_conc,
												)
						elif intrinsic_conc == 0:
												return (
												    "intrinsic_conc",
												    (electron_conc * hole_conc) ** 0.5,
												)
						else:
												return (-1, -1)


if __name__ == "__main__":
		import doctest

		doctest.testmod()