U
    3d                     @   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 G dd dZG dd dZ	ej
dd	d
 ZG dd dZG dd deZG dd deZG dd dZG dd dZG dd dZej
ddd ZG dd dZdd Zdd Zdd  Zej
dd!d" Zd#d$ Zd%d& ZdS )'    N)if_delegate_has_method)available_ifc                   @   s   e Zd Zdd ZdS )Prefixc                 C   s   d S N selfr   r   K/tmp/pip-unpacked-wheel-zrfo1fqw/sklearn/utils/tests/test_metaestimators.pyfunc   s    zPrefix.funcN)__name__
__module____qualname__r
   r   r   r   r	   r      s   r   c                   @   s(   e Zd ZdZe Zedddd ZdS )MockMetaEstimatorzThis is a mock meta estimatora_prefixZdelegatec                 C   s   dS )!This is a mock delegated functionNr   r   r   r   r	   r
      s    zMockMetaEstimator.funcN)r   r   r   __doc__r   r   r   r
   r   r   r   r	   r      s   r   z,ignore:if_delegate_has_method was deprecatedc                   C   sF   dt tjd jkstdt tjjks,tdt t jjksBtd S )Nr   r
   )strr   __dict__r   AssertionErrorr
   r   r   r   r	   test_delegated_docstring   s
    

r   c                   @   s,   e Zd ZdZd	ddZedddd ZdS )
MetaEstzA mock meta estimatorNc                 C   s   || _ || _d S r   sub_estbetter_sub_est)r   r   r   r   r   r	   __init__'   s    zMetaEst.__init__r   r   c                 C   s   d S r   r   r   r   r   r	   predict+   s    zMetaEst.predict)N)r   r   r   r   r   r   r   r   r   r   r	   r   $   s   
r   c                   @   s"   e Zd ZdZedddd ZdS )MetaEstTestTuplez:A mock meta estimator to test passing a tuple of delegatesr   r   c                 C   s   d S r   r   r   r   r   r	   r   3   s    zMetaEstTestTuple.predictNr   r   r   r   r   r   r   r   r   r	   r   0   s   r   c                   @   s&   e Zd ZdZeddgddd ZdS )MetaEstTestListz9A mock meta estimator to test passing a list of delegatesr   r   r   c                 C   s   d S r   r   r   r   r   r	   r   ;   s    zMetaEstTestList.predictNr   r   r   r   r	   r   8   s   r   c                   @   s   e Zd ZdZdd ZdS )
HasPredictz(A mock sub-estimator with predict methodc                 C   s   d S r   r   r   r   r   r	   r   C   s    zHasPredict.predictN)r   r   r   r   r   r   r   r   r	   r    @   s   r    c                   @   s   e Zd ZdZdS )HasNoPredictz+A mock sub-estimator with no predict methodN)r   r   r   r   r   r   r   r	   r!   G   s   r!   c                   @   s    e Zd ZdZejdejdZdS )HasPredictAsNDArrayz3A mock sub-estimator where predict is a NumPy array)
      )ZdtypeN)r   r   r   r   npZonesZint64r   r   r   r   r	   r"   M   s   r"   c                   C   s   t tt dstt tt dr(tt tt t dr@tt tt t dsXtt tt t drptt tt t drtt tt t dstd S )Nr   )hasattrr   r    r   r!   r   r   r   r   r   r	   test_if_delegate_has_methodS   s    r'   c                   @   s.   e Zd ZdZdddZedd dd	 Zd
S )AvailableParameterEstimatorzGThis estimator's `available` parameter toggles the presence of a methodT   c                 C   s   || _ || _d S r   	availablereturn_value)r   r+   r,   r   r   r	   r   a   s    z$AvailableParameterEstimator.__init__c                 C   s   | j S r   r+   estr   r   r	   <lambda>e       z$AvailableParameterEstimator.<lambda>c                 C   s   | j S )$This is a mock available_if function)r,   r   r   r   r	   available_funce   s    z*AvailableParameterEstimator.available_funcN)Tr)   )r   r   r   r   r   r   r3   r   r   r   r	   r(   ^   s   

r(   c                   C   sF   dt tjd jkstdt tjjks,tdt t jjksBtd S )Nr2   r3   )r   r(   r   r   r   r3   r   r   r   r	   test_available_if_docstringk   s    


r4   c                   C   s(   t t dstt tdddr$td S )Nr3   Fr-   )r&   r(   r   r   r   r   r	   test_available_ifw   s    r5   c               	   C   sB   t  } t |  t dd} tjtdd t |  W 5 Q R X d S )NFr-   zDThis 'AvailableParameterEstimator' has no attribute 'available_func'match)r(   r3   pytestZraisesAttributeErrorr.   r   r   r	    test_available_if_unbound_method|   s    

r:   c                  C   s   t t } t| dstdS )zCheck that we can check for an attribute that is a NumPy array.

    This is a non-regression test for:
    https://github.com/scikit-learn/scikit-learn/issues/21144
    r   N)r   r"   r&   r   )Z	estimatorr   r   r	   'test_if_delegate_has_method_numpy_array   s    
r;   c               	   C   sX   t   t dt tdd} W 5 Q R X tjtdd ttt	 d W 5 Q R X dS )z7Check the deprecation warning of if_delegate_has_methoderrorr   r   z%if_delegate_has_method was deprecatedr6   N)
warningscatch_warningssimplefilterFutureWarningr   r8   Zwarnsr&   r   r    )_r   r   r	   &test_if_delegate_has_method_deprecated   s
    
rB   c                  C   s8   d} t d| d}t|j}t|}| | ks4tdS )zYCheck that available_if methods can be pickled.

    Non-regression test for #21344.
    r#   Tr*   N)r(   pickledumpsr3   loadsr   )r,   r/   Zpickled_bytesZunpickled_funcr   r   r	   (test_available_if_methods_can_be_pickled   s
    
rF   )Znumpyr%   r8   r=   rC   Zsklearn.utils.metaestimatorsr   r   r   r   markfilterwarningsr   r   r   r   r    r!   r"   r'   r(   r4   r5   r:   r;   rB   rF   r   r   r   r	   <module>   s2   







