a
    �ù»j‰  ã                   @   sŽ  d dl Z d dlmZ d dlmZ d dlZd dlmZmZ d dl	m
Z
mZmZ e d¡Zdd„ Zd	d
„ Zd%dd„Zd&ee edœdd„Zej deƒ ¡dd„ ƒZej deƒ ¡dd„ ƒZedk�rŠd dlZd dlZejdd�Zejddd� e ¡ Ze  ej!¡Z"ej! #d¡Z$e%e$ƒdk�r4e  &de$d ¡�r4e$d  Z'ndZ'e(ee"d! e'ƒƒe"d!< e"d! �rzee"ej!d"�Z)e*e)ƒ e +d#¡ ne*d$ ,ej!¡ƒ dS )'é    N)Ú	signature)ÚOptional)Úenable_halving_search_cvÚenable_iterative_imputer)Úall_displaysÚall_estimatorsÚall_functionsznumpydoc.validatec                  c   sš   t ƒ } tƒ }| | D ]€\}}| d¡r(qg }t|ƒD ]8}| d¡rDq4t||ƒ}t|dƒsbt|tƒr4| |¡ q4| d ¡ t	|t
d�D ]}||fV  q„qd S )NÚ_Ú__call__)Úkey)r   r   Ú
startswithÚdirÚgetattrÚhasattrÚ
isinstanceÚpropertyÚappendÚsortedÚstr)Z
estimatorsZdisplaysÚnameÚKlassÚmethodsÚ
method_objÚmethod© r   úCE:\soccer\ml_env\Lib\site-packages\sklearn/tests/test_docstrings.pyÚget_all_methods   s    



r   c                  c   s6   t ƒ } | D ]&\}}d|jvr
|j› d|j› �V  q
d S )Nzutils.fixesÚ.)r   Ú
__module__Ú__name__)Z	functionsr	   Úfuncr   r   r   Úget_all_functions_names%   s    
r!   c                 c   sf   | D ]\\}}|dv rq|dv rD|durD|durDt ||ƒ}t|tƒrDq|durV|dv rVq||fV  qdS )za
    Ignore some errors based on the method type.

    These rules are specific for scikit-learn.)ZRT02ZGL01ZGL02)ZPR02ZGL08N)ZEX01ZSA01ZES01)r   r   r   )Úerrorsr   r   ÚcodeÚmessager   r   r   r   Úfilter_errors-   s    


r%   )r   Úreturnc                 C   sÀ   |du r.t |dƒrd}n|du r*tdƒ‚nt‚|durxt||ƒ}ztt|ƒƒ}W n tyf   d}Y n0 |jd | }nd}|}dd t| d ƒ|| | d	 d
d dd„ | d D ƒ¡g¡ }|S )a~  Pretty print original docstring and the obtained errors

    Parameters
    ----------
    res : dict
        result of numpydoc.validate.validate
    Klass : {Estimator, Display, None}
        estimator object or None
    method : str
        if estimator is not None, either the method name or None.

    Returns
    -------
    str
       String representation of the error.
    NÚ__init__z0At least one of Klass, method should be providedzM
Parsing of the method signature failed, possibly because this is a property.r   Ú z

ÚfileÚ	docstringz# ErrorsÚ
c                 s   s   | ]\}}d   ||¡V  qdS )z	 - {}: {}N)Úformat)Ú.0r#   r$   r   r   r   Ú	<genexpr>‰   s   zrepr_errors.<locals>.<genexpr>r"   )	r   Ú
ValueErrorÚNotImplementedErrorr   r   r   Ú	TypeErrorr   Újoin)Úresr   r   ÚobjZobj_signatureÚobj_nameÚmsgr   r   r   Úrepr_errorsZ   s6    


ÿ

ÿûÿr7   Úfunction_namec                 C   sH   t  | ¡}tt|d dd�ƒ|d< |d rDt|d| › �d�}t|ƒ‚dS )z)Check function docstrings using numpydoc.r"   Úfunction©r   zTested function: N)Únumpydoc_validationÚvalidateÚlistr%   r7   r/   )r8   Úrequestr3   r6   r   r   r   Útest_function_docstring‘   s
    
r?   zKlass, methodc                 C   sp   | j }|| jg}|d ur"| |¡ d |¡}t |¡}tt|d || d�ƒ|d< |d rlt|| |ƒ}t	|ƒ‚d S )Nr   r"   )r   )
r   r   r   r2   r;   r<   r=   r%   r7   r/   )r   r   r>   Zbase_import_pathÚimport_pathr3   r6   r   r   r   Útest_docstringž   s    



rA   Ú__main__z!Validate docstring with numpydoc.)Údescriptionr@   zImport path to validate)Úhelpr   é   z(?:[A-Z][a-z]*)+éþÿÿÿéÿÿÿÿr"   r:   é   z#All docstring checks passed for {}!)N)NN)-ÚreÚinspectr   Útypingr   ZpytestZsklearn.experimentalr   r   Zsklearn.utils.discoveryr   r   r   Zimportorskipr;   r   r!   r%   r   r7   ÚmarkZparametrizer?   rA   r   ÚargparseÚsysÚArgumentParserÚparserÚadd_argumentÚ
parse_argsÚargsr<   r@   r3   ÚsplitZimport_path_sectionsÚlenÚmatchr   r=   r6   ÚprintÚexitr,   r   r   r   r   Ú<module>   sB   

-7


ÿ

