o
    d
                     @  sr   d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlZej	dd	d
Z
dddZej		ddddZdS )    )annotationsN)	Generatorold_namestrnew_namereturnGenerator[None, None, None]c              
   c  sx    zdV  W dS  t y; } z(|js t|jd }|| |}|f}t|jdkr3||jdd  }||_ d}~ww )z.
    Rewrite the message of an exception.
    Nr      )	Exceptionargsr   replacelen)r   r   errmsgr    r   K/app/.heroku/python/lib/python3.10/site-packages/pandas/util/_exceptions.pyrewrite_exception   s   r   intc                  C  sp   ddl } tj| j}tj|d}t }d}|r6t|}|	|r1|	|s1|j
}|d7 }n	 |S |s|S )zb
    Find the first place in the stack that is not inside pandas
    (tests notwithstanding).
    r   Ntestsr	   )Zpandasospathdirname__file__joininspectcurrentframegetfile
startswithf_back)pdZpkg_dirZtest_dirframenfnamer   r   r   find_stack_level   s   

r#   target_messagetarget_categorytype[Warning]new_messagenew_categorytype[Warning] | Nonec           	      c  s    |du r|}t jdd}dV  W d   n1 sw   Y  t|dkrUt| }|D ])}|j|u rBt|t|jrB|}|}n|j|j}}t j	|||j
|jd q-dS dS )a  
    Rewrite the message of a warning.

    Parameters
    ----------
    target_message : str
        Warning message to match.
    target_category : Warning
        Warning type to match.
    new_message : str
        New warning message to emit.
    new_category : Warning or None, default None
        New warning type to emit. When None, will be the same as target_category.
    NT)recordr   )messagecategoryfilenamelineno)warningscatch_warningsr   recompiler,   searchr   r+   warn_explicitr-   r.   )	r$   r%   r'   r(   r*   matchwarningr,   r+   r   r   r   rewrite_warning6   s.   

r7   )r   r   r   r   r   r   )r   r   )N)
r$   r   r%   r&   r'   r   r(   r)   r   r   )
__future__r   
contextlibr   r   r1   typingr   r/   contextmanagerr   r#   r7   r   r   r   r   <module>   s    
