U
    "Jj
                     @  s   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dddZ
d	d
ddZej	dddddddddZdS )    )annotationsN)	GeneratorstrzGenerator[(None, None, None)])old_namenew_namereturnc              
   c  s   z
dV  W nr t k
r| } zT|js$ t|jd }|| |}|f}t|jdkrd||jdd  }||_ W 5 d}~X Y nX dS )z.
    Rewrite the message of an exception.
    Nr      )	Exceptionargsr   replacelen)r   r   errmsgr
    r   x/var/www/api.dyntland.com/public_html/python_social_comments/venv/lib/python3.8/site-packages/pandas/util/_exceptions.pyrewrite_exception   s    
r   int)r   c                  C  sj   ddl } tj| j}tj|d}t }d}|rft|}|	|rf|	|sf|j
}|d7 }q0qfq0|S )zb
    Find the first place in the stack that is not inside pandas
    (tests notwithstanding).
    r   NZ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!   ztype[Warning]ztype[Warning] | None)target_messagetarget_categorynew_messagenew_categoryr   c           	   	   c  s   |dkr|}t jdd}dV  W 5 Q R X t|dkrt| }|D ]N}|j|krnt|t|jrn|}|}n|j|j }}t j	|||j
|jd qDd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(    
 r3   )N)
__future__r   
contextlibr   r   r-   typingr   r+   contextmanagerr   r!   r3   r   r   r   r   <module>   s    