






'''simple docstring'''




import json
import os
from pathlib import Path

import pytest

from datasets.download.download_config import DownloadConfig
from datasets.download.download_manager import DownloadManager
from datasets.utils.file_utils import hash_url_to_filename


__lowerCamelCase   :					List[Any]   							=					'''http://www.mocksite.com/file1.txt'''
__lowerCamelCase   :					Dict   							=					'''"text": ["foo", "foo"]'''
__lowerCamelCase   :					str   							=					'''6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8'''







class    A_	:
							"""simple docstring"""




							a__   		=	200
							a__   		=	{'''Content-Length''': '''100'''}
							a__   		=	{}

							def 							_A	(		self			:Dict       ,							**lowerCAmelCase__			:Optional[int]				)				->  List[Any]:


										'''simple docstring'''




										return [bytes(lowerCAmelCase__       ,							"utf-8"				)]

def 	__UpperCAmelCase       ( *__magic_name__     ,**__magic_name__						)->    str:



			"""simple docstring"""



			return MockResponse()

@pytest.mark.parametrize("urls_type"     ,[str, list, dict]						)
def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__     ,__magic_name__						)->    Dict:



			"""simple docstring"""



			import requests

			monkeypatch.setattr(__magic_name__     ,"request"     ,__magic_name__						)

			snake_case_				:					Any   =       URL
			if issubclass(__magic_name__     ,__magic_name__						):
						snake_case_				:					Dict   =       url
			elif issubclass(__magic_name__     ,__magic_name__						):
						snake_case_				:					Optional[Any]   =       [url]
			elif issubclass(__magic_name__     ,__magic_name__						):
						snake_case_				:					Tuple   =       {"train": url}
			snake_case_				:					Optional[Any]   =       "dummy"
			snake_case_				:					Dict   =       "downloads"
			snake_case_				:					int   =       tmp_path
			snake_case_				:					List[str]   =       DownloadConfig(
			    cache_dir=os.path.join(__magic_name__     ,__magic_name__						)     ,use_etag=__magic_name__     ,)
			snake_case_				:					List[Any]   =       DownloadManager(dataset_name=__magic_name__     ,download_config=__magic_name__						)
			snake_case_				:					Any   =       dl_manager.download(__magic_name__						)
			snake_case_				:					int   =       urls
			for downloaded_paths in [downloaded_paths]:
						if isinstance(__magic_name__     ,__magic_name__						):
									snake_case_				:					int   =       [downloaded_paths]
									snake_case_				:					int   =       [urls]
						elif isinstance(__magic_name__     ,__magic_name__						):
									assert "train" in downloaded_paths.keys()
									snake_case_				:					Tuple   =       downloaded_paths.values()
									snake_case_				:					List[str]   =       urls.values()
						assert downloaded_paths
						for downloaded_path, input_url in zip(__magic_name__     ,__magic_name__						):
									assert downloaded_path == dl_manager.downloaded_paths[input_url]
									snake_case_				:					Union[str, Any]   =       Path(__magic_name__						)
									snake_case_				:					Tuple   =       downloaded_path.parts
									assert parts[-1] == HASH
									assert parts[-2] == cache_subdir
									assert downloaded_path.exists()
									snake_case_				:					List[Any]   =       downloaded_path.read_text()
									assert content == CONTENT
									snake_case_				:					Tuple   =       downloaded_path.with_suffix(".json"						)
									assert metadata_downloaded_path.exists()
									snake_case_				:					str   =       json.loads(metadata_downloaded_path.read_text()						)
									assert metadata_content == {"url": URL, "etag": None}

@pytest.mark.parametrize("paths_type"     ,[str, list, dict]						)
def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__     ,__magic_name__						)->    Dict:



			"""simple docstring"""



			snake_case_				:					Tuple   =       str(__magic_name__						)
			if issubclass(__magic_name__     ,__magic_name__						):
						snake_case_				:					Optional[Any]   =       filename
			elif issubclass(__magic_name__     ,__magic_name__						):
						snake_case_				:					str   =       [filename]
			elif issubclass(__magic_name__     ,__magic_name__						):
						snake_case_				:					List[Any]   =       {"train": filename}
			snake_case_				:					str   =       "dummy"
			snake_case_				:					int   =       xz_file.parent
			snake_case_				:					str   =       "extracted"
			snake_case_				:					Optional[Any]   =       DownloadConfig(
			    cache_dir=__magic_name__     ,use_etag=__magic_name__     ,)
			snake_case_				:					str   =       DownloadManager(dataset_name=__magic_name__     ,download_config=__magic_name__						)
			snake_case_				:					int   =       dl_manager.extract(__magic_name__						)
			snake_case_				:					int   =       paths
			for extracted_paths in [extracted_paths]:
						if isinstance(__magic_name__     ,__magic_name__						):
									snake_case_				:					List[str]   =       [extracted_paths]
									snake_case_				:					int   =       [paths]
						elif isinstance(__magic_name__     ,__magic_name__						):
									assert "train" in extracted_paths.keys()
									snake_case_				:					List[Any]   =       extracted_paths.values()
									snake_case_				:					Optional[Any]   =       paths.values()
						assert extracted_paths
						for extracted_path, input_path in zip(__magic_name__     ,__magic_name__						):
									assert extracted_path == dl_manager.extracted_paths[input_path]
									snake_case_				:					str   =       Path(__magic_name__						)
									snake_case_				:					int   =       extracted_path.parts
									assert parts[-1] == hash_url_to_filename(__magic_name__     ,etag=__magic_name__						)
									assert parts[-2] == extracted_subdir
									assert extracted_path.exists()
									snake_case_				:					Union[str, Any]   =       extracted_path.read_text()
									snake_case_				:					Dict   =       text_file.read_text()
									assert extracted_file_content == expected_file_content

def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__						)->    List[str]:



			"""simple docstring"""



			assert path.endswith(".jsonl"						)
			for num_items, line in enumerate(__magic_name__     ,start=1						):
						snake_case_				:					Union[str, Any]   =       json.loads(line.decode("utf-8"						)						)
						assert item.keys() == {"col_1", "col_2", "col_3"}
			assert num_items == 4

@pytest.mark.parametrize("archive_jsonl"     ,["tar_jsonl_path", "zip_jsonl_path"]						)
def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__						)->    Optional[Any]:



			"""simple docstring"""



			snake_case_				:					List[str]   =       request.getfixturevalue(__magic_name__						)
			snake_case_				:					Dict   =       DownloadManager()
			for num_jsonl, (path, file) in enumerate(dl_manager.iter_archive(__magic_name__						)     ,start=1						):
						_test_jsonl(__magic_name__     ,__magic_name__						)
			assert num_jsonl == 2

@pytest.mark.parametrize("archive_nested_jsonl"     ,["tar_nested_jsonl_path", "zip_nested_jsonl_path"]						)
def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__						)->    Any:



			"""simple docstring"""



			snake_case_				:					Optional[Any]   =       request.getfixturevalue(__magic_name__						)
			snake_case_				:					List[str]   =       DownloadManager()
			for num_tar, (path, file) in enumerate(dl_manager.iter_archive(__magic_name__						)     ,start=1						):
						for num_jsonl, (subpath, subfile) in enumerate(dl_manager.iter_archive(__magic_name__						)     ,start=1						):
									_test_jsonl(__magic_name__     ,__magic_name__						)
			assert num_tar == 1
			assert num_jsonl == 2






def 	__UpperCAmelCase       ( __magic_name__						)->    List[str]:



			"""simple docstring"""



			snake_case_				:					Union[str, Any]   =       DownloadManager()
			for num_file, file in enumerate(dl_manager.iter_files(__magic_name__						)     ,start=1						):
						assert os.path.basename(__magic_name__						) == ("test.txt" if num_file == 1 else "train.txt")
			assert num_file == 2












'''simple docstring'''




from scipy.stats import spearmanr

import datasets


__lowerCamelCase   :					str   							=					'''
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
'''

__lowerCamelCase   :					int   							=					'''
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric("spearmanr")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {\'spearmanr\': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric("spearmanr")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results[\'spearmanr\'])
        -0.7
        >>> print(round(results[\'spearmanr_pvalue\'], 2))
        0.19
'''

__lowerCamelCase   :					List[str]   							=					R'''\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
'''







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,					_KWARGS_DESCRIPTION							)
class    A_	(datasets.Metric							):
							"""simple docstring"""




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


										'''simple docstring'''




										return datasets.MetricInfo(
										    description=_DESCRIPTION       ,							citation=_CITATION       ,							inputs_description=_KWARGS_DESCRIPTION       ,							features=datasets.Features(
										        {
										            "predictions": datasets.Value("float"				),
										            "references": datasets.Value("float"				),
										        }				)       ,							reference_urls=["https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html"]       ,							)






							def 							_A	(		self			:Optional[int]       ,							lowerCAmelCase__			:Optional[Any]       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:Optional[Any]=False				)				->  List[Any]:


										'''simple docstring'''




										snake_case_				:					Optional[Any]   =       spearmanr(lowerCAmelCase__       ,							lowerCAmelCase__				)
										if return_pvalue:
													return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
										else:
													return {"spearmanr": results[0]}




