a
    h                     @   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rd 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  qq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   Y/var/www/html/assistant/venv/lib/python3.9/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




