a
    ;Za-                     @   s  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Zd dlZd dl	m
Z
 d dlmZ d dlmZ d dlmZ d dl	mZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlZe < ede ej Z!e"dd ede!dD Z#W d   n1 s$0    Y  g dZ$g dZ%ej&'dej&'dej&j(e
dddd Z)eeddd Z*d d! Z+d"d# Z,d$d% Z-ej&.d&e d'd( Z/d)d* Z0dS )+    N)walk_packages)	signature)IS_PYPY)check_docstring_parameters)_get_func_name)ignore_warnings)all_estimators)_enforce_estimator_tags_y)_enforce_estimator_tags_x)_construct_instance)_is_deprecated)make_classificationLogisticRegression)FunctionTransformerignorec                 C   s,   g | ]$}d |d v sd|d v s|d qS )z._   z.tests. ).0Zpckgr   r   Flib/python3.9/site-packages/sklearn/tests/test_docstring_parameters.py
<listcomp>&   s   r   sklearn.)prefixpath)z%sklearn.utils.deprecation.load_mlcompzsklearn.pipeline.make_pipelinezsklearn.pipeline.make_unionz%sklearn.utils.extmath.safe_sparse_dotzsklearn.utils._joblib)fitZscoreZfit_predictZfit_transformZpartial_fitZpredictzignore::FutureWarningzignore::DeprecationWarningztest segfaults on PyPyreasonc               
      s  t jddd ddlm}  g }tD ]6  dr4q" dkr>q"tjdd	 t	 }W d    n1 sj0    Y  t
|t
j}d
d |D }|D ]2\}}g }|tv s|drqt
|rqtjdd	}| |}W d    n1 s0    Y  t|rtd| |d f t|dd }	t|	r2qn|	d urL|t|j|7 }|jD ]l}
t||
}t|rnqRd }|
tv rt|}d|jv r|jd jd u rdg}t||d}||7 }qR||7 }qt
|t
j} fdd|D }|D ]j\}}|drq|dkr  dr qt|tfddtD st|s|t|7 }qq"d|}t|dkrt d| d S )Nnumpydocz+numpydoc is required to test the docstringsr   r   	docscrapez	.conftestzsklearn.utils.fixesT)recordc                 S   s    g | ]}|d  j dr|qS )r   sklearn)
__module__
startswith)r   clsr   r   r   r   ]       z-test_docstring_parameters.<locals>.<listcomp>_z"Error for __init__ of %s in %s:
%s__init__y)r   c                    s   g | ]}|d  j  kr|qS )r   )r"   )r   fnnamer   r   r      r%   ZconfigurationZsetupc                 3   s   | ]}| v V  qd S )Nr   )r   d)name_r   r   	<genexpr>   r%   z,test_docstring_parameters.<locals>.<genexpr>
zDocstring Error:
)!pytestimportorskipr   r   PUBLIC_MODULESendswithwarningscatch_warnings	importlibimport_moduleinspectZ
getmembersZisclass_DOCSTRING_IGNORESr#   Z
isabstractClassDoclenRuntimeErrorgetattrr   r   r'   methods_METHODS_IGNORE_NONE_Yr   
parametersdefaultZ
isfunctionr   anyjoinAssertionError)r   Z	incorrectmoduleclassesZcnamer$   Zthis_incorrectwZcdocZcls_initZmethod_namemethodZparam_ignoreZsigresultZ	functionsfnamefuncmsgr   )r+   r-   r   test_docstring_parametersC   st    

(
(








rM   categoryc               	   C   s|   t tjddD ]h\} }}tr.d|v sd|v r.qt|}zt|}W n ty\   Y qY n0 d|vsJ dd| fqd S )Nr   )r   Z_svmlight_format_ioz feature_extraction._hashing_fast	z""%s" has tabs, please remove them zor add it to the ignore list)	r   r!   __path__r   r6   r7   r8   Z	getsourceIOError)importermodnameispkgmodsourcer   r   r   	test_tabs   s     


rX   c                 C   s   | t  dddgiS )NCg?r   r   )ZSearchCVr   r   r   _construct_searchcv_instance   s    rZ   c                 C   s\   | j dkr | ddddgfgdS | j dkr<| dt fgd	S | j d
krX| dt fgdS d S )NColumnTransformerZtransformerZpassthroughr   r   )ZtransformersPipelineZclf)ZstepsFeatureUnion)Ztransformer_list)__name__r   r   )	Estimatorr   r   r   $_construct_compose_pipeline_instance   s    


r`   c                 C   s8   t jg dg dg dg dg dgt jd}| |dS )N)r   r   r   )ra      )r   r   r   )r   r   r   )r   rb   r   )Zdtype)
dictionary)npZarrayZfloat64)r_   rc   r   r   r   _construct_sparse_coder   s
     re   zname, Estimatorc              	   C   s  t d ddlm} ||}|d }|jdv r<t|}n0|jdv rPt|}n|jdkrdt|}nt	|}|jdkr|j
d	d
 nR|jdkr|j
dd n:|jdks|jdr|j
dd n|jdv r|j
d	d |jdv r|j
dd |jdkr|j
dd |jdkr|j
ddd ddh}|jdrp|jd v rJg d!}n |jd"krjdd	d#d$dd%g}d }n*td&d$dd	d	d'\}}t||}t||}d(| d) v r|| n4d*| d) v r|tj||f  n||| |D ]r}	|	j|v rqd+|	j }
d,|
v r"qttd-" t||	js@J W d    n1 sV0    Y  qt|}d.d/ |D }t||}t||}|rtd0|j d1| d S )2Nr   r   r   Z
Attributes)ZHalvingRandomSearchCVZRandomizedSearchCVZHalvingGridSearchCVZGridSearchCV)r[   r\   r]   ZSparseCoderZSelectKBestrb   )kZDummyClassifierZ
stratified)ZstrategyZCCAZPLSr   )Zn_components)ZGaussianRandomProjectionZSparseRandomProjection)ZOrthogonalMatchingPursuitZOrthogonalMatchingPursuitCVZLarsZLarsCVZ	LassoLarsZLassoLarsCVZLassoLarsICF)Z	normalizeZNMFZnndsvda)initZTSNEg      i@Zrandom)Zlearning_raterg   Z	x_scores_Z	y_scores_Z
Vectorizer)ZCountVectorizerZHashingVectorizerZTfidfVectorizer)zThis is the first document.z%This document is the second document.zAnd this is the third one.zIs this the first document?ZDictVectorizer)fooZbar   )rh   Zbaz   )Z	n_samplesZ
n_featuresZn_redundantZ	n_classesZrandom_stateZ1dlabelsZX_typesZ2dlabels zonly rN   c                 S   s   g | ]
}|j qS r   r*   )r   attrr   r   r   r   5  r%   z1test_fit_docstring_attributes.<locals>.<listcomp>zUndocumented attributes for z: )r0   r1   r   r   r:   r^   rZ   r`   re   r   Z
set_paramsr#   r3   r   r	   r
   Z	_get_tagsr   rd   Zc_r+   rC   desclowerr   FutureWarninghasattr_get_all_fitted_attributesset
differencerD   )r+   r_   r   docZ
attributesZestZskipped_attributesXr(   rl   rm   fit_attrZfit_attr_namesZundocumented_attrsr   r   r   test_fit_docstring_attributes   s|    











	




6rw   c                 C   s   t | j }t z tjdtd t| jD ]P}t	| j|}t
|tsLq0zt	| | W n ttfyt   Y q0Y n0 || q0W d   n1 s0    Y  dd |D S )zBGet all the fitted attributes of an estimator including propertieserrorrN   Nc                 S   s$   g | ]}| d r|d s|qS )r&   )r3   r#   )r   rf   r   r   r   r   T  r%   z._get_all_fitted_attributes.<locals>.<listcomp>)list__dict__keysr4   r5   filterwarningsro   dir	__class__r=   
isinstancepropertyAttributeErrorappend)Z	estimatorrv   r+   objr   r   r   rq   >  s    


*rq   )1r8   r4   r6   pkgutilr   r   Znumpyrd   r!   Zsklearn.utilsr   Zsklearn.utils._testingr   r   r   r   Zsklearn.utils.estimator_checksr	   r
   r   Zsklearn.utils.deprecationr   Zsklearn.datasetsr   Zsklearn.linear_modelr   Zsklearn.preprocessingr   r0   r5   simplefilterro   rQ   Zsklearn_pathrr   r2   r9   r?   Zmarkr|   ZskipifrM   rX   rZ   r`   re   Zparametrizerw   rq   r   r   r   r   <module>   sR   

$		

P

	
x