
    +gd{c                     :   d Z ddlZddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZmZmZ ddlZddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$m%Z%  e e&          Z'e G d d                      Z(e G d d                      Z) G d de*          Z+ G d de*          Z,e G d d                      Z-e G d d                      Z. G d dee/e.f                   Z0e G d d                      Z1dS ) a   DatasetInfo and MetricInfo record information we know about a dataset and a metric.

This includes things that we know about the dataset statically, i.e.:
 - description
 - canonical location
 - does it have validation and tests splits
 - size
 - etc.

This also includes the things that can and should be computed once we've
processed the dataset as well:
 - number of examples (in each split)
 - etc.
    N)	dataclass)Path)ClassVarDictListOptionalUnion   )config)FeaturesValue)is_remote_filesystem)	SplitDict)TaskTemplatetask_template_from_dict)Version)
get_logger)DatasetMetadata)asdictunique_valuesc                   ,    e Zd ZU dZeed<   dZeed<   dS )SupervisedKeysData inputoutputN)__name__
__module____qualname__r   str__annotations__r        -lib/python3.11/site-packages/datasets/info.pyr   r   9   s/         E3OOOFCr"   r   c                   ,    e Zd ZU dZeed<   dZeed<   dS )DownloadChecksumsEntryDatar   keyvalueN)r   r   r   r&   r   r    r'   r!   r"   r#   r%   r%   ?   s*         CMMME3OOOOOr"   r%   c                       e Zd ZdZdS )MissingCachedSizesConfigErrorz;The expected cached sizes of the download file are missing.Nr   r   r   __doc__r!   r"   r#   r)   r)   E   s        EEEEr"   r)   c                       e Zd ZdZdS )NonMatchingCachedSizesErrorz/The prepared split doesn't have expected sizes.Nr*   r!   r"   r#   r-   r-   I   s        9999r"   r-   c                   j    e Zd ZU dZee         ed<   dZee         ed<   d Z	e
dedd fd            ZdS )PostProcessedInfoNfeaturesresources_checksumsc                     | j         :t          | j         t                    s"t          j        | j                   | _         d S d S d S N)r0   
isinstancer   	from_dictselfs    r#   __post_init__zPostProcessedInfo.__post_init__R   sA    =$Zx-P-P$$.t}==DMMM %$$$r"   post_processed_info_dictreturnc                     d t          j        |           D              | di fd|                                D             S )Nc                     h | ]	}|j         
S r!   name.0fs     r#   	<setcomp>z.PostProcessedInfo.from_dict.<locals>.<setcomp>Y       ???!qv???r"   c                 $    i | ]\  }}|v 	||S r!   r!   r@   kvfield_namess      r#   
<dictcomp>z/PostProcessedInfo.from_dict.<locals>.<dictcomp>Z   s*    \\\tq!1P[K[K[aK[K[K[r"   r!   dataclassesfieldsitems)clsr9   rH   s     @r#   r5   zPostProcessedInfo.from_dictW   sY    ??{'9#'>'>???s]]\\\\'?'E'E'G'G\\\]]]r"   )r   r   r   r0   r   r   r    r1   dictr8   classmethodr5   r!   r"   r#   r/   r/   M   s         #'Hhx '''*.$...> > >
 ^ ^:M ^ ^ ^ [^ ^ ^r"   r/   c                   F   e Zd ZU dZ ej        e          Zeed<    ej        e          Z	eed<    ej        e          Z
eed<    ej        e          Zeed<   dZee         ed<   dZee         ed	<   dZee         ed
<   dZeee                  ed<   dZee         ed<   dZee         ed<   dZeeeef                  ed<   dZee         ed<   dZee         ed<   dZee         ed<   dZ ee         ed<   dZ!ee         ed<   dZ"ee         ed<   g dZ#e$ee                  ed<   d Z%	 d,dee         fdZ&d-dZ'd Z(e)ded          fd            Z*e)	 d.d edee         d!d fd"            Z+e)d#ed!d fd$            Z,d/d0d'Z-d1d(Z.d!efd)Z/e)d*ed!d fd+            Z0dS )2DatasetInfoa
  Information about a dataset.

    `DatasetInfo` documents datasets, including its name, version, and features.
    See the constructor arguments and properties for a full list.

    Not all fields are known on construction and may be updated later.

    Attributes:
        description (`str`):
            A description of the dataset.
        citation (`str`):
            A BibTeX citation of the dataset.
        homepage (`str`):
            A URL to the official homepage for the dataset.
        license (`str`):
            The dataset's license. It can be the name of the license or a paragraph containing the terms of the license.
        features ([`Features`], *optional*):
            The features used to specify the dataset's column types.
        post_processed (`PostProcessedInfo`, *optional*):
            Information regarding the resources of a possible post-processing of a dataset. For example, it can contain the information of an index.
        supervised_keys (`SupervisedKeysData`, *optional*):
            Specifies the input feature and the label for supervised learning if applicable for the dataset (legacy from TFDS).
        builder_name (`str`, *optional*):
            The name of the `GeneratorBasedBuilder` subclass used to create the dataset. Usually matched to the corresponding script name. It is also the snake_case version of the dataset builder class name.
        config_name (`str`, *optional*):
            The name of the configuration derived from [`BuilderConfig`].
        version (`str` or [`Version`], *optional*):
            The version of the dataset.
        splits (`dict`, *optional*):
            The mapping between split name and metadata.
        download_checksums (`dict`, *optional*):
            The mapping between the URL to download the dataset's checksums and corresponding metadata.
        download_size (`int`, *optional*):
            The size of the files to download to generate the dataset, in bytes.
        post_processing_size (`int`, *optional*):
            Size of the dataset in bytes after post-processing, if any.
        dataset_size (`int`, *optional*):
            The combined size in bytes of the Arrow tables for all splits.
        size_in_bytes (`int`, *optional*):
            The combined size in bytes of all files associated with the dataset (downloaded files + Arrow files).
        task_templates (`List[TaskTemplate]`, *optional*):
            The task templates to prepare the dataset for during training and evaluation. Each template casts the dataset's [`Features`] to standardized column names and types as detailed in `datasets.tasks`.
        **config_kwargs (additional keyword arguments):
            Keyword arguments to be passed to the [`BuilderConfig`] and used in the [`DatasetBuilder`].
    default_factorydescriptioncitationhomepagelicenseNr0   post_processedsupervised_keystask_templatesbuilder_nameconfig_nameversionsplitsdownload_checksumsdownload_sizepost_processing_sizedataset_sizesize_in_bytes)r]   ra   rc   r0   r_   _INCLUDED_INFO_IN_YAMLc                      j         8t           j         t                    st          j         j                    _          j        >t           j        t
                    s$t
                               j                   _         j        lt           j        t                    sRt           j        t                    rt           j                   _        nt          j         j                   _         j	        8t           j	        t                    st          j         j	                   _	         j        et           j        t                    sKt           j        t          t          f          rt           j          _        nt          di  j         _         j        t           j        t          t          f          r#d  j        D             }d |D              _        nHt           j        t"                    r j        g _        n t%           j                  }||gng  _         j        :t           j                   _         j          fd j        D              _        d S d S d S )Nc                 Z    g | ](}t          |t                    r|nt          |          )S r!   )r4   r   r   r@   templates     r#   
<listcomp>z-DatasetInfo.__post_init__.<locals>.<listcomp>   sE         !+8\ B BiHHH_`hHiHi  r"   c                     g | ]}||S r3   r!   rh   s     r#   rj   z-DatasetInfo.__post_init__.<locals>.<listcomp>   s    &b&b&bHXMaxMaMaMar"   c                 D    g | ]}|                     j                  S r!   )align_with_featuresr0   )r@   ri   r7   s     r#   rj   z-DatasetInfo.__post_init__.<locals>.<listcomp>   s6     ' ' 'DLH00??' ' 'r"   r!   )r0   r4   r   r5   rY   r/   r^   r   r   r_   r   from_split_dictrZ   r   tuplelistr[   r   r   )r7   	templatesri   s   `  r#   r8   zDatasetInfo.__post_init__   s\   =$Zx-P-P$$.t}==DM*:d>QSd3e3e*"3"="=d>Q"R"RD<#Jt|W,M,M#$,,, ?&t|44&0>>;":dk9+M+M"#3DK@@DK+Jt?SUg4h4h+$.>> R'94;O'P$$'9'Q'QD<P'Q'Q$ *$-e}== 
Q $($7  	 'c&b	&b&b&b##D/>> Q'+':&;##243FGG4<4Hxjjb# *"&t':";";D}(' ' ' 'QUQd' ' '### +*((r"   F
deprecatedstorage_optionsc                 b   |dk    r!t          j        dt                     |j        }t	          j        ||          }|d         }t          |           }|rt          j        j	        nt          j	        }|                     ||t          j                  d          5 }|                     ||           ddd           n# 1 swxY w Y   | j        rZ|                     ||t          j                  d          5 }|                     |           ddd           dS # 1 swxY w Y   dS dS )ah  Write `DatasetInfo` and license (if present) as JSON files to `dataset_info_dir`.

        Args:
            dataset_info_dir (`str`):
                Destination directory.
            pretty_print (`bool`, defaults to `False`):
                If `True`, the JSON will be pretty-printed with the indent level of 4.
            fs (`fsspec.spec.AbstractFileSystem`, *optional*):
                Instance of the remote filesystem used to download the files from.

                <Deprecated version="2.9.0">

                `fs` was deprecated in version 2.9.0 and will be removed in 3.0.0.
                Please use `storage_options` instead, e.g. `storage_options=fs.storage_options`.

                </Deprecated>

            storage_options (`dict`, *optional*):
                Key/value pairs to be passed on to the file-system backend, if any.

                <Added version="2.9.0"/>

        Example:

        ```py
        >>> from datasets import load_dataset
        >>> ds = load_dataset("rotten_tomatoes", split="validation")
        >>> ds.info.write_to_directory("/path/to/directory/")
        ```
        rr   'fs' was deprecated in favor of 'storage_options' in version 2.9.0 and will be removed in 3.0.0.
You can remove this warning by passing 'storage_options=fs.storage_options' instead.rs   r   wb)pretty_printN)warningswarnFutureWarningrs   fsspecget_fs_token_pathsr   ospathjoin	posixpathopenr   DATASET_INFO_FILENAME
_dump_inforX   LICENSE_FILENAME_dump_license)	r7   dataset_info_dirrx   fsrs   fs_token_pathsis_local	path_joinrA   s	            r#   write_to_directoryzDatasetInfo.write_to_directory   s   B Mg  
 !0O23CUdeee(6q(9+B///$,@BGLL).	WWYY/1MNNPTUU 	:YZOOALO999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:< 	&#3V5LMMtTT &XY""1%%%& & & & & & & & & & & & & & & & & &	& 	&s$   CC
C?D""D&)D&c                     |                     t          j        t          |           |rdnd                              d                     dS )zQDump info in `file` file-like object open in bytes mode (to support remote files)   Nindentutf-8)writejsondumpsr   encode)r7   filerx   s      r#   r   zDatasetInfo._dump_info	  sG    

4:fTll3N11$OOOVVW^__`````r"   c                 `    |                     | j                            d                     dS )zTDump license in `file` file-like object open in bytes mode (to support remote files)r   N)r   rX   r   )r7   r   s     r#   r   zDatasetInfo._dump_license  s*    

4<&&w//00000r"   dataset_infosc           	      L   d |D             }d                     t          d |D                                                                 }d                     t          d |D                                                                 }d                     t          d |D                                                                 }d                     t          d |D                                                                 }d }d }d }d |D             }	t          |	          dk    r3t	           t          |	d	                   j        |	dd                     }n1t          |	          r"t	          t          |	d	                             }|r|nd } | |||||||
          S )Nc                 :    g | ]}||                                 S r3   )copy)r@   	dset_infos     r#   rj   z*DatasetInfo.from_merge.<locals>.<listcomp>  s'    bbbiILa))LaLaLar"   z

c              3   $   K   | ]}|j         V  d S r3   )rU   r@   infos     r#   	<genexpr>z)DatasetInfo.from_merge.<locals>.<genexpr>  s%      /[/[T0@/[/[/[/[/[/[r"   c              3   $   K   | ]}|j         V  d S r3   )rV   r   s     r#   r   z)DatasetInfo.from_merge.<locals>.<genexpr>  $      ,U,UtT],U,U,U,U,U,Ur"   c              3   $   K   | ]}|j         V  d S r3   )rW   r   s     r#   r   z)DatasetInfo.from_merge.<locals>.<genexpr>  r   r"   c              3   $   K   | ]}|j         V  d S r3   )rX   r   s     r#   r   z)DatasetInfo.from_merge.<locals>.<genexpr>  s$      +S+STDL+S+S+S+S+S+Sr"   c                 *    g | ]}|j         	|j         S r3   )r[   r   s     r#   rj   z*DatasetInfo.from_merge.<locals>.<listcomp>  s#    ooodtObOnd1OnOnOnr"   r
   r   )rU   rV   rW   rX   r0   rZ   r[   )r   r   striplenrp   setintersection)
rN   r   rU   rV   rW   rX   r0   rZ   r[   all_task_templatess
             r#   
from_mergezDatasetInfo.from_merge  s   bb=bbbkk-/[/[]/[/[/["["[\\bbdd;;},U,U},U,U,UUUVV\\^^;;},U,U},U,U,UUUVV\\^^++m+S+S]+S+S+SSSTTZZ\\ pomooo!""Q&&!"I#&8&;"<"<"IK]^_^`^`Ka"bccNN#$$ 	>!#&8&;"<"<==N+9Cts#+)
 
 
 	
r"   r   r:   c                     |dk    r!t          j        dt                     |j        }t	          j        ||          }|d         }t                              d|            |st          d          t          |           }|rt          j        j        nt          j        }|                     ||t          j                  dd	          5 }t#          j        |          }d
d
d
           n# 1 swxY w Y   |                     |          S )a  Create [`DatasetInfo`] from the JSON file in `dataset_info_dir`.

        This function updates all the dynamically generated fields (num_examples,
        hash, time of creation,...) of the [`DatasetInfo`].

        This will overwrite all previous metadata.

        Args:
            dataset_info_dir (`str`):
                The directory containing the metadata file. This
                should be the root directory of a specific dataset version.
            fs (`fsspec.spec.AbstractFileSystem`, *optional*):
                Instance of the remote filesystem used to download the files from.

                <Deprecated version="2.9.0">

                `fs` was deprecated in version 2.9.0 and will be removed in 3.0.0.
                Please use `storage_options` instead, e.g. `storage_options=fs.storage_options`.

                </Deprecated>

            storage_options (`dict`, *optional*):
                Key/value pairs to be passed on to the file-system backend, if any.

                <Added version="2.9.0"/>

        Example:

        ```py
        >>> from datasets import DatasetInfo
        >>> ds_info = DatasetInfo.from_directory("/path/to/directory/")
        ```
        rr   ru   rv   r   zLoading Dataset info from zECalling DatasetInfo.from_directory() with undefined dataset_info_dir.rr   encodingN)ry   rz   r{   rs   r|   r}   loggerr   
ValueErrorr   r~   r   r   r   r   r   r   r   loadr5   )	rN   r   r   rs   r   r   r   rA   dataset_info_dicts	            r#   from_directoryzDatasetInfo.from_directory/  sN   J Mg  
 !0O23CUdeee(6q(9C1ACCDDD 	fdeee+B///$,@BGLL).	WWYY/1MNNPS^eWff 	-jk $	!	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-}}.///s   C00C47C4r   c                     d t          j        |           D              | di fd|                                D             S )Nc                     h | ]	}|j         
S r!   r=   r?   s     r#   rB   z(DatasetInfo.from_dict.<locals>.<setcomp>l  rC   r"   c                 $    i | ]\  }}|v 	||S r!   r!   rE   s      r#   rI   z)DatasetInfo.from_dict.<locals>.<dictcomp>m  s)    UUUtq!ADTDTaDTDTDTr"   r!   rJ   )rN   r   rH   s     @r#   r5   zDatasetInfo.from_dictj  sY    ??{'9#'>'>???sVVUUUU'8'>'>'@'@UUUVVVr"   Tother_dataset_infoc                 v    | j         } |j        di fd|j                                         D              d S )Nc                 H    i | ]\  }}|	|t          j        |          S r3   r   deepcopy)r@   rF   rG   ignore_nones      r#   rI   z&DatasetInfo.update.<locals>.<dictcomp>r  s:       AqMM 4=##!MMr"   r!   )__dict__updaterM   )r7   r   r   	self_dicts     ` r#   r   zDatasetInfo.updateo  sj    M		 	
 	
   .7==??  	
 	
 	
 	
 	
r"   c                 ^     | j         di d | j                                        D             S )Nc                 >    i | ]\  }}|t          j        |          S r!   r   )r@   rF   rG   s      r#   rI   z$DatasetInfo.copy.<locals>.<dictcomp>z  s(     W W WADM!$4$4 W W Wr"   r!   )	__class__r   rM   r6   s    r#   r   zDatasetInfo.copyy  s7    t~XX W WATATAVAV W W WXXXr"   c                    i }t          |           }|D ]p}|| j        v ret          | |          }t          |d          r|                                ||<   Ct          |d          r|                                ||<   k|||<   q|S )N_to_yaml_list_to_yaml_string)r   re   getattrhasattrr   r   )r7   	yaml_dictr   r&   r'   s        r#   _to_yaml_dictzDatasetInfo._to_yaml_dict|  s    	"4LL$ 	+ 	+Cd111c**5/22 +%*%8%8%:%:IcNNU$566 +%*%:%:%<%<IcNN%*IcNr"   	yaml_datac                 |   t          j        |          }|                    d          t          j        |d                   |d<   |                    d          t          j        |d                   |d<   d t          j        |           D              | di fd|                                D             S )Nr0   r_   c                     h | ]	}|j         
S r!   r=   r?   s     r#   rB   z.DatasetInfo._from_yaml_dict.<locals>.<setcomp>  rC   r"   c                 $    i | ]\  }}|v 	||S r!   r!   rE   s      r#   rI   z/DatasetInfo._from_yaml_dict.<locals>.<dictcomp>  s)    MMMtq!A<L<La<L<L<Lr"   r!   )	r   r   getr   _from_yaml_listr   rK   rL   rM   )rN   r   rH   s     @r#   _from_yaml_dictzDatasetInfo._from_yaml_dict  s    M),,	==$$0$,$<Yz=R$S$SIj!==""."+";Ih<O"P"PIh??{'9#'>'>???sNNMMMMy'8'8MMMNNNr"   )Frr   NF)rr   N)T)r   rR   )r:   rR   )1r   r   r   r+   rK   fieldr   rU   r    rV   rW   rX   r0   r   r   rY   r/   rZ   r   r[   r   r   r\   r]   r^   r	   r   r_   rO   r`   ra   intrb   rc   rd   re   r   r8   r   r   r   rP   r   r   r5   r   r   r   r   r!   r"   r#   rR   rR   ]   sy        , ,^ ){(===K===%K%c:::Hc:::%K%c:::Hc:::$;$S999GS999#'Hhx '''26NH./66648OX0188837NHT,/0777 #'L(3-&&&!%K#%%%-1GXeCL)*111!FHTN!!!)----#'M8C='''*.(3-..."&L(3-&&&#'M8C='''3 3 3HT#Y/   ' ' 'T hl3& 3&V^_cVd3& 3& 3& 3&ja a a a1 1 1 
tM': 
 
 
 [
: W[80 80"80FNtn80	80 80 80 [80t W$ W= W W W [W
 
 
 
 
Y Y Y Yt     O O O O O [O O Or"   rR   c                   `    e Zd Zd	d
dZedd            Zededd fd            ZdeddfdZdS )DatasetInfosDictFr:   Nc                    i }t           j                            |t          j                  }t           j                            |d          }|s|                     |          }|                    |            t           j                            |          rct          |dd          5 }d |	                                D             }t          j        |||rdnd            d d d            n# 1 swxY w Y   t           j                            |          r"t          j        t          |                    }	nt                      }	|r9|                    |	           |	                    t          |                     d S d S )N	README.mdwr   r   c                 4    i | ]\  }}|t          |          S r!   )r   r@   r]   r   s      r#   rI   z7DatasetInfosDict.write_to_directory.<locals>.<dictcomp>  s3     & & &7M{IK	!2!2& & &r"   r   r   )r~   r   r   r   DATASETDICT_INFOS_FILENAMEr   r   existsr   rM   r   dumpr   from_readmer   to_metadata	to_readme)
r7   dataset_infos_dir	overwriterx   total_dataset_infosdataset_infos_pathdataset_readme_pathrA   dataset_infos_dictdataset_metadatas
             r#   r   z#DatasetInfosDict.write_to_directory  s    W\\*;V=^__ gll+<kJJ 	I"&"5"56G"H"H""4(((7>>,-- 	U(#@@@ UA& &QdQjQjQlQl& & &" 	,a\8StTTTT	U U U U U U U U U U U U U U U 7>>-.. 	1.:4@S;T;TUU.00 	B++,<===&&t,?'@'@AAAAA	B 	Bs   *:C00C47C4c                    t                               d|            t          j                            t          j                            |d                    r=t          j        t          |          dz            }d|v r| 	                    |          S t          j                            t          j                            |t          j                            rt          t          j                            |t          j                  d          5 } | d t          j        |                                          D                       cd d d            S # 1 swxY w Y   d S  |             S )NzLoading Dataset Infos from r   dataset_infor   r   c                 J    i | ] \  }}|t                               |          !S r!   )rR   r5   )r@   r]   r   s      r#   rI   z3DatasetInfosDict.from_directory.<locals>.<dictcomp>  s>       :K): $[%:%:;L%M%M  r"   )r   r   r~   r   r   r   r   r   r   from_metadatar   r   r   r   r   rM   )rN   r   r   rA   s       r#   r   zDatasetInfosDict.from_directory  s   E2CEEFFF7>>"',,'8+FFGG 	;.:4@Q;R;RU`;`aa!111(()9:::7>>"',,'8&:[\\]] 
	bgll#4f6WXXcjkkk ops >Bill>P>P>R>R                     355Ls   9EE"%E"r   c                    t          |                    d          t          t          f          rt          |d         t                    r | d |d         D                       S t                              |d                   }|d                             dd          |_         | |j        |i          S  |             S )Nr   c                 l    i | ]1}|                     d d          t                              |          2S )r]   default)r   rR   r   )r@   dataset_info_yaml_dicts     r#   rI   z2DatasetInfosDict.from_metadata.<locals>.<dictcomp>  sQ        3 /22=)LLkNiNi2O O  r"   r]   r   )r4   r   rp   rO   rR   r   r]   )rN   r   r   s      r#   r   zDatasetInfosDict.from_metadata  s    &**>::T4LII 	*>:DAA Es  7G~6V	      +::;KN;[\\+;N+K+O+OP]_h+i+i(sL4lCDDD355Lr"   c                 <   | rd |                                  D             }|                                 D ]
\  }}||d<   t          |          dk    rpt          t          |                                                    |d<   |d                             d          dk    r|d                             dd            d S d S g |d<   |                                 D ]>\  }}|                    dd            d|i|}|d                             |           =d S d S )Nc                 >    i | ]\  }}||                                 S r!   )r   r   s      r#   rI   z0DatasetInfosDict.to_metadata.<locals>.<dictcomp>  s,    "u"u"uNdk[d;	0G0G0I0I"u"u"ur"   r]   r
   r   r   )rM   r   nextitervaluesr   popappend)r7   r   r   r]   dset_info_yaml_dictr   s         r#   r   zDatasetInfosDict.to_metadata  sm    	T"u"uhlhrhrhtht"u"u"u4G4M4M4O4O A A005@#M22&''1,,37=P=W=W=Y=Y8Z8Z3[3[ 0#N377FF)SS$^488MMMMM TS 46 0;N;T;T;V;V T T7K!7*..}dCCC.;[-cLb-c*$^4;;<RSSSS#	T 	TT Tr"   )FF)r:   N)r:   r   )	r   r   r   r   rP   r   r   r   r   r!   r"   r#   r   r     s        B B B B B.    [& _ AS    [$TO T T T T T T Tr"   r   c                      e Zd ZU dZeed<   eed<   eed<    ej        e          Z	eed<    ej        e          Z
eed<    ej        e          Zeed<    ej        e          Zee         ed	<    ej        e          Zee         ed
<   dZeed<   dZee         ed<   dZee         ed<   dZee         ed<   dZee         ed<   d ZddZedd            Zededd fd            ZdS )
MetricInfoa  Information about a metric.

    `MetricInfo` documents a metric, including its name, version, and features.
    See the constructor arguments and properties for a full list.

    Note: Not all fields are known on construction and may be updated later.
    rU   rV   r0   rS   inputs_descriptionrW   rX   codebase_urlsreference_urlsF
streamableNformatmetric_namer]   experiment_idc                     | j         S| j                                        D ];\  }}t          |t                    st          d| d|j        j                   :d S d S )NzSWhen using 'numpy' format, all features should be a `datasets.Value` feature. Here z is an instance of )r   r0   rM   r4   r   r   r   r   )r7   r&   r'   s      r#   r8   zMetricInfo.__post_init__  s    ;""m1133  
U!%// $S #S S8=8PS S   #" r"   c                    t          t          j                            |t          j                  dd          5 }t          j        t          |           ||rdnd           ddd           n# 1 swxY w Y   | j	        rot          t          j                            |t          j
                  dd          5 }|                    | j	                   ddd           dS # 1 swxY w Y   dS dS )a  Write `MetricInfo` as JSON to `metric_info_dir`.
        Also save the license separately in LICENCE.
        If `pretty_print` is True, the JSON will be pretty-printed with the indent level of 4.

        Example:

        ```py
        >>> from datasets import load_metric
        >>> metric = load_metric("accuracy")
        >>> metric.info.write_to_directory("/path/to/directory/")
        ```
        r   r   r   r   Nr   )r   r~   r   r   r   METRIC_INFO_FILENAMEr   r   r   rX   r   r   )r7   metric_info_dirrx   rA   s       r#   r   zMetricInfo.write_to_directory  sk    "',,0KLLc\cddd 	KhiIfTllA<.IaaTJJJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K < 	&bgll?F4KLLc\cddd &hi%%%& & & & & & & & & & & & & & & & & &	& 	&s#   )A00A47A4<C$$C(+C(r:   c                 R   t                               d|            |st          d          t          t          j                            |t          j                  d          5 }t          j
        |          }ddd           n# 1 swxY w Y   |                     |          S )a  Create MetricInfo from the JSON file in `metric_info_dir`.

        Args:
            metric_info_dir: `str` The directory containing the metadata file. This
                should be the root directory of a specific dataset version.

        Example:

        ```py
        >>> from datasets import MetricInfo
        >>> metric_info = MetricInfo.from_directory("/path/to/directory/")
        ```
        zLoading Metric info from zCCalling MetricInfo.from_directory() with undefined metric_info_dir.r   r   N)r   r   r   r   r~   r   r   r   r  r   r   r5   )rN   r  rA   metric_info_dicts       r#   r   zMetricInfo.from_directory!  s     	AAABBB 	dbccc"',,0KLLW^___ 	,cd#y||	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,}}-...s   (B		BBr  c                     d t          j        |           D              | di fd|                                D             S )Nc                     h | ]	}|j         
S r!   r=   r?   s     r#   rB   z'MetricInfo.from_dict.<locals>.<setcomp>:  rC   r"   c                 $    i | ]\  }}|v 	||S r!   r!   rE   s      r#   rI   z(MetricInfo.from_dict.<locals>.<dictcomp>;  s)    TTTtq!1CSCSaCSCSCSr"   r!   rJ   )rN   r  rH   s     @r#   r5   zMetricInfo.from_dict8  sY    ??{'9#'>'>???sUUTTTT'7'='='?'?TTTUUUr"   r   )r:   r   )r   r   r   r+   r   r    r   rK   r   r   rW   rX   rp   r   r   r   r   boolr   r   r   r]   r  r8   r   rP   r   rO   r5   r!   r"   r#   r   r     s          MMM/k/DDDDDD%K%c:::Hc:::$;$S999GS9990{0FFFM49FFF 1 1$ G G GNDIGGGJ FHSM    "&K#%%%!%K#%%%#'M8C='''  & & & &( / / / [/, V V, V V V [V V Vr"   r   )2r+   r   rK   r   r~   r   ry   r   pathlibr   typingr   r   r   r   r	   r|   r   r   r0   r   r   filesystemsr   r_   r   tasksr   r   utilsr   utils.loggingr   utils.metadatar   utils.py_utilsr   r   r   r   r   r%   	Exceptionr)   r-   r/   rR   r   r   r   r!   r"   r#   <module>r     sE           				      ! ! ! ! ! !       8 8 8 8 8 8 8 8 8 8 8 8 8 8        % % % % % % % % - - - - - -       8 8 8 8 8 8 8 8       % % % % % % + + + + + + 1 1 1 1 1 1 1 1 
H		        
        
F F F F FI F F F: : : : :) : : : ^ ^ ^ ^ ^ ^ ^ ^ tO tO tO tO tO tO tO tOn	QT QT QT QT QTtC,- QT QT QTh QV QV QV QV QV QV QV QV QV QVr"   