U
    _»{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   ú\/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sklearn/tests/test_docstrings.pyÚget_all_methods   s    



r   c                  c   s6   t ƒ } | D ]&\}}d|jk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krq|dkrD|dk	rD|dk	rDt ||ƒ}t|tƒrDq|dk	rV|dk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kr.t |dƒrd}n|dkr*tdƒ‚nt‚|dk	rzt||ƒ}ztt|ƒƒ}W n tk
rh   d}Y nX |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

ÚfileZ	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    


ÿ

ÿûÿr6   Ú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%   r6   r.   )r7   Úrequestr2   r5   r   r   r   Útest_function_docstring‘   s
    
r>   zKlass, methodc                 C   sp   | j }|| jg}|d k	r"| |¡ d |¡}t |¡}tt|d || d�ƒ|d< |d rlt|| |ƒ}t	|ƒ‚d S )Nr   r"   )r   )
r   r   r   r1   r:   r;   r<   r%   r6   r.   )r   r   r=   Zbase_import_pathÚimport_pathr2   r5   r   r   r   Útest_docstringž   s    



r@   Ú__main__z!Validate docstring with numpydoc.)Údescriptionr?   zImport path to validate)Úhelpr   é   z(?:[A-Z][a-z]*)+éþÿÿÿéÿÿÿÿr"   r9   é   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   r6   ÚmarkZparametrizer>   r@   r   ÚargparseÚsysÚArgumentParserÚparserÚadd_argumentÚ
parse_argsÚargsr;   r?   r2   ÚsplitZimport_path_sectionsÚlenÚmatchr   r<   r5   ÚprintÚexitr+   r   r   r   r   Ú<module>   sD   

-7


 ÿ

