o
    ?Hh6                     @   s  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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 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 d dlmZmZmZm Z m!Z! d dl"m#Z# d dl$m%Z%m&Z& e' # e(de) ej*+e
j,gZ-e.dd ede-dD Z/W d   n1 sw   Y  g dZ0g dZ1dd Z2dd Z3dd Z4dd Z5e	j67de	j68de d d! Z9d"d# Z:e!d$d% Z;e!d&d' Z<dS )(    N)	signature)walk_packages)metrics)make_classification)StackingClassifierStackingRegressor)enable_halving_search_cvenable_iterative_imputerLogisticRegression)FunctionTransformer)all_estimators)_construct_instances)_get_func_nameassert_docstring_consistencycheck_docstring_parametersignore_warningsskip_if_no_numpydoc)_is_deprecated)_enforce_estimator_tags_X_enforce_estimator_tags_yignorec                 C   s,   g | ]}d |d v sd|d v s|d qS )z._   z.tests. ).0pckgr   r   g/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/sklearn/tests/test_docstring_parameters.py
<listcomp>0   s
    r   z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HalfBinomialLoss)fitscorefit_predictfit_transformpartial_fitpredictc               
      sP  t jddd ddlm}  g }tD ]  drq dkrqtjdd	 t	 }W d    n1 s5w   Y  t
|t
j}d
d |D }|D ]\}}g }|tv sY|drZqJt
|r`qJtjdd	}| |}W d    n1 svw   Y  t|rtd| |d f t|jrqJ|t|j|7 }|jD ]0}	t||	}
t|
rqd }|	tv rt|
}d|jv r|jd jd u rdg}t|
|d}||7 }q||7 }qJt
|t
j} fdd|D }|D ]/\}}|drq|dkr drqt|tfddtD st|s|t|7 }qqd |}t|dkr&t!d| d S )Nnumpydocz+numpydoc is required to test the docstrings)reasonr   	docscrapez	.conftestzsklearn.utils.fixesT)recordc                 S   s    g | ]}|d  j dr|qS )r   sklearn)
__module__
startswith)r   clsr   r   r   r   d   s     z-test_docstring_parameters.<locals>.<listcomp>_z"Error for __init__ of %s in %s:
%sy)r   c                    s   g | ]}|d  j  kr|qS )r   )r-   )r   fnnamer   r   r      s    configurationsetupc                 3   s    | ]}| v V  qd S )Nr   )r   d)name_r   r   	<genexpr>   s    z,test_docstring_parameters.<locals>.<genexpr>
zDocstring Error:
)"pytestimportorskipr'   r*   PUBLIC_MODULESendswithwarningscatch_warnings	importlibimport_moduleinspect
getmembersisclass_DOCSTRING_IGNORESr.   
isabstractClassDoclenRuntimeErrorr   __new__r   __init__methodsgetattr_METHODS_IGNORE_NONE_Yr   
parametersdefault
isfunctionr   anyjoinAssertionError)r*   	incorrectmoduleclassescnamer/   this_incorrectwcdocmethod_namemethodparam_ignoresigresult	functionsfnamefuncmsgr   )r4   r8   r   test_docstring_parametersM   sz   









rf   c                 C   s   | t  dddgiS )NCg?r   r
   )SearchCVr   r   r   _construct_searchcv_instance   s   ri   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r,| dt fgdS d S )NColumnTransformertransformerpassthroughr   r   )transformersPipelineclf)stepsFeatureUnion)transformer_list)__name__r   r   )	Estimatorr   r   r   $_construct_compose_pipeline_instance   s   


ru   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   )rv      )r   r   r   )r   r   r   )r   rw   r   )dtype)
dictionary)nparrayfloat64)rt   ry   r   r   r   _construct_sparse_coder   s
    
r}   z-ignore::sklearn.exceptions.ConvergenceWarningzname, Estimatorc              	   C   s  t d ddlm} ||}|d }|jdv rt|}n2|jdv r(t|}n(|jdkr2t|}n|jdkrJt	d	d
dd\}}|t
 ||}ntt|}|jdkr\|jdd n5|jdkrh|jdd n)|jdkss|jdrz|jdd n|jdv r|jdd n|jdkr|jdd d| v r|jdd |jdkr|jdd d| v r|jdd i }|jdr|jdv rg d }n|jd!krddd"d#dd$g}d }nt	d	d#dddd%\}}t||}t||}| jjr|| n+| jjr|tj||f  n| jjr||tjd&f | n||| |D ]9}	|	j|v r0q&d'|	j  }
d(|
v r?q&t!t"d) t#||	jsNJ W d    n	1 sYw   Y  q&t$|}d*d+ |D }t%|&|}t%|&|}|rt'd,|j d-| d S ).Nr'   r   r)   
Attributes)HalvingRandomSearchCVRandomizedSearchCVHalvingGridSearchCVGridSearchCV)rj   rn   rq   SparseCoderFrozenEstimator      )	n_samples
n_featuresrandom_stateSelectKBestrw   )kDummyClassifier
stratified)strategyCCAPLSr   )n_components)GaussianRandomProjectionSparseRandomProjectionTSNE)
perplexitymax_iter)r      r   )r   
Vectorizer)CountVectorizerHashingVectorizer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?DictVectorizer)foobar   )r   baz)r   r   n_redundant	n_classesr   . zonly categoryc                 S   s   g | ]}|j qS r   r3   )r   attrr   r   r   r   %  s    z1test_fit_docstring_attributes.<locals>.<listcomp>zUndocumented attributes for z: )(r;   r<   r'   r*   rH   rs   ri   ru   r}   r   r   r!   nextr   
set_paramsr.   
get_paramsr>   r   r   __sklearn_tags__target_tagsone_d_labelstwo_d_labelsrz   c_
input_tagsthree_d_arraynewaxisr4   rT   desclowerr   FutureWarninghasattr_get_all_fitted_attributesset
differencerU   )r4   rt   r*   doc
attributesestXr1   skipped_attributesr   r   fit_attrfit_attr_namesundocumented_attrsr   r   r   test_fit_docstring_attributes   s   




















r   c                 C   s   t | j }t ; tjdtd t| jD ]&}t	| j|}t
|ts&qzt	| | W n ttfy8   Y qw || qW d   n1 sIw   Y  dd |D S )zBGet all the fitted attributes of an estimator including propertieserrorr   Nc                 S   s$   g | ]}| d r|d s|qS )r0   )r>   r.   )r   r   r   r   r   r   D  s   $ z._get_all_fitted_attributes.<locals>.<listcomp>)list__dict__keysr?   r@   filterwarningsr   dir	__class__rN   
isinstancepropertyAttributeErrorappend)	estimatorr   r4   objr   r   r   r   .  s    

r   c                  C   sL   t jt jt jt jt jg} t| dddgd d}t| dgd| d dS )	z>Check docstrings parameters of related metrics are consistent.Taveragezero_division)include_paramsexclude_paramsa  This parameter is required for multiclass/multilabel targets\.
        If ``None``, the metrics for each class are returned\. Otherwise, this
        determines the type of averaging performed on the data:
        ``'binary'``:
            Only report results for the class specified by ``pos_label``\.
            This is applicable only if targets \(``y_\{true,pred\}``\) are binary\.
        ``'micro'``:
            Calculate metrics globally by counting the total true positives,
            false negatives and false positives\.
        ``'macro'``:
            Calculate metrics for each label, and find their unweighted
            mean\.  This does not take label imbalance into account\.
        ``'weighted'``:
            Calculate metrics for each label, and find their average weighted
            by support \(the number of true instances for each label\)\. This
            alters 'macro' to account for label imbalance; it can result in an
            F-score that is not between precision and recall\.[\s\w]*\.*
        ``'samples'``:
            Calculate metrics for each instance, and find their average \(only
            meaningful for multilabel classification where this differs from
            :func:`accuracy_score`\)\.r   )r   descr_regex_patternN)	r   precision_recall_fscore_supportf1_scorefbeta_scoreprecision_scorerecall_scorer   rT   split)metrics_to_checkdescription_regexr   r   r   3test_precision_recall_f_score_docstring_consistencyG  s$   
r   c                   C   s   t ttgg dddgd dS )z?Check docstrings parameters stacking estimators are consistent.)cvn_jobsrl   verboseTfinal_estimator_)r   include_attrsexclude_attrsN)r   r   r   r   r   r   r   8test_stacking_classifier_regressor_docstring_consistencyx  s   
r   )=rA   rC   osr?   r   pkgutilr   numpyrz   r;   r,   r   sklearn.datasetsr   sklearn.ensembler   r   sklearn.experimentalr   r	   sklearn.linear_modelr   sklearn.preprocessingr   sklearn.utilsr   -sklearn.utils._test_common.instance_generatorr   sklearn.utils._testingr   r   r   r   r   sklearn.utils.deprecationr   sklearn.utils.estimator_checksr   r   r@   simplefilterr   r   dirname__file__sklearn_pathr   r=   rF   rO   rf   ri   ru   r}   markr   parametrizer   r   r   r   r   r   r   r   <module>   sV   



O

	y
0