U
    sVcw8                     @   sT   d dl Zd dlZd dlm  mZ d dlmZm	Z	m
Z
 d dlmZ G dd dZdS )    N)	DataFrameSeries
date_rangec                
   @   sD  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	e
jdd Ze
jdd Zdd Zejdejddddejddddejddddgdd  Zd!d" Zejd#d$ejd%e
jd&gd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zejdd5d6gd7d8 Zejd9d:d;d<gd=d> Zd?d@ ZdAS )BTestDataFrameInterpolatec                 C   s   |r&|t kr&tjjdd}|j| |dtjdg}|j}|j	dd |dddg}t
|| t||jstt| d dkstd S )Nz'.values-based in-place check is invalid)reason      Tinplaceg      ?)r   pytestmarkZxfailnodeZ
add_markernpnanvaluesinterpolatetmZassert_equalshares_memoryAssertionErrorZsqueeze)selfZframe_or_seriesusing_array_managerrequestr   objorigexpected r   O/tmp/pip-unpacked-wheel-xj8nt62q/pandas/tests/frame/methods/test_interpolate.pytest_interpolate_inplace   s    z1TestDataFrameInterpolate.test_interpolate_inplacec                 C   s
  t ddtjdgdddtjgddddgtdd}t d	d
ddgd	dddgddddgtdd}| }t|| |d j}|d j}t	||d jrt
t	||d jrt
|jdd}|d kst
t|| t	|d j|st
t	|d j|st
d S )Nr   r      	         abcdABCD      ?       @      @      @      "@r&   r'   Tr	   )r   r   r   listr   r   assert_frame_equalZ_valuesr   r   r   )r   dfr   resultZcvaluesZdvaluesresr   r   r   test_interp_basic    s2    





z*TestDataFrameInterpolate.test_interp_basicc                 C   s   t ddtjdgdddtjgddddgtdd}t d	d
ddgd	dddgddddgtdd}|d }|d}d|jd< d|jd< t|| d S )Nr   r   r   r   r    r!   r"   r#   r(   r)   r*   r+   r,   r&   r    r$   )r!   r%   )	r   r   r   r-   	set_indexr   locr   r.   r   r/   r   r0   r   r   r   &test_interp_basic_with_non_range_indexB   s&    



	


z?TestDataFrameInterpolate.test_interp_basic_with_non_range_indexc                 C   s.   t  }| }||k	st|}t|| d S )N)r   r   r   r   r.   r   r/   r0   r   r   r   r   test_interp_emptyZ   s
    z*TestDataFrameInterpolate.test_interp_emptyc              	   C   s`   t ddtjdgdddtjgddddgtdd}d	}tjt|d
 |jdd W 5 Q R X d S )Nr   r   r   r   r    r!   r"   r#   a  method must be one of \['linear', 'time', 'index', 'values', 'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'barycentric', 'krogh', 'spline', 'polynomial', 'from_derivatives', 'piecewise_polynomial', 'pchip', 'akima', 'cubicspline'\]. Got 'not_a_method' instead.matchZnot_a_methodmethod)r   r   r   r-   r   raises
ValueErrorr   r   r/   msgr   r   r   test_interp_bad_methodb   s    
	z/TestDataFrameInterpolate.test_interp_bad_methodc                 C   s   t ddtjdgdddtjgdddd	gtd
d}|d  }tddddgdd}t|| |d jdd}tddddgdd}t|| d S )Nr(   r)   r+   r   r   r   r   r    r!   r"   r#   r$   r*   )nameinferdowncast)r   r   r   r-   r   r   r   Zassert_series_equalr8   r   r   r   test_interp_combou   s    
	z*TestDataFrameInterpolate.test_interp_comboc              	   C   sZ   t ddtjdgtjdddgd}|d}d}tjt|d |jd	d
 W 5 Q R X d S )Nr   r   r   r    r$   r%   r$   zkInterpolation with NaNs in the index has not been implemented. Try filling those NaNs before interpolating.r:   r   r<   )r   r   r   r4   r   r>   NotImplementedErrorr   r@   r   r   r   test_interp_nan_idx   s    "
z,TestDataFrameInterpolate.test_interp_nan_idxc              	   C   sV  t ddtjddtjdgddddddd	gd
}|d}| }|jddd}d|jd< d|jd< t|| |jdd}d|jd< d|jd< t|| |jdd}d|jd< d|jd< tj||dd |jdd}d|jd< d|jd< t|| |jdd}d|jd< d|jd< t|| |jdd}d|jd< d|jd< tj||dd d S ) Nr   r   r   r!      r             r$   r&   r&   
polynomialr=   ordergUUU@r3   gu:@)rM   r$   Zcubicr<   gv:@gb+hZ@ZnearestF)Zcheck_dtypeZ	quadraticg^r@g!g@ZslineargX ;@Zzeror)   )	r   r   r   r4   copyr   r5   r   r.   r6   r   r   r   test_interp_various   s:    (












z,TestDataFrameInterpolate.test_interp_variousc              	   C   s   t ddtjddtjdgddddddd	gd
}|jdd}| }d|jd< d|jd< t|| |jddd}t||tj	 |jdd}| }|d |d< t|| |jdd}d|jd< d|jd< t|| d S )Nr   r   r   r!   rK   r    rL   rM   rN   rO   Zbarycentricr<   )r   r$      )r!   r$   rD   )r=   rF   Zkroghr$   Zpchip      @)
r   r   r   r   rS   r5   r   r.   astypeint64)r   r/   r0   r   Z	expectedkr   r   r   test_interp_alt_scipy   s$    (



z.TestDataFrameInterpolate.test_interp_alt_scipyc              	   C   s   t ddtjdgdddtjgtjdddgdtjddgddddgd}|jdd	}| }d|jd
< d|jd< d|jd< |d tj|d< t	|| |jddd}t	|| |jdd	}| }t	|| d S )Nr   r   r   r    r!   rU   rK   )r   r   r   r    r   axis)r    r   )r   r   )r   r    r   r[   r=   r   )
r   r   r   r   rS   r5   rW   float64r   r.   r8   r   r   r   test_interp_rowwise   s(    
	


z,TestDataFrameInterpolate.test_interp_rowwisezaxis_name, axis_numberZrowsr   Zrows_0)idindexZindex_0columnsr   Z	columns_1c                 C   s\   dt jdgdt jdgdddgd}t|t jd	}|j|d
d}|j|d
d}t|| d S )Nr   rU   r   rK   r   r!   rL   )r   r   r   Zdtypelinearr\   )r   r   r   r]   r   r   r.   )r   	axis_nameaxis_numberdatar/   r0   r   r   r   r   test_interp_axis_names   s
    
"z/TestDataFrameInterpolate.test_interp_axis_namesc                 C   sH   t dddtjddtjtjdg	ddd	dd	dddd
g	d}|jdd d S )Nr         ?r(   r   rL   @   r   r   r    )r   r   rZ   )r   r   r   r   )r   r/   r   r   r   test_rowwise_alt   s    z)TestDataFrameInterpolate.test_rowwise_altcheck_scipyFT)Zmarksc                 C   sr   t tjtjdddgtjddtjdgd}| }| }d|jd	< t|| |rn|jd
dd}t|| d S )Nrh   g      ?r   g      rH   g      )r    r%   rP   r   rQ   )r   r   r   r   rS   r5   r   r.   )r   rl   r/   r0   r   r   r   r   test_interp_leading_nans  s    $
z1TestDataFrameInterpolate.test_interp_leading_nansc              	   C   sx   t ddtjdgddddgtjddd	gtjtjd
d
gddddgd}d}tjt|d |dj|d W 5 Q R X d S )Nr   r   r   abcdr!   rK   r   r    )r$   r%   r&   r'   EvCannot interpolate with all object-dtype columns in the DataFrame. Try setting at least one column to a numeric dtype.r:   objectrZ   )r   r   r   r   r>   	TypeErrorrW   r   )r   r[   r/   rA   r   r   r   test_interp_raise_on_only_mixed  s    


z8TestDataFrameInterpolate.test_interp_raise_on_only_mixedc              	   C   sH   t dddgdddgddd	}d
}tjt|d |  W 5 Q R X d S )Nr   r   r    r   r!   rU   rH   rv   rb   ru   r:   )r   r   r>   rw   r   r@   r   r   r   %test_interp_raise_on_all_object_dtype'  s
    z>TestDataFrameInterpolate.test_interp_raise_on_all_object_dtypec                 C   s   |rt d tdddtjdgi}tdddddgi}| }|d jdd}|d ks\tt	|| | }|d jdd	d
}|d kstt	||
d d S )Nz$CoW: inplace keyword not yet handledrp   r(   r)   r+   r*   Tr	   rD   )r
   rF   rX   )r   skipr   r   r   rS   r   r   r   r.   rW   )r   Zusing_copy_on_writer/   r   r0   return_valuer   r   r   test_interp_inplace2  s    
z,TestDataFrameInterpolate.test_interp_inplacec                 C   sf   t ddddgtjdddgddddgd}|jdd	d
d}|jdd	dd}|d ksVtt|| d S )Nr(   r)   r*   r+   r    r   )rp   rq   rr   rc   r   F)r=   r[   r
   T)r   r   r   r   r   r   r.   )r   r0   r   r{   r   r   r   test_interp_inplace_rowB  s    $z0TestDataFrameInterpolate.test_interp_inplace_rowc              	   C   s   t ddtjdgddddgddtjdgddddgd	}t tjddddgd
dtjddddgddtjddddgd
dtjddddgd
dd	}|jd d}t|| |ddg jd d}t||ddg  d S )Nr   r   r   r    r(   r)   r+   r*   r#   r]   rb   rX   rE   r%   r'   )r   r   r   arrayr   r   r.   r6   r   r   r   test_interp_ignore_all_goodL  s$    

	z4TestDataFrameInterpolate.test_interp_ignore_all_goodc                 C   st   d}t d|d}tj||}tj||dk < t|||d}|jddd}|jddd	d
}|d ksdtt	|| d S )Nr!   z
2014-01-01)startperiodsrh   )r`   ra   rf   r   timer\   T)r[   r=   r
   )
r   r   randomZrandr   r   r   r   r   r.   )r   r   idxrf   r   r0   r{   r   r   r   test_interp_time_inplace_axisf  s    z6TestDataFrameInterpolate.test_interp_time_inplace_axis)r`   r   )ra   r   c                 C   sl   t ddd}t |}tt |dt d|dj|d d}|jd	|d
}|jd	|d
}t	|| d S )Nr   d   i  )
   r   r   )rf   r`   ra   gGz?)ra   rc   r=   r[   )
r   Zlinspacesinr   ZtileZarangeZreindexr   r   r.   )r   rd   re   xyr/   r0   r   r   r   r   test_interp_string_axiss  s    

  z0TestDataFrameInterpolate.test_interp_string_axisr=   ZffillZbfillpadc              	   C   s   |r|dks|dkrt | tddddtjdgdddtjd	d
gdddtjtjdgd}|j||d}|j||d}t|| d S )Nr   ra   r(   r)   r*   r+   g      @rV   g       @g      $@r,   g      >@)r$   r%   r&   r\   r   )	tdZ&mark_array_manager_not_yet_implementedr   r   r   Zfillnar   r   r.   )r   r   r[   r=   r   r/   r   r0   r   r   r   test_interp_fillna_methods  s    
z3TestDataFrameInterpolate.test_interp_fillna_methodsc              	   C   s^   t ddddgi}d}tjt|d |dd}W 5 Q R X t ddddgi}t|| d S )	Nrp   r   r   r    zzIn a future version of pandas all arguments of DataFrame.interpolate except for the argument 'method' will be keyword-onlyr:   r   r   )r   r   Zassert_produces_warningFutureWarningr   r.   )r   r/   rA   r0   r   r   r   r   %test_interpolate_pos_args_deprecation  s    z>TestDataFrameInterpolate.test_interpolate_pos_args_deprecationN)__name__
__module____qualname__r   r2   r7   r9   rB   rG   rJ   r   Zskip_if_no_scipyrT   rY   r^   r   r   Zparametrizeparamrg   rk   ro   rx   ry   r|   r}   r   r   r   r   r   r   r   r   r   r      sJ   "

&

	
 



r   )Znumpyr   r   Zpandas.util._test_decoratorsutilZ_test_decoratorsr   Zpandasr   r   r   Zpandas._testingZ_testingr   r   r   r   r   r   <module>   s
   