o
    g                  
   @   s8  d dl Zd dlZd dlmZ d dlmZmZmZm	Z	 d dl
mZ d dlmZ dd Zdd Zejd	g d
dd Zdd Zdd Zdd Zdd Zejdeddde	dddde	ddddddgejdd dgd d! Zd"d# Zd$d% Zd&d' Zejd(g d)d*d+ Zd,d- Z d.d/ Z!dS )0    N)UnsupportedFunctionCall)	DataFrameDatetimeIndexSeries
date_range)ExponentialMovingWindowc                  C   s0   t ddddtjdgi} |  | jdd  d S )NBr                  ?com)r   npnanewmmean)df r   Z/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pandas/tests/window/test_ewm.pytest_doc_string   s   r   c              	   C   s
  | t dj}|dd |dd |dd |dd |dd d	 |dd d
 |dd d d}tjt|d |ddd W d    n1 sGw   Y  tjt|d |ddd W d    n1 sdw   Y  tjt|d |ddd W d    n1 sw   Y  d}tjt|d |dd W d    n1 sw   Y  d}tjt|d |dd W d    n1 sw   Y  d}tjt|d |dd W d    n1 sw   Y  d}dD ]}tjt|d ||d W d    n1 sw   Y  qd S )N   r   r         ?)spanalphag      ?halflife)r   r   )r   r   )r   r   z8comass, span, halflife, and alpha are mutually exclusivematch)r   r   )r   r   )r   r   z comass must satisfy: comass >= 0      zspan must satisfy: span >= 1z#halflife must satisfy: halflife > 0r   z"alpha must satisfy: 0 < alpha <= 1)r    r   )ranger   pytestraises
ValueError)frame_or_seriescmsgr   r   r   r   test_constructor   sJ   



r(   method)stdr   varc                 C   s   t tg ddd}d}tjt|d t|| ddd W d    n1 s'w   Y  tjt|d t|| tjd	 W d    d S 1 sHw   Y  d S )
N)r
   r      r   r   z2numpy operations are not valid with window objectsr   r	   r
      )dtype)r   r   r"   r#   r   getattrr   float64)r)   er'   r   r   r   test_numpy_compatC   s   "r2   c                  C   sR   d} t jt| d ttdjtdd W d    d S 1 s"w   Y  d S )Nz%times must be datetime64\[ns\] dtype.r   r   times)r"   r#   r$   r   r!   r   r   aranger'   r   r   r   !test_ewma_times_not_datetime_typeP   s   "r7   c                  C   sX   d} t jt| d ttdjtddd W d    d S 1 s%w   Y  d S )Nz,times must be the same length as the object.r   r   r   datetime64[ns]r3   	r"   r#   r$   r   r!   r   r   r5   astyper6   r   r   r   test_ewma_times_not_same_lengthV   s   ""r;   c                  C   sZ   d} t jt| d ttdjdtddd W d    d S 1 s&w   Y  d S )Nz6halflife must be a string or datetime.timedelta objectr   r   r	   r8   r   r4   r9   r6   r   r   r   #test_ewma_halflife_not_correct_type\   s   $"r=   c                 C   sL   d}t jt|d ttdj| d W d    d S 1 sw   Y  d S )NzKhalflife can only be a timedelta convertible argument if times is not None.r   r   r   )r"   r#   r$   r   r!   r   )halflife_with_timesr'   r   r   r    test_ewma_halflife_without_timesb   s   "r?   r4   
   zdatetime64[D]r8   2000DfreqperiodsUTCtime_colmin_periodsr
   c                 C   sl   | }t d}t j|d d d< t|tddddd}|j|||d }|jd	|d
 }t|| d S )N      $@r
   rA   rB   r@   rC   )ArG   )r   rH   r4         ?)r   rH   )	r   r5   r   r   r   r   r   tmassert_frame_equal)r>   r4   rH   r   datar   resultexpectedr   r   r   "test_ewma_with_times_equal_spacingh   s   
rQ   c                 C   sZ   | }d}t g d|}td}t|}|j||d }tg d}t|| d S )Nz23 days)z
2020-01-01z2020-01-10T00:04:05z2020-02-23T05:00:23r-   r<   )g        gE(?g*M?)	r   tz_localizer   r5   r   r   r   rL   rM   )tz_aware_fixturetzr   r4   rN   r   rO   rP   r   r   r   %test_ewma_with_times_variable_spacing|   s   
rU   c                 C   sZ   t td}tdg}tjtdd |jd| |d W d    d S 1 s&w   Y  d S )Nr	   NaTz$Cannot convert NaT values to integerr   皙?)r   r   r4   )r   r!   r   r"   r#   r$   r   )r>   serr4   r   r   r   test_ewm_with_nat_raises   s
   
"rY   c                 C   st   | }t d}t j|d d d< tdddd}t||d}|j||dd	  }|jd
dd	  }t|| d S )NrI   r
   rA   rB   r@   rC   rJ   r   r<   rJ   rK   r   )	r   r5   r   r   r   r   r   rL   assert_series_equal)r>   r   rN   r4   r   rO   rP   r   r   r   test_ewm_with_times_getitem   s   
r\   arg)r   r   r   r   c                    sr   | dd|d|i}t tdtddjd	i |  fdd jD } d } fdd|jD }||ks7J d S )
Nr	   adjust	ignore_narZ   c                       i | ]}|t  |qS r   r/   .0attrr   r   r   
<dictcomp>       z8test_ewm_getitem_attributes_retained.<locals>.<dictcomp>rJ   c                    r`   r   ra   rb   re   r   r   rf      rg   r   )r   r!   r   _attributes)r]   r^   r_   kwargsrP   	ewm_slicerO   r   re   r   $test_ewm_getitem_attributes_retained   s   "rk   c                  C   sf   t td} tt | jdd }W d    n1 sw   Y  | jdd }t|| d S )Nr	   rW   r   )	r   r!   rL   assert_produces_warningFutureWarningr   volr*   r[   )rX   rO   rP   r   r   r   test_ewm_vol_deprecated   s   ro   c                	   C   sV   t jtdd ttdjddtddddd	 W d    d S 1 s$w   Y  d S )
Nz)times is not supported with adjust=False.r   r	   rW   FrA   rB   rC   )r^   r4   )r"   r#   NotImplementedErrorr   r!   r   r   r   r   r   r   #test_ewma_times_adjust_false_raises   s   "rq   )"numpyr   r"   pandas.errorsr   pandasr   r   r   r   pandas._testing_testingrL   pandas.core.windowr   r   r(   markparametrizer2   r7   r;   r=   r?   r5   r:   rR   rQ   rU   rY   r\   rk   ro   rq   r   r   r   r   <module>   s>    ,
	


