





import importlib
import os

import fsspec
import pytest
from fsspec import register_implementation
from fsspec.registry import _registry as _fsspec_registry

from datasets.filesystems import COMPRESSION_FILESYSTEMS, HfFileSystem, extract_path_from_uri, is_remote_filesystem

from .utils import require_lza, require_zstandard




def     a__ (					lowercase__  ):






   '''simple docstring'''






   assert "mock" in _fsspec_registry
   assert "bz2" in _fsspec_registry




def     a__ (					):






   '''simple docstring'''






   assert "mock" not in _fsspec_registry
   assert "bz2" in _fsspec_registry




def     a__ (					):






   '''simple docstring'''






   UpperCAmelCase_											="mock-s3-bucket"
   UpperCAmelCase_											=F's3://{mock_bucket}'
   UpperCAmelCase_											=extract_path_from_uri(lowercase__  )
   assert dataset_path.startswith("s3://"  ) is False

   UpperCAmelCase_											="./local/path"
   UpperCAmelCase_											=extract_path_from_uri(lowercase__  )
   assert dataset_path == new_dataset_path




def     a__ (					lowercase__  ):






   '''simple docstring'''






   UpperCAmelCase_											=is_remote_filesystem(lowercase__  )
   assert is_remote is True

   UpperCAmelCase_											=fsspec.filesystem("file"  )

   UpperCAmelCase_											=is_remote_filesystem(lowercase__  )
   assert is_remote is False




@pytest.mark.parametrize("compression_fs_class"  ,    lowercase__  )
def     a__ (					lowercase__  ,    lowercase__  ,    lowercase__  ,    lowercase__  ,    lowercase__  ,    lowercase__  ,    lowercase__  ):






   '''simple docstring'''






   UpperCAmelCase_											={"gzip": gz_file, "xz": xz_file, "zstd": zstd_file, "bz2": bza_file, "lz4": lza_file}
   UpperCAmelCase_											=input_paths[compression_fs_class.protocol]
   if input_path is None:
      UpperCAmelCase_											=F'for \'{compression_fs_class.protocol}\' compression protocol, '
      if compression_fs_class.protocol == "lz4":
         reason += require_lza.kwargs["reason"]
      elif compression_fs_class.protocol == "zstd":
         reason += require_zstandard.kwargs["reason"]
      pytest.skip(lowercase__  )
   UpperCAmelCase_											=fsspec.filesystem(compression_fs_class.protocol  ,    fo=lowercase__  )
   assert isinstance(lowercase__  ,    lowercase__  )
   UpperCAmelCase_											=os.path.basename(lowercase__  )
   UpperCAmelCase_											=expected_filename[: expected_filename.rindex("."  )]
   assert fs.glob("*"  ) == [expected_filename]
   with fs.open(lowercase__  ,    "r"  ,    encoding="utf-8"  ) as f, open(lowercase__  ,    encoding="utf-8"  ) as expected_file:
      assert f.read() == expected_file.read()




@pytest.mark.parametrize("protocol"  ,    ["zip", "gzip"]  )
def     a__ (					lowercase__  ,    lowercase__  ,    lowercase__  ):






   '''simple docstring'''






   UpperCAmelCase_											={"zip": zip_jsonl_path, "gzip": jsonl_gz_path}
   UpperCAmelCase_											=compressed_file_paths[protocol]
   UpperCAmelCase_											="dataset.jsonl"
   UpperCAmelCase_											=F'{protocol}://{member_file_path}::{compressed_file_path}'
   UpperCAmelCase_						,       *UpperCAmelCase_											=fsspec.get_fs_token_paths(lowercase__  )
   assert fs.isfile(lowercase__  )
   assert not fs.isfile("non_existing_" + member_file_path  )




@pytest.mark.integration
def     a__ (					lowercase__  ,    lowercase__  ,    lowercase__  ,    lowercase__  ):






   '''simple docstring'''






   UpperCAmelCase_											=hf_api.dataset_info(lowercase__  ,    token=lowercase__  )
   UpperCAmelCase_											=HfFileSystem(repo_info=lowercase__  ,    token=lowercase__  )
   assert sorted(hffs.glob("*"  )  ) == [".gitattributes", "data"]
   assert hffs.isdir("data"  )
   assert hffs.isfile(".gitattributes"  ) and hffs.isfile("data/text_data.txt"  )
   with open(lowercase__  ) as f:
      assert hffs.open("data/text_data.txt"  ,    "r"  ).read() == f.read()





def     a__ (					):






   '''simple docstring'''






   UpperCAmelCase_											="bz2"

   # Import module
   import datasets.filesystems

   # Overwrite protocol and reload
   register_implementation(lowercase__  ,    lowercase__  ,    clobber=lowercase__  )
   with pytest.warns(lowercase__  ) as warning_info:
      importlib.reload(datasets.filesystems  )

   assert len(lowercase__  ) == 1
   assert (
       str(warning_info[0].message  )
       == F'A filesystem protocol was already set for {protocol} and will be overwritten.'
   )











import math_equivalence  # From: git+https://github.com/hendrycks/math.git

import datasets


__lowercase  :   int						      ="""\
@article{hendrycksmath2021,
  title={Measuring Mathematical Problem Solving With the MATH Dataset},
  author={Dan Hendrycks
    and Collin Burns
    and Saurav Kadavath
    and Akul Arora
    and Steven Basart
    and Eric Tang
    and Dawn Song
    and Jacob Steinhardt},
  journal={arXiv preprint arXiv:2103.03874},
  year={2021}
}
"""


__lowercase  :   List[Any]						      ="""\
This metric is used to assess performance on the Mathematics Aptitude Test of Heuristics (MATH) dataset.
It first canonicalizes the inputs (e.g., converting \"1/2\" to \"\\frac{1}{2}\") and then computes accuracy.
"""


__lowercase  :   str						      =R"""
Calculates accuracy after canonicalizing inputs.

Args:
    predictions: list of predictions to score. Each prediction
        is a string that contains natural language and LaTex.
    references: list of reference for each prediction. Each
        reference is a string that contains natural language
        and LaTex.
Returns:
    accuracy: accuracy after canonicalizing inputs
        (e.g., converting \"1/2\" to \"\\frac{1}{2}\")

Examples:
    >>> metric = datasets.load_metric(\"competition_math\")
    >>> results = metric.compute(references=[\"\\frac{1}{2}\"], predictions=[\"1/2\"])
    >>> print(results)
    {'accuracy': 1.0}
"""

@datasets.utils.file_utils.add_end_docstrings(_DESCRIPTION		,      _KWARGS_DESCRIPTION						)
class      A       (	datasets.Metric						):



      def 	lowerCAmelCase__    (	self:						Any       )						->    Optional[Any]:
         '''simple docstring'''

         return datasets.MetricInfo(
             description=_DESCRIPTION		,  citation=_CITATION		,  inputs_description=_KWARGS_DESCRIPTION		,  features=datasets.Features(
                 {
                     "predictions": datasets.Value("string"       ),
                     "references": datasets.Value("string"       ),
                 }       )		,  homepage="https://github.com/hendrycks/math"		,  codebase_urls=["https://github.com/hendrycks/math"]		,  )






      def 	lowerCAmelCase__    (	self:						Any		,  _lowerCAmelCase:						Tuple		,  _lowerCAmelCase:						Union[str, Any]       )						->    Dict:
         '''simple docstring'''

         UpperCAmelCase_											=0.0
         for i, j in zip(_lowerCAmelCase		,  _lowerCAmelCase       ):
            n_correct += 1.0 if math_equivalence.is_equiv(_lowerCAmelCase		,  _lowerCAmelCase       ) else 0.0
         UpperCAmelCase_											=n_correct / len(_lowerCAmelCase       )
         return {
             "accuracy": accuracy,
         }




