Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
sklearn
/
utils
/
__pycache__
/
File Content:
metaestimators.cpython-35.pyc
��(X� � @ s� d Z d d l m Z d d l m Z d d l Z d d l m Z d g Z Gd d � d e � Z d d � Z d d d � Z d S) zUtilities for meta-estimators� )� attrgetter)�update_wrapperN� )� safe_indexing�if_delegate_has_methodc @ s1 e Z d Z d Z d d � Z d d d � Z d S)�_IffHasAttrDescriptorat Implements a conditional property using the descriptor protocol. Using this class to create a decorator will raise an ``AttributeError`` if none of the delegates (specified in ``delegate_names``) is an attribute of the base object or the first found delegate does not have an attribute ``attribute_name``. This allows ducktyping of the decorated method based on ``delegate.attribute_name``. Here ``delegate`` is the first item in ``delegate_names`` for which ``hasattr(object, delegate) is True``. See https://docs.python.org/3/howto/descriptor.html for an explanation of descriptors. c C s, | | _ | | _ | | _ t | | � d S)N)�fn�delegate_names�attribute_namer )�selfr r r � r �/metaestimators.py�__init__ s z_IffHasAttrDescriptor.__init__Nc s� � d k rv xg � j D]E } y t | � � � } Wn t k rI w Yq Xt | � j � Pq Wt � j d � � � � � f d d � } t | � j � | S)N� c s � j � | | � S)N)r )�args�kwargs)�objr r r �<lambda>6 s z/_IffHasAttrDescriptor.__get__.<locals>.<lambda>���)r r �AttributeError�getattrr r r )r r �typeZ delegate_name�delegate�outr )r r r �__get__% s z_IffHasAttrDescriptor.__get__)�__name__� __module__�__qualname__�__doc__r r r r r r r s r c sC t � t � r t � � � t � t � s3 � f � � f d d � S)a� Create a decorator for methods that are delegated to a sub-estimator This enables ducktyping by hasattr returning True according to the sub-estimator. Parameters ---------- delegate : string, list of strings or tuple of strings Name of the sub-estimator that can be accessed as an attribute of the base object. If a list or a tuple of names are provided, the first sub-estimator that is an attribute of the base object will be used. c s t | � d | j �S)Nr )r r )r )r r r r O s z(if_delegate_has_method.<locals>.<lambda>)� isinstance�list�tuple)r r )r r r <