






"""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      _lowercase (     datasets.BeamBasedBuilder						):


      def _UpperCamelCase						(    self				:	Union[str, Any]						):





            """simple docstring"""







            return datasets.DatasetInfo(
                features=datasets.Features({'''content''': datasets.Value('''string'''						)}						)							,   supervised_keys=a							,   )


      def _UpperCamelCase						(    self				:	int							,   a				:	Tuple							,   a				:	int						):





            """simple docstring"""







            return [datasets.SplitGenerator(name=datasets.Split.TRAIN							,   gen_kwargs={'''examples''': get_test_dummy_examples()}						)]







      def _UpperCamelCase						(    self				:	Dict							,   a				:	Tuple							,   a				:	List[str]						):





            """simple docstring"""







            import apache_beam as beam

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



class      _lowercase (     datasets.BeamBasedBuilder						):


      def _UpperCamelCase						(    self				:	List[Any]						):





            """simple docstring"""







            return datasets.DatasetInfo(
                features=datasets.Features({'''a''': datasets.Sequence({'''b''': datasets.Value('''string'''						)}						)}						)							,   supervised_keys=a							,   )


      def _UpperCamelCase						(    self				:	Union[str, Any]							,   a				:	List[Any]							,   a				:	Tuple						):





            """simple docstring"""







            return [
                datasets.SplitGenerator(name=datasets.Split.TRAIN							,   gen_kwargs={'''examples''': get_test_nested_examples()}						)
            ]







      def _UpperCamelCase						(    self				:	Any							,   a				:	Any							,   a				:	Optional[int]						):





            """simple docstring"""







            import apache_beam as beam

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



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



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


class      _lowercase (     lowerCAmelCase						):


      @require_beam
      def _UpperCamelCase						(    self				:	Any						):





            """simple docstring"""







            __snake_case      :    Union[str, Any]  			=len(get_test_dummy_examples()						)
            with tempfile.TemporaryDirectory() as tmp_cache_dir:
                  __snake_case      :    int  			=DummyBeamDataset(cache_dir=a							,   beam_runner='''DirectRunner'''						)
                  builder.download_and_prepare()
                  self.assertTrue(
                      os.path.exists(
                          os.path.join(a							,   builder.name							,   '''default'''							,   '''0.0.0'''							,   f'''{builder.name}-train.arrow'''						)						)						)
                  self.assertDictEqual(builder.info.features							,   datasets.Features({'''content''': datasets.Value('''string'''						)}						)						)
                  __snake_case      :    Dict  			=builder.as_dataset()
                  self.assertEqual(dset['''train'''].num_rows							,   a						)
                  self.assertEqual(dset['''train'''].info.splits['''train'''].num_examples							,   a						)
                  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(a							,   builder.name							,   '''default'''							,   '''0.0.0'''							,   '''dataset_info.json'''						)						)						)
                  del dset


      @require_beam
      def _UpperCamelCase						(    self				:	Optional[int]						):





            """simple docstring"""







            import apache_beam as beam

            __snake_case      :    Union[str, Any]  			=beam.io.parquetio.WriteToParquet

            __snake_case      :    Optional[Any]  			=len(get_test_dummy_examples()						)
            with tempfile.TemporaryDirectory() as tmp_cache_dir:
                  __snake_case      :    List[Any]  			=DummyBeamDataset(cache_dir=a							,   beam_runner='''DirectRunner'''						)
                  with patch('''apache_beam.io.parquetio.WriteToParquet'''						) as write_parquet_mock:
                        __snake_case      :    int  			=partial(a							,   num_shards=2						)
                        builder.download_and_prepare()
                  self.assertTrue(
                      os.path.exists(
                          os.path.join(
                              a							,   builder.name							,   '''default'''							,   '''0.0.0'''							,   f'''{builder.name}-train-00000-of-00002.arrow'''						)						)						)
                  self.assertTrue(
                      os.path.exists(
                          os.path.join(
                              a							,   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'''						)}						)						)
                  __snake_case      :    Dict  			=builder.as_dataset()
                  self.assertEqual(dset['''train'''].num_rows							,   a						)
                  self.assertEqual(dset['''train'''].info.splits['''train'''].num_examples							,   a						)
                  # 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(a							,   builder.name							,   '''default'''							,   '''0.0.0'''							,   '''dataset_info.json'''						)						)						)
                  del dset


      @require_beam
      def _UpperCamelCase						(    self				:	Union[str, Any]						):





            """simple docstring"""







            with tempfile.TemporaryDirectory() as tmp_cache_dir:
                  __snake_case      :    Dict  			=DummyBeamDataset(cache_dir=a						)
                  self.assertRaises(datasets.builder.MissingBeamOptions							,   builder.download_and_prepare						)







      @require_beam
      def _UpperCamelCase						(    self				:	int						):





            """simple docstring"""







            __snake_case      :    Dict  			=len(get_test_nested_examples()						)
            with tempfile.TemporaryDirectory() as tmp_cache_dir:
                  __snake_case      :    Tuple  			=NestedBeamDataset(cache_dir=a							,   beam_runner='''DirectRunner'''						)
                  builder.download_and_prepare()
                  self.assertTrue(
                      os.path.exists(
                          os.path.join(a							,   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'''						)}						)}						)						)
                  __snake_case      :    int  			=builder.as_dataset()
                  self.assertEqual(dset['''train'''].num_rows							,   a						)
                  self.assertEqual(dset['''train'''].info.splits['''train'''].num_examples							,   a						)
                  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(a							,   builder.name							,   '''default'''							,   '''0.0.0'''							,   '''dataset_info.json'''						)						)						)
                  del dset










"""simple docstring"""





from math import atan, cos, radians, sin, tan

from .haversine_distance import haversine_distance

UpperCamelCase_	:				Optional[Any]										= 6_37_81_37.0
UpperCamelCase_	:				Optional[Any]										= 6_35_67_52.31_42_45
UpperCamelCase_	:				Union[str, Any]										= 6378137



def     __lowercase					(    a :				float       ,		a :				float       ,		a :				float       ,		a :				float )					->					float:
      __snake_case      :    Optional[Any]  			=(AXIS_A - AXIS_B) / AXIS_A
      # Parametric latitudes
      # https://en.wikipedia.org/wiki/Latitude#Parametric_(or_reduced)_latitude
      __snake_case      :    List[str]  			=atan((1 - flattening) * tan(radians(a ) ) )
      __snake_case      :    Any  			=atan((1 - flattening) * tan(radians(a ) ) )

      # Compute central angle between two points
      # using haversine theta. sigma =  haversine_distance / equatorial radius
      __snake_case      :    Optional[Any]  			=haversine_distance(a       ,		a       ,		a       ,		a ) / EQUATORIAL_RADIUS

      # Intermediate P and Q values
      __snake_case      :    List[str]  			=(b_lata + b_lata) / 2
      __snake_case      :    Dict  			=(b_lata - b_lata) / 2

      # Intermediate X value
      # X = (sigma - sin(sigma)) * sin^2Pcos^2Q / cos^2(sigma/2)
      __snake_case      :    Optional[int]  			=(sin(a ) ** 2) * (cos(a ) ** 2)
      __snake_case      :    Any  			=cos(sigma / 2 ) ** 2
      __snake_case      :    Optional[Any]  			=(sigma - sin(a )) * (x_numerator / x_demonimator)

      # Intermediate Y value
      # Y = (sigma + sin(sigma)) * cos^2Psin^2Q / sin^2(sigma/2)
      __snake_case      :    Tuple  			=(cos(a ) ** 2) * (sin(a ) ** 2)
      __snake_case      :    Dict  			=sin(sigma / 2 ) ** 2
      __snake_case      :    Tuple  			=(sigma + sin(a )) * (y_numerator / y_denominator)

      return EQUATORIAL_RADIUS * (sigma - ((flattening / 2) * (x_value + y_value)))


if __name__ == "__main__":
    import doctest

    doctest.testmod()


