






"""simple docstring"""





import os
import tempfile
from functools import partial
from unittest import TestCase
from unittest.mock import patch

import datasets
import datasets.config

from .utils import require_beam






class 	a		(   datasets.BeamBasedBuilder						):






    def   UpperCamelCase			(			self	:				Dict   )	->						Dict:
      return datasets.DatasetInfo(
          features=datasets.Features({'content': datasets.Value('string'   )}   )			,		supervised_keys=__SCREAMING_SNAKE_CASE			,		)






    def   UpperCamelCase			(			self	:				int			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				int   )	->						Union[str, Any]:
      return [datasets.SplitGenerator(name=datasets.Split.TRAIN			,		gen_kwargs={'examples': get_test_dummy_examples()}   )]






    def   UpperCamelCase			(			self	:				Optional[Any]			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]   )	->						Optional[Any]:
      import apache_beam as beam

      return pipeline | "Load Examples" >> beam.Create(__SCREAMING_SNAKE_CASE   )






class 	a		(   datasets.BeamBasedBuilder						):






    def   UpperCamelCase			(			self	:				Tuple   )	->						List[Any]:
      return datasets.DatasetInfo(
          features=datasets.Features({'a': datasets.Sequence({'b': datasets.Value('string'   )}   )}   )			,		supervised_keys=__SCREAMING_SNAKE_CASE			,		)






    def   UpperCamelCase			(			self	:				Dict			,		__SCREAMING_SNAKE_CASE	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				int   )	->						int:
      return [
          datasets.SplitGenerator(name=datasets.Split.TRAIN			,		gen_kwargs={'examples': get_test_nested_examples()}   )
      ]






    def   UpperCamelCase			(			self	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				Any   )	->						Union[str, Any]:
      import apache_beam as beam

      return pipeline | "Load Examples" >> beam.Create(__SCREAMING_SNAKE_CASE   )







def 	lowerCamelCase__			(				) ->							Dict:
  return [(i, {"content": content}) for i, content in enumerate(['foo', 'bar', 'foobar']					)]







def 	lowerCamelCase__			(				) ->							Tuple:
  return [(i, {"a": {"b": [content]}}) for i, content in enumerate(['foo', 'bar', 'foobar']					)]






class 	a		(   __snake_case						):






    @require_beam
    def   UpperCamelCase			(			self	:				str   )	->						str:
      lowerCamelCase_       	=		len(get_test_dummy_examples()   )
      with tempfile.TemporaryDirectory() as tmp_cache_dir:
        lowerCamelCase_       	=		DummyBeamDataset(cache_dir=__SCREAMING_SNAKE_CASE			,		beam_runner='DirectRunner'   )
        builder.download_and_prepare()
        self.assertTrue(
            os.path.exists(
                os.path.join(__SCREAMING_SNAKE_CASE			,		builder.name			,		'default'			,		'0.0.0'			,		F'''{builder.name}-train.arrow'''   )   )   )
        self.assertDictEqual(builder.info.features			,		datasets.Features({'content': datasets.Value('string'   )}   )   )
        lowerCamelCase_       	=		builder.as_dataset()
        self.assertEqual(dset['train'].num_rows			,		__SCREAMING_SNAKE_CASE   )
        self.assertEqual(dset['train'].info.splits['train'].num_examples			,		__SCREAMING_SNAKE_CASE   )
        self.assertDictEqual(dset['train'][0]			,		get_test_dummy_examples()[0][1]   )
        self.assertDictEqual(
            dset['train'][expected_num_examples - 1]			,		get_test_dummy_examples()[expected_num_examples - 1][1]   )
        self.assertTrue(
            os.path.exists(os.path.join(__SCREAMING_SNAKE_CASE			,		builder.name			,		'default'			,		'0.0.0'			,		'dataset_info.json'   )   )   )
        del dset






    @require_beam
    def   UpperCamelCase			(			self	:				Optional[Any]   )	->						Tuple:
      import apache_beam as beam

      lowerCamelCase_       	=		beam.io.parquetio.WriteToParquet

      lowerCamelCase_       	=		len(get_test_dummy_examples()   )
      with tempfile.TemporaryDirectory() as tmp_cache_dir:
        lowerCamelCase_       	=		DummyBeamDataset(cache_dir=__SCREAMING_SNAKE_CASE			,		beam_runner='DirectRunner'   )
        with patch('apache_beam.io.parquetio.WriteToParquet'   ) as write_parquet_mock:
          lowerCamelCase_       	=		partial(__SCREAMING_SNAKE_CASE			,		num_shards=2   )
          builder.download_and_prepare()
        self.assertTrue(
            os.path.exists(
                os.path.join(
                    __SCREAMING_SNAKE_CASE			,		builder.name			,		'default'			,		'0.0.0'			,		F'''{builder.name}-train-00000-of-00002.arrow'''   )   )   )
        self.assertTrue(
            os.path.exists(
                os.path.join(
                    __SCREAMING_SNAKE_CASE			,		builder.name			,		'default'			,		'0.0.0'			,		F'''{builder.name}-train-00000-of-00002.arrow'''   )   )   )
        self.assertDictEqual(builder.info.features			,		datasets.Features({'content': datasets.Value('string'   )}   )   )
        lowerCamelCase_       	=		builder.as_dataset()
        self.assertEqual(dset['train'].num_rows			,		__SCREAMING_SNAKE_CASE   )
        self.assertEqual(dset['train'].info.splits['train'].num_examples			,		__SCREAMING_SNAKE_CASE   )
        # Order is not preserved when sharding, so we just check that all the elements are there
        self.assertListEqual(sorted(dset['train']['content']   )			,		sorted(['foo', 'bar', 'foobar']   )   )
        self.assertTrue(
            os.path.exists(os.path.join(__SCREAMING_SNAKE_CASE			,		builder.name			,		'default'			,		'0.0.0'			,		'dataset_info.json'   )   )   )
        del dset






    @require_beam
    def   UpperCamelCase			(			self	:				int   )	->						str:
      with tempfile.TemporaryDirectory() as tmp_cache_dir:
        lowerCamelCase_       	=		DummyBeamDataset(cache_dir=__SCREAMING_SNAKE_CASE   )
        self.assertRaises(datasets.builder.MissingBeamOptions			,		builder.download_and_prepare   )






    @require_beam
    def   UpperCamelCase			(			self	:				List[str]   )	->						str:
      lowerCamelCase_       	=		len(get_test_nested_examples()   )
      with tempfile.TemporaryDirectory() as tmp_cache_dir:
        lowerCamelCase_       	=		NestedBeamDataset(cache_dir=__SCREAMING_SNAKE_CASE			,		beam_runner='DirectRunner'   )
        builder.download_and_prepare()
        self.assertTrue(
            os.path.exists(
                os.path.join(__SCREAMING_SNAKE_CASE			,		builder.name			,		'default'			,		'0.0.0'			,		F'''{builder.name}-train.arrow'''   )   )   )
        self.assertDictEqual(
            builder.info.features			,		datasets.Features({'a': datasets.Sequence({'b': datasets.Value('string'   )}   )}   )   )
        lowerCamelCase_       	=		builder.as_dataset()
        self.assertEqual(dset['train'].num_rows			,		__SCREAMING_SNAKE_CASE   )
        self.assertEqual(dset['train'].info.splits['train'].num_examples			,		__SCREAMING_SNAKE_CASE   )
        self.assertDictEqual(dset['train'][0]			,		get_test_nested_examples()[0][1]   )
        self.assertDictEqual(
            dset['train'][expected_num_examples - 1]			,		get_test_nested_examples()[expected_num_examples - 1][1]   )
        self.assertTrue(
            os.path.exists(os.path.join(__SCREAMING_SNAKE_CASE			,		builder.name			,		'default'			,		'0.0.0'			,		'dataset_info.json'   )   )   )
        del dset












"""simple docstring"""





_SCREAMING_SNAKE_CASE   :							Optional[int]          =		8.314_4598







def 	lowerCamelCase__			(				_lowerCamelCase			:						float						,							_lowerCamelCase			:						float					) ->							float:
  if temperature < 0:
    raise Exception('Temperature cannot be less than 0 K'					)
  if molar_mass <= 0:
    raise Exception('Molar mass cannot be less than or equal to 0 kg/mol'					)
  else:
    return (3 * UNIVERSAL_GAS_CONSTANT * temperature / molar_mass) ** 0.5


if __name__ == "__main__":
  import doctest

  # run doctest
  doctest.testmod()

  # example
  _SCREAMING_SNAKE_CASE   :							List[Any]          =		300
  _SCREAMING_SNAKE_CASE   :							Dict          =		28
  _SCREAMING_SNAKE_CASE   :							List[str]          =		rms_speed_of_molecule(temperature, molar_mass)
  print(F'''Vrms of Nitrogen gas at 300 K is {vrms} m/s''')




