
    hB                    F   d dl mZ d dlmZ d dlZd dlmZ d dlmZm	Z	m
Z
mZ d dlZd dlmZ d dlmZmZ d dlmZ erd d	lmZ 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
Z	 	 d	 	 	 	 	 	 	 	 	 ddZddZddZ	 	 d	 	 	 	 	 	 	 ddZddZ G d d      Z G d d      Zdd dZg dZy)!    )annotations)wrapsN)dedent)TYPE_CHECKINGAnyCallablecast)cache_readonly)FT)find_stack_level)Mappingc                   |xs j                   }xs t        |xs |  d| dt              dfd       }|xs d| d}dj                   }j                  rj                  j	                  d      dk  rt        |      j                  j                  dd      \  }	}
}}|	s|r|
st        |      t        d	|
j                          d
| d| dt        |             |_        |S )a  
    Return a new function that emits a deprecation warning on use.

    To use this method for a deprecated function, another function
    `alternative` with the same signature must exist. The deprecated
    function will emit a deprecation warning, and in the docstring
    it will contain the deprecation directive with the provided version
    so it can be detected for future removal.

    Parameters
    ----------
    name : str
        Name of function to deprecate.
    alternative : func
        Function to use instead.
    version : str
        Version of pandas in which the method has been deprecated.
    alt_name : str, optional
        Name to use in preference of alternative.__name__.
    klass : Warning, default FutureWarning
    stacklevel : int, default 2
    msg : str
        The message to display in the warning.
        Default is '{name} is deprecated. Use {alt_name} instead.'
    z is deprecated, use 	 instead.c                 D    t        j                          | i |S )N
stacklevel)warningswarn)argskwargsalternativeklassr   warning_msgs     <D:\jyotish\venv\Lib\site-packages\pandas/util/_decorators.pywrapperzdeprecate.<locals>.wrapper?   s#    k5Z@D+F++    zUse `z
` instead.zdeprecate needs a correctly formatted docstring in the target function (should have a one liner short summary, and opening quotes should be in their own line). Found:

   z	
        z

        .. deprecated:: z
            z


        returnCallable[..., Any])	__name__FutureWarningr   __doc__countAssertionErrorsplitr   strip)namer   versionalt_namer   r   msgr   doc_error_msgempty1summaryempty2
doc_stringr   s    `  ``       @r   	deprecater3      s0   D /;//H"]EID6!5hZyIK
;, ,
 
-5
*-C	 &--.	0  $$T*Q. //.9.A.A.G.Ga.P+VG // 		  	 "E 		
	 
 Nr   c                h     "t        d      st              st        d      d fd}|S )a  
    Decorator to deprecate a keyword argument of a function.

    Parameters
    ----------
    old_arg_name : str
        Name of argument in function to deprecate
    new_arg_name : str or None
        Name of preferred argument in function. Use None to raise warning that
        ``old_arg_name`` keyword is deprecated.
    mapping : dict or callable
        If mapping is present, use it to translate old arguments to
        new arguments. A callable must do its own value checking;
        values not found in a dict will be forwarded unchanged.

    Examples
    --------
    The following deprecates 'cols', using 'columns' instead

    >>> @deprecate_kwarg(old_arg_name='cols', new_arg_name='columns')
    ... def f(columns=''):
    ...     print(columns)
    ...
    >>> f(columns='should work ok')
    should work ok

    >>> f(cols='should raise warning')  # doctest: +SKIP
    FutureWarning: cols is deprecated, use columns instead
      warnings.warn(msg, FutureWarning)
    should raise warning

    >>> f(cols='should error', columns="can't pass do both")  # doctest: +SKIP
    TypeError: Can only specify 'cols' or 'columns', not both

    >>> @deprecate_kwarg('old', 'new', {'yes': True, 'no': False})
    ... def f(new=False):
    ...     print('yes!' if new else 'no!')
    ...
    >>> f(old='yes')  # doctest: +SKIP
    FutureWarning: old='yes' is deprecated, use new=True instead
      warnings.warn(msg, FutureWarning)
    yes!

    To raise a warning that a keyword will be removed entirely in the future

    >>> @deprecate_kwarg(old_arg_name='cols', new_arg_name=None)
    ... def f(cols='', another_param=''):
    ...     print(cols)
    ...
    >>> f(cols='should raise warning')  # doctest: +SKIP
    FutureWarning: the 'cols' keyword is deprecated and will be removed in a
    future version please takes steps to stop use of 'cols'
    should raise warning
    >>> f(another_param='should not raise warning')  # doctest: +SKIP
    should not raise warning

    >>> f(cols='should raise warning', another_param='')  # doctest: +SKIP
    FutureWarning: the 'cols' keyword is deprecated and will be removed in a
    future version please takes steps to stop use of 'cols'
    should raise warning
    getzAmapping from old to new argument values must be dict or callable!c                V     t               d fd       }t        t        |      S )Nc            
     F   |j                  d       }|Cdt               dt               }t        j                  |t        	       ||<    | i |S Ht              r	 |      }nj                  ||      }d dt        |       d dt        |       d	}n|}dt               dt               d}t        j                  |t        	       |j                        &dt               dt               d	}t        |      ||<    | i |S )
Nzthe ze keyword is deprecated and will be removed in a future version. Please take steps to stop the use of r   =z keyword is deprecated, use r   zCan only specify z or z, not both.)popreprr   r   r$   callabler5   	TypeError)
r   r   old_arg_valuer-   new_arg_valuefuncmappingnew_arg_nameold_arg_namer   s
        r   r   z:deprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper   ss   "JJ|T:M('tL12 34484F3GI 
 MM#}L+8F<(000(((/(>(/M=(Q|nAd=.A-B C+'.$}*=)>iI  %2MtL12 3#L12)= 
 c=ZH::l+7+D,>+? @"<01>  $C.('4|$(((r   r    )r   r	   r   )r?   r   r@   rA   rB   r   s   ` r   _deprecate_kwargz)deprecate_kwarg.<locals>._deprecate_kwarg   s.    	t'	) '	) 
'	)R Awr   r?   r   r!   r   )hasattrr;   r<   )rB   rA   r@   r   rC   s   ```` r   deprecate_kwargrF   d   s?    F 77E#:8GCTO
 	
+  + Z r   c                    d| v r| j                  d       | syt        |       dk(  r	d| d    dS | d   }dj                  | d	d D cg c]
  }d|z   dz    c}      }d
| d| dS c c}w )a5  
    Convert the allow_args argument (either string or integer) of
    `deprecate_nonkeyword_arguments` function to a string describing
    it to be inserted into warning message.

    Parameters
    ----------
    allowed_args : list, tuple or int
        The `allowed_args` argument for `deprecate_nonkeyword_arguments`,
        but None value is not allowed.

    Returns
    -------
    str
        The substring describing the argument list in best way to be
        inserted to the warning message.

    Examples
    --------
    `format_argument_list([])` -> ''
    `format_argument_list(['a'])` -> "except for the arguments 'a'"
    `format_argument_list(['a', 'b'])` -> "except for the arguments 'a' and 'b'"
    `format_argument_list(['a', 'b', 'c'])` ->
        "except for the arguments 'a', 'b' and 'c'"
    self    z except for the argument 'r   'z, Nz except for the arguments z and ')removelenjoin)
allow_argslastxr   s       r   _format_argument_listrS      s    4 &!	ZA	+JqM?!<<"~yyCRAA#'C-AB+D6vQ?? Bs   A&c                    | yd|  S )zCSpecify which version of pandas the deprecation will take place in.zIn a future version of pandaszStarting with pandas version  )r+   s    r   future_version_msgrV     s    ..wi88r   c                      fd}|S )a  
    Decorator to deprecate a use of non-keyword arguments of a function.

    Parameters
    ----------
    version : str, optional
        The version in which positional arguments will become
        keyword-only. If None, then the warning message won't
        specify any particular version.

    allowed_args : list, optional
        In case of list, it must be the list of names of some
        first arguments of the decorated functions that are
        OK to be given as positional arguments. In case of None value,
        defaults to list of all arguments not having the
        default value.

    name : str, optional
        The specific name of the function to show in the warning
        message. If None, then the Qualified name of the function
        is used.
    c                    t        j                         }		nn|j                  j                         D cg c]J  }|j                  |j
                  |j                  fv r$|j                  |j                  u r|j                  L c}|j                  j                         D cg c]R  }|j                  |j
                  |j                  fv r*|j                  vr|j                  |j                        n|T }}|j                  d        |j                  |      }t              t               d
xs  j                   dt!                fd       }||_        |S c c}w c c}w )Nkindc                    | j                   S NrY   )ps    r   <lambda>zBdeprecate_nonkeyword_arguments.<locals>.decorate.<locals>.<lambda><  s    affr   )key)
parametersz all arguments of z!{arguments} will be keyword-only.c                     t        |       kD  r=t        j                  j                  t	                    t
        t                       | i |S )N)	argumentsr   )rN   r   r   formatrS   r$   r   )r   r   rP   r?   r-   num_allow_argss     r   r   zAdeprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapperE  sJ    4y>)JJ)>z)JJK!/1
 (((r   )inspect	signaturer`   valuesrZ   POSITIONAL_ONLYPOSITIONAL_OR_KEYWORDdefaultemptyr*   replaceKEYWORD_ONLYsortrN   rV   __qualname__r   __signature__)r?   old_sigr]   
new_paramsnew_sigr   rP   r-   rd   allowed_argsr*   r+   s   `     @@@r   decoratez0deprecate_nonkeyword_arguments.<locals>.decorate&  s   ##D)#%J !++2244A66a//1H1HIIII( 4J ''..0
 1	 1,,a.E.EFFFF*, II1>>I*
  1 	 
 	,-//Z/8Z!'*++=(t(())LN 	
 
t	) 
	) !(M
s   AE1*AE6rU   )r+   rt   r*   ru   s   ``` r   deprecate_nonkeyword_argumentsrv   
  s    8,\ Or   c                      d fd}|S )a  
    A decorator to take docstring templates, concatenate them and perform string
    substitution on them.

    This decorator will add a variable "_docstring_components" to the wrapped
    callable to keep track the original docstring template for potential usage.
    If it should be consider as a template, it will be saved as a string.
    Otherwise, it will be saved as callable, and later user __doc__ and dedent
    to get docstring.

    Parameters
    ----------
    *docstrings : None, str, or callable
        The string / docstring / docstring template to be appended in order
        after default docstring under callable.
    **params
        The string which would be used to format docstring template.
    c           	     f   g }| j                   r$|j                  t        | j                                D ][  }|t        |d      r|j	                  |j
                         .t        |t              s|j                   sK|j                  |       ] |D cg c]4  }t        |t              r t              dkD  r |j                  di n|6 }}dj                  |D cg c]-  }t        |t              r|nt        |j                   xs d      / c}      | _         || _        | S c c}w c c}w )N_docstring_componentsr   rI   rU   )r%   appendr   rE   extendry   
isinstancestrrN   rc   rO   )	decorateddocstring_components	docstring	componentparams_applied
docstringsparamss        r   	decoratorzdoc.<locals>.decoratork  sM   57 ''y/@/@(AB#I y"9:$++33 Is+y/@/@$++I6 $ 2	
 2	 )S)c&kAo I&v& 2	 	 
 GG
 "0	 "0I i- I--345 "0	
	 ! 	' )
s   9D)"2D.)r~   r   r!   r   rU   )r   r   r   s   `` r   docr   W  s    ($L r   c                  (    e Zd ZdZddZddZddZy)Substitutiona/  
    A decorator to take a function's docstring and perform string
    substitution on it.

    This decorator should be robust even if func.__doc__ is None
    (for example, if -OO was passed to the interpreter)

    Usage: construct a docstring.Substitution with a sequence or
    dictionary suitable for performing substitution; then
    decorate a suitable function with the constructed object. e.g.

    sub_author_name = Substitution(author='Jason')

    @sub_author_name
    def some_function(x):
        "%(author)s wrote this function"

    # note that some_function.__doc__ is now "Jason wrote this function"

    One can also use positional arguments.

    sub_first_last_names = Substitution('Edgar Allen', 'Poe')

    @sub_first_last_names
    def some_function(x):
        "%s %s wrote the Raven"
    c                8    |r|rt        d      |xs || _        y )Nz+Only positional or keyword args are allowed)r'   r   rH   r   r   s      r   __init__zSubstitution.__init__  s    F !NOOnfr   c                ^    |j                   xr |j                   | j                  z  |_         |S r\   )r%   r   )rH   r?   s     r   __call__zSubstitution.__call__  s$    ||Bt{{(Br   c                r    t        | j                  t              r | j                  j                  |i | yy)z8
        Update self.params with supplied args.
        N)r|   r   dictupdater   s      r   r   zSubstitution.update  s0     dkk4(DKK// )r   N)r!   NonerD   )r#   
__module__ro   r%   r   r   r   rU   r   r   r   r     s    8%0r   r   c                  .    e Zd ZU dZded<   dddZd	dZy)
Appenderaf  
    A function decorator that will append an addendum to the docstring
    of the target function.

    This decorator should be robust even if func.__doc__ is None
    (for example, if -OO was passed to the interpreter).

    Usage: construct a docstring.Appender with a string to be joined to
    the original docstring. An optional 'join' parameter may be supplied
    which will be used to join the docstring and addendum. e.g.

    add_copyright = Appender("Copyright (c) 2009", join='
')

    @add_copyright
    def my_dog(has='fleas'):
        "This docstring will have a copyright below"
        pass
    
str | Noneaddendumc                ^    |dkD  rt        ||      | _        || _        y || _        || _        y )Nr   )indents)indentr   rO   )rH   r   rO   r   s       r   r   zAppender.__init__  s0    Q;"8W=DM 	 %DM	r   c                   |j                   r|j                   nd|_         | j                  r| j                  nd| _        |j                   | j                  g}t        | j                  j                  |            |_         |S )NrI   )r%   r   r   rO   )rH   r?   docitemss      r   r   zAppender.__call__  sX    '+||t||)-BLL$--0diinnX67r   N)rI   r   )r   r   rO   r}   r   intr!   r   )r?   r   r!   r   )r#   r   ro   r%   __annotations__r   r   rU   r   r   r   r     s    & r   r   c                    | rt        | t              sydj                  dgdg|z  z         }|j                  | j                  d            S )NrI   r   z    )r|   r}   rO   r(   )textr   jointexts      r   r   r     sE    z$,wwv7 223H==D)**r   )r   r
   r3   rF   rv   r   rV   r   )NN   N)r*   r}   r   r"   r+   r}   r,   r   r   ztype[Warning] | Noner   r   r-   r   r!   Callable[[F], F])Nr   )
rB   r}   rA   r   r@   z/Mapping[Any, Any] | Callable[[Any], Any] | Noner   r   r!   r   )rP   z	list[str]r!   r}   )r+   r   r!   r}   )NN)r+   r   rt   zlist[str] | Noner*   r   r!   r   )r   zNone | str | Callabler!   r   )rJ   )r   r   r   r   r!   r}   ) 
__future__r   	functoolsr   re   textwrapr   typingr   r   r   r	   r   pandas._libs.propertiesr
   pandas._typingr   r   pandas.util._exceptionsr   collections.abcr   r3   rF   rS   rV   rv   r   r   r   r   __all__rU   r   r   <module>r      sK   "      2 5'  "&H
H#H H 	H
  H H 
H H\ @D	uuu =u 	u
 up#@L9 &*JJ"J J 	JZ:B,0 ,0^" "J+	r   