


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


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[int]						)			->	Union[str, Any]:




											'''simple docstring'''

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


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]     ,    SCREAMING_SNAKE_CASE	:		Dict     ,    SCREAMING_SNAKE_CASE	:		int						)			->	List[str]:




											'''simple docstring'''

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






					def 							SCREAMING_SNAKE_CASE_  (						self	:		Any     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]						)			->	Optional[Any]:




											'''simple docstring'''

											import apache_beam as beam

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






class     UpperCamelCase(  datasets.BeamBasedBuilder   ):


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	Optional[Any]:




											'''simple docstring'''

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


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[Any]     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]     ,    SCREAMING_SNAKE_CASE	:		Dict						)			->	str:




											'''simple docstring'''

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






					def 							SCREAMING_SNAKE_CASE_  (						self	:		Tuple     ,    SCREAMING_SNAKE_CASE	:		Tuple     ,    SCREAMING_SNAKE_CASE	:		Dict						)			->	Dict:




											'''simple docstring'''

											import apache_beam as beam

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





def 	_lowerCAmelCase       (    )						->	Union[str, Any]:


						'''simple docstring'''






						return [(i, {"content": content}) for i, content in enumerate(["foo", "bar", "foobar"] )]





def 	_lowerCAmelCase       (    )						->	List[Any]:


						'''simple docstring'''






						return [(i, {"a": {"b": [content]}}) for i, content in enumerate(["foo", "bar", "foobar"] )]






class     UpperCamelCase(  __SCREAMING_SNAKE_CASE   ):


					@require_beam
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[Any]						)			->	List[str]:




											'''simple docstring'''

											__snake_case				=		len(get_test_dummy_examples()						)
											with tempfile.TemporaryDirectory() as tmp_cache_dir:
																	__snake_case				=		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				=		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 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	Union[str, Any]:




											'''simple docstring'''

											import apache_beam as beam

											__snake_case				=		beam.io.parquetio.WriteToParquet

											__snake_case				=		len(get_test_dummy_examples()						)
											with tempfile.TemporaryDirectory() as tmp_cache_dir:
																	__snake_case				=		DummyBeamDataset(cache_dir=_a     ,    beam_runner="DirectRunner"						)
																	with patch("apache_beam.io.parquetio.WriteToParquet"						) as write_parquet_mock:
																							__snake_case				=		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				=		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 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[int]						)			->	int:




											'''simple docstring'''

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






					@require_beam
					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[Any]						)			->	Tuple:




											'''simple docstring'''

											__snake_case				=		len(get_test_nested_examples()						)
											with tempfile.TemporaryDirectory() as tmp_cache_dir:
																	__snake_case				=		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				=		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









from sklearn.metrics import mean_squared_error

import datasets


A							:					List[Any]     						=     '\\n@article{scikit-learn,\n title={Scikit-learn: Machine Learning in {P}ython},\n author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.\n         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.\n         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and\n         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},\n journal={Journal of Machine Learning Research},\n volume={12},\n pages={2825--2830},\n year={2011}\n}\n'

A							:					Optional[int]     						=     '\\nMean Squared Error(MSE) is the average of the square of difference between the predicted\nand actual values.\n'


A							:					str     						=     '\nArgs:\n    predictions: array-like of shape (n_samples,) or (n_samples, n_outputs)\n        Estimated target values.\n    references: array-like of shape (n_samples,) or (n_samples, n_outputs)\n        Ground truth (correct) target values.\n    sample_weight: array-like of shape (n_samples,), default=None\n        Sample weights.\n    multioutput: {"raw_values", "uniform_average"} or array-like of shape (n_outputs,), default="uniform_average"\n        Defines aggregating of multiple output values. Array-like value defines weights used to average errors.\n\n        "raw_values" : Returns a full set of errors in case of multioutput input.\n\n        "uniform_average" : Errors of all outputs are averaged with uniform weight.\n\n    squared : bool, default=True\n        If True returns MSE value, if False returns RMSE (Root Mean Squared Error) value.\n\nReturns:\n    mse : mean squared error.\nExamples:\n\n    >>> mse_metric = datasets.load_metric("mse")\n    >>> predictions = [2.5, 0.0, 2, 8]\n    >>> references = [3, -0.5, 2, 7]\n    >>> results = mse_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'mse\': 0.375}\n    >>> rmse_result = mse_metric.compute(predictions=predictions, references=references, squared=False)\n    >>> print(rmse_result)\n    {\'mse\': 0.6123724356957945}\n\n    If you\'re using multi-dimensional lists, then set the config as follows :\n\n    >>> mse_metric = datasets.load_metric("mse", "multilist")\n    >>> predictions = [[0.5, 1], [-1, 1], [7, -6]]\n    >>> references = [[0, 2], [-1, 2], [8, -5]]\n    >>> results = mse_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'mse\': 0.7083333333333334}\n    >>> results = mse_metric.compute(predictions=predictions, references=references, multioutput=\'raw_values\')\n    >>> print(results) # doctest: +NORMALIZE_WHITESPACE\n    {\'mse\': array([0.41666667, 1. ])}\n'






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION     ,							_KWARGS_DESCRIPTION   )
class     UpperCamelCase(  datasets.Metric   ):


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	Union[str, Any]:




											'''simple docstring'''

											return datasets.MetricInfo(
											    description=_DESCRIPTION     ,    citation=_CITATION     ,    inputs_description=_KWARGS_DESCRIPTION     ,    features=datasets.Features(self._get_feature_types()						)     ,    reference_urls=[
											        "https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html"
											    ]     ,    )


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	Dict:




											'''simple docstring'''

											if self.config_name == "multilist":
																	return {
																	    "predictions": datasets.Sequence(datasets.Value("float"						)						),
																	    "references": datasets.Sequence(datasets.Value("float"						)						),
																	}
											else:
																	return {
																	    "predictions": datasets.Value("float"						),
																	    "references": datasets.Value("float"						),
																	}






					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict     ,    SCREAMING_SNAKE_CASE	:		int     ,    SCREAMING_SNAKE_CASE	:		List[Any]     ,    SCREAMING_SNAKE_CASE	:		str=None     ,    SCREAMING_SNAKE_CASE	:		int="uniform_average"     ,    SCREAMING_SNAKE_CASE	:		Optional[int]=True						)			->	Tuple:




											'''simple docstring'''

											__snake_case				=		mean_squared_error(
											    SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE     ,    sample_weight=SCREAMING_SNAKE_CASE     ,    multioutput=SCREAMING_SNAKE_CASE     ,    squared=SCREAMING_SNAKE_CASE						)

											return {"mse": mse}





