
    o[weG                     r    d dl Zd dlZd dlmZ d dlmc mZ d dl	m
Z
mZmZmZ d dlmZ  G d d          ZdS )    N)ChainedAssignmentError)	DataFrameNaTSeries
date_rangec            
          e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zej                            d ej        ddd           ej        ddd           ej        ddd          g          d             Zd Zej                            dd ej        dej                  g          d             Zd Zd  Zd! Zd" Zd# Zd$ Zej                            dd%d&g          d'             Zej                            d(ddg          ej                            d)g d*          d+                         Z d, Z!d- Z"d.S )/TestDataFrameInterpolatec                    t          t          d          t          d          t          d          g          }|j        j        dk    sJ |                                }t          |d         |d         dz  |d         g          }t          j        ||           |                                }|                                }|                                }t          j	        ||           d S )Nz1+1jnanz2+2jcr         ?   )
r   complexfloatdtypekindinterpolatetmassert_series_equalto_frameassert_frame_equal)selfserresexpecteddfs        Klib/python3.11/site-packages/pandas/tests/frame/methods/test_interpolate.pytest_interpolate_complexz1TestDataFrameInterpolate.test_interpolate_complex   s    gfoouU||WV__EFFy~$$$$oo3q63q6C<Q899
sH---\\^^nn$$&&
c8,,,,,    c                 x   t          t          dd                    }|                                }t          |d<    ||                                          } ||          }t          j        ||           |j                            d          } ||                                          } ||j                            d                    }t          j        ||           ||d         z
  }	 ||	                                          }
 |||d         z
            }t          j        |
|           d S )Nz
2012-01-01   )periodsr   z
US/Pacificr   )	r   r   copyr   r   r   assert_equaldttz_localize)r   frame_or_seriesorigr   r   r   ser_tzres_tzexpected_tzser_tdres_tdexpected_tds               r   $test_interpolate_datetimelike_valuesz=TestDataFrameInterpolate.test_interpolate_datetimelike_values   s*   jq999::iikkAoc""..00"?4((
X&&& ##L11 ((4466%odg&9&9,&G&GHH
,,, s1v ((4466%odT!Wn55
,,,,,r   c                    |rC|t           u r:t          j                            d          }|j                            |            |dt          j        dg          }|j        }|	                    d            |g d          }t          j        ||           t          j        ||j                  sJ |                                d         dk    sJ d S )	Nz'.values-based in-place check is invalid)reason   r   Tinplace)r2   r   r   r   )r   pytestmarkxfailnode
add_markernpr   valuesr   r   r$   shares_memorysqueeze)r   r'   using_array_managerrequestr6   objr(   r   s           r   test_interpolate_inplacez1TestDataFrameInterpolate.test_interpolate_inplace5   s     	*?i#?#?;$$,U$VVDL##D)))oq"&!n--z%%%"?;;;//
X&&& cj11111||~~a C''''''r   c                 $   t          ddt          j        dgdddt          j        gg dt          d          d          }t          g dg d	g dt          d          d          }d
}t	          j        t          |          5  |                                }d d d            n# 1 swxY w Y   t	          j        ||           |d         j	        }|d         j
        }|rEt          j        ||d         j	                  sJ t          j        ||d         j	                  sJ nDt          j        ||d         j	                  rJ t          j        ||d         j	                  rJ t	          j        t          |          5  |                    d          }d d d            n# 1 swxY w Y   |J t	          j        ||           t          j        |d         j	        |          sJ t          j        |d         j	        |          sJ d S )Nr2   r      	   r2   r      r!   abcdABCD      ?       @      @      @)rN   rQ         "@rR   'DataFrame.interpolate with object dtypematchrK   rL   Tr3   )r   r:   r   listr   assert_produces_warningFutureWarningr   r   _valuesr;   r<   )	r   using_copy_on_writer   r   msgresultcvaluesdvaluesr   s	            r   test_interp_basicz*TestDataFrameInterpolate.test_interp_basicF   s   BFA&Arv&!\\&\\	 
 
 ))))))!\\&\\	 
 
 8'SAAA 	& 	&^^%%F	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&
fh/// S'/S'. 	F#GVC[-@AAAAA#GVC[-@AAAAAA'1DEEEEE'1DEEEEE'SAAA 	/ 	/.....C	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/{{{
b(+++ 39999939999999s$   B%%B),B)F((F,/F,c                    t          ddt          j        dgdddt          j        gg dt          d          d          }d}t	          j        t          |	          5  |                    d
                                          }d d d            n# 1 swxY w Y   |                    d
          }d|j	        d<   d|j	        d<   t	          j
        ||           d S )Nr2   r   rC   rD   rE   rG   rH   rS   rT   rK   rF   rF   rI   )r!   rJ   )r   r:   r   rV   r   rW   rX   	set_indexr   locr   )r   r   r[   r\   r   s        r   &test_interp_basic_with_non_range_indexz?TestDataFrameInterpolate.test_interp_basic_with_non_range_indexo   s   BFA&Arv&!\\&\\	 
 
 8'SAAA 	5 	5\\#&&2244F	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5<<$$ V V
fh/////s   (BBBc                     t                      }|                                }||usJ |}t          j        ||           d S )N)r   r   r   r   r   r   r\   r   s       r   test_interp_emptyz*TestDataFrameInterpolate.test_interp_empty   sI    [[!!R
fh/////r   c                     t          ddt          j        dgdddt          j        gg dd          }d}t          j        t
          |          5  |                    d	
           d d d            d S # 1 swxY w Y   d S )Nr2   r   rC   rD   rE   rI   rJ   rK   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.rT   not_a_methodmethod)r   r:   r   r5   raises
ValueErrorr   r   r   r[   s      r   test_interp_bad_methodz/TestDataFrameInterpolate.test_interp_bad_method   s    BFA&Arv&!\\ 
 
< 	 ]:S111 	2 	2NN.N111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   A33A7:A7c                    t          ddt          j        dgdddt          j        gg dt          d          d	          }|d
                                         }t          g dd
          }t          j        ||           d}t          j        t          |          5  |d
                             d          }d d d            n# 1 swxY w Y   t          g dd
          }t          j        ||           d S )NrN   rO   rQ   r2   rC   rD   rE   rG   rH   rI   rM   )name:The 'downcast' keyword in Series.interpolate is deprecatedrT   inferdowncastr2   r   rF   rC   )
r   r:   r   rV   r   r   r   r   rW   rX   )r   r   r\   r   r[   s        r   test_interp_comboz*TestDataFrameInterpolate.test_interp_combo   sC   3,Arv&!\\&\\	 
 
 C$$&&...S999
vx000J'SAAA 	; 	;W(('(::F	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;,,,S111
vx00000s   CCCc                    t          ddt          j        dgdddt          j        gg dt          d          d	          }d
}d}d}t	          j        t          |          5  t          j        t          |          5  |
                    d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t	          j        t          |          5  t          j        t          |          5  |d         
                    d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrN   rO   rQ   r2   rC   rD   rE   rG   rH   z'downcast must be either None or 'infer'=The 'downcast' keyword in DataFrame.interpolate is deprecatedrs   rT   int64ru   rI   )r   r:   r   rV   r5   rm   rn   r   rW   rX   r   )r   r   r[   msg2msg3s        r    test_inerpolate_invalid_downcastz9TestDataFrameInterpolate.test_inerpolate_invalid_downcast   sB   3,Arv&!\\&\\	 
 
 8NK]:S111 	1 	1+MFFF 1 10001 1 1 1 1 1 1 1 1 1 1 1 1 1 1	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 ]:S111 	6 	6+MFFF 6 63##W#5556 6 6 6 6 6 6 6 6 6 6 6 6 6 6	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6sl   !B7=B B7 B$	$B7'B$	(B77B;>B;D:9D"D:"D&	&D:)D&	*D::D>D>c                 $   t          ddt          j        dgt          j        dddgd          }|                    d          }d}t	          j        t          |          5  |                    d	
           d d d            d S # 1 swxY w Y   d S )Nr2   r   rC   rF   rI   rJ   rI   zkInterpolation with NaNs in the index has not been implemented. Try filling those NaNs before interpolating.rT   r;   rk   )r   r:   r   rb   r5   rm   NotImplementedErrorr   ro   s      r   test_interp_nan_idxz,TestDataFrameInterpolate.test_interp_nan_idx   s    aBFA.bfaA5FGGHH\\#; 	 ].c::: 	, 	,NN(N+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   !BB	B	c           	         t          j        d           t          ddt          j        ddt          j        dgg dd          }|                    d	          }|                                }|                    d
d          }d|j        d<   d|j        d<   t          j
        ||           |                    d          }d|j        d<   d|j        d<   t          j
        ||           |                    d          }d|j        d<   d|j        d<   t          j
        ||d           |                    d          }d|j        d<   d|j        d<   t          j
        ||           |                    d          }d|j        d<   d|j        d<   t          j
        ||           |                    d          }d|j        d<   d|j        d<   t          j
        ||d           d S )Nscipyr2   r   rC   r!      r2   r   rF   r!            rI   rK   rK   
polynomialrl   ordergUUU@ra   gu:@)r   rI   cubicrk   gv:@gb+hZ@nearestF)check_dtype	quadraticg^r@g!g@slineargX ;@zerorO   )r5   importorskipr   r:   r   rb   r#   r   rc   r   r   r   r   r   r\   s       r   test_interp_variousz,TestDataFrameInterpolate.test_interp_various   s   G$$$aArvq18O8O8OPP
 
 \\#7799|1==)V *W
fh///w//)V *W
fh///y11 V !W
fhEBBBB{33)V *W
fh///y11)V *W
fh///v.."V !W
fhEBBBBBBr   c           	      @   t          j        d           t          ddt          j        ddt          j        dgg dd          }|                    d	
          }|                                }d|j        d<   d|j        d<   t          j	        ||           d}t          j
        t          |          5  |                    d	d          }d d d            n# 1 swxY w Y   t          j	        ||                    t          j                             |                    d
          }|                                }|d         |d<   t          j	        ||           |                    d
          }d|j        d<   d|j        d<   t          j	        ||           d S )Nr   r2   r   rC   r!   r   r   r   barycentricrk   rF   )r   rI      )r!   rI   rz   rT   rt   )rl   rv   kroghrI   pchip      @)r5   r   r   r:   r   r   r#   rc   r   r   rW   rX   astyper{   )r   r   r\   r   r[   	expectedks         r   test_interp_alt_scipyz.TestDataFrameInterpolate.test_interp_alt_scipy   s   G$$$aArvq18O8O8OPP
 
 }557799 V V
fh///M'SAAA 	L 	L^^=7^KKF	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L
fhoobh&?&?@@@w//GGII	!#	#
fi000w// V"V
fh/////s   4CCCc           	         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g dd	          }|                    d
          }|                                }d|j        d<   d|j        d<   d|j        d<   |d                             t          j                  |d<   t          j	        ||           |                    dd          }t          j	        ||           |                    d
          }|                                }t          j	        ||           d S )Nr2   r   rC   rF   r!   r   r   rw   )r   r2   r   rF   rC   axis)rF   r2   )r   r   )r2   rF   r;   r   rl   r   )
r   r:   r   r   r#   rc   r   float64r   r   rf   s       r   test_interp_rowwisez,TestDataFrameInterpolate.test_interp_rowwise  s3   q"&!$q!RV$FAq!$rvq!$<< 
 
 Q''7799TTTqk((44
fh///Qx88
fh///Q''>>##
fh/////r   zaxis_name, axis_numberrowsr   rows_0)idindexindex_0columnsr2   	columns_1c                    dt           j        dgdt           j        dgg dd}t          |t           j                  }|                    |d	          }|                    |d	          }t          j        ||           d S )
Nr   r   r2   r   )r   r!   r   )r   r2   r   r   linearr   )r:   r   r   r   r   r   r   )r   	axis_nameaxis_numberdatar   r\   r   s          r   test_interp_axis_namesz/TestDataFrameInterpolate.test_interp_axis_names)  s~     rvq>q"&!nCCt2:...Yx@@>>{8>DD
fh/////r   c                     t          dddt          j        ddt          j        t          j        dg	g dd          }|                    d	           d S )
Nr         ?rN   rC   r   @   )	r2   r   rF   rC   rF   r   r2   r   )r   r2   r   )r   r:   r   r   r   r   s     r   test_rowwise_altz)TestDataFrameInterpolate.test_rowwise_alt:  s\    sCArvrvrB/// 
 
 	Ar   check_scipyFT)marksc                 |   t          t          j        t          j        dddgt          j        ddt          j        dgd          }|                                }|                                }d|j        d	<   t          j        ||           |r.|                    d
d          }t          j        ||           d S d S )Nr   g      ?r   g      r   g      )rF   rJ   r   r2   r   )r   r:   r   r   r#   rc   r   r   )r   r   r   r\   r   s        r   test_interp_leading_nansz1TestDataFrameInterpolate.test_interp_leading_nansD  s     6263a0D"&RT7UVV
 
 !!7799$V
fh/// 	4^^<q^AAF!&(33333	4 	4r   c           	      ^   t          ddt          j        dgg dt          j        dddgt          j        t          j        ddgg dd	          }d
}t          j        t
          |          5  |                    d                              |           d d d            d S # 1 swxY w Y   d S )Nr2   r   rC   )abr   dr!   r   rD   rw   )rI   rJ   rK   rL   EvCannot interpolate with all object-dtype columns in the DataFrame. Try setting at least one column to a numeric dtype.rT   objectr   )r   r:   r   r5   rm   	TypeErrorr   r   )r   r   r   r[   s       r   test_interp_raise_on_only_mixedz8TestDataFrameInterpolate.test_interp_raise_on_only_mixedT  s    BFA&)))faA&fbfa+!\\ 
 
) 	
 ]9C000 	7 	7IIh+++666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   +*B""B&)B&c                     t          g dg ddd          }d}t          j        t          |          5  |                                 d d d            d S # 1 swxY w Y   d S )N)r2   r   rF   )rC   r!   r   r   r   r   r   rT   )r   r5   rm   r   r   ro   s      r   %test_interp_raise_on_all_object_dtypez>TestDataFrameInterpolate.test_interp_raise_on_all_object_dtypef  s    YYYYYY77xHHH) 	
 ]9C000 	 	NN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                    t          dddt          j        dgi          }t          dg di          }|                                }|                                }|rat	          j                    5  |d                             d          }d d d            n# 1 swxY w Y   |J t	          j        ||           n5|d                             d          }|J t	          j        ||           |                                }d}|rrt	          j        t          t          f|	          5  |d                             dd
          }d d d            n# 1 swxY w Y   |J t	          j        ||           d S t	          j        t          |	          5  |d                             dd
          }d d d            n# 1 swxY w Y   |J t	          j        ||                    d                     d S )Nr   rN   rO   rQ   rM   Tr3   rs   rT   rt   )r4   rv   r{   )r   r:   r   r#   r   raises_chained_assignment_errorr   r   rW   rX   r   r   )r   rZ   r   r   expected_cowr\   return_valuer[   s           r   test_interp_inplacez,TestDataFrameInterpolate.test_interp_inplaceq  s   c34566c#7#7#7899wwyy 	4355 E E%c{66t6DDE E E E E E E E E E E E E E E'''!&,7777!#;2242@@L'''!&(333J 	D+ 67s   W W  &c{66tg6VVW W W W W W W W W W W W W W W  '''!&,77777+MEEE W W%c{66tg6VVW W W W W W W W W W W W W W W'''!&(//'*B*BCCCCCs6   0BB B-EEEGG	Gc                     t          g dt          j        dddgg dd          }|                    ddd	
          }|                    ddd
          }|J t	          j        ||           d S )NrM   rO   rP   rQ   )rF   r   r   r   )r   r   r   r   r2   F)rl   r   r4   T)r   r:   r   r   r   r   )r   r\   r   r   s       r   test_interp_inplace_rowz0TestDataFrameInterpolate.test_interp_inplace_row  s    &&&bfc3-D<<<XX
 
 %%XAu%MM))4)PP###
fh/////r   c           	         t          ddt          j        dgg dddt          j        dgg dd	          }t          t          j        g dd
          t          j        g dd          t          j        g dd
          t          j        g dd
          d	          }d}t	          j        t          |          5  |                    d           }d d d            n# 1 swxY w Y   t	          j        ||           t	          j        t          |          5  |ddg                             d           }d d d            n# 1 swxY w Y   t	          j        ||ddg                    d S )Nr2   r   rC   rw   rN   rO   rQ   rM   rH   r   r   r{   )rN   rO   rF   rQ   rz   rT   ru   rJ   rL   )	r   r:   r   arrayr   rW   rX   r   r   )r   r   r   r[   r\   s        r   test_interp_ignore_all_goodz4TestDataFrameInterpolate.test_interp_ignore_all_good  s   BFA&!\\3,)))	 
 
 Xlll)<<<Xlll':::X000	BBBX222)DDD	 
 
 N'SAAA 	3 	3^^T^22F	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3
fh/// 'SAAA 	? 	?c
^///>>F	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?
fb#sn55555s$   >C!!C%(C%EEEc                 n   d}t          d|          }t          j                            d                              ||f          }t          j        ||dk     <   t          |||          }|                    dd	          }|                    ddd
          }|J t          j        ||           d S )Nr!   z
2014-01-01)startr"   r   r   )r   r   r   r   timer   T)r   rl   r4   )	r   r:   randomdefault_rngr   r   r   r   r   )r   r"   idxr   r   r\   r   s          r   test_interp_time_inplace_axisz6TestDataFrameInterpolate.test_interp_time_inplace_axis  s    |W===y$$Q''../ABB6TCZ3$???%%1V%<<++64+PP###
fh/////r   )r   r   )r   r2   c                 |   t          j        ddd          }t          j        |          }t          t          j        |d          t          j        d          |                              |dz            }|                    d	|
          }|                    d	|
          }t          j	        ||           d S )Nr   d   i  )
   r2   r   )r   r   r   gGz?)r   r   rl   r   )
r:   linspacesinr   tilearangereindexr   r   r   )r   r   r   xyr   r\   r   s           r   test_interp_string_axisz0TestDataFrameInterpolate.test_interp_string_axis  s     K3%%F1IIG$$BIbMM1
 
 

'!e)'
$
$ 	 xi@@>>>DD
fh/////r   
multiblockrl   )ffillbfillpadc           
         |r|dv rt          j        |           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          }|rt          j        |d<   d|d<   |dk    r|nd} t          ||          |          }d| d}	t          j        t          |	          5  |	                    ||          }
d d d            n# 1 swxY w Y   t          j
        |
|           d S )N)r2   r   rN   rO   rP   rQ   g      @r   g       @g      $@rR   g      >@ri   rL   r   r   r   r   z"DataFrame.interpolate with method=z is deprecatedrT   r   )td&mark_array_manager_not_yet_implementedr   r:   r   getattrr   rW   rX   r   r   )r   r?   r   r   rl   r>   r   method2r   r[   r\   s              r   test_interp_fillna_methodsz3TestDataFrameInterpolate.test_interp_fillna_methods  sl     	?4>#9#95g>>>3S"&#63RVS$73RVRVT: 
 
  	fBsGBsG"eOO&&'72w''T222I6III'SAAA 	> 	>^^6^==F	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>
fh/////s   C''C+.C+c                     t                      }|                                }|                    d          }|J t          j        ||           d S )NTr3   )r   r#   r   r   r   r   s       r   test_interpolate_empty_dfz2TestDataFrameInterpolate.test_interpolate_empty_df  sM    [[7799--~~~
b(+++++r   c                     t          dg did          }t          j        t          d          5  |                                 d d d            d S # 1 swxY w Y   d S )Nr   )r2   Nr   Int64r   zdoes not implementrT   )r   r5   rm   r   r   r   s     r   test_interpolate_ea_raisez2TestDataFrameInterpolate.test_interpolate_ea_raise  s    \\\*':::].6JKKK 	 	NN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAN)#__name__
__module____qualname__r   r/   rA   r_   rd   rg   rp   rx   r~   r   r   r   r   r5   r6   parametrizeparamr   r   r   skip_if_no_scipyr   r   r   r   r   r   r   r   r   r   r    r   r   r	   r	      s       - - -- - -,( ( ("': ': ':R0 0 0$0 0 02 2 2$1 1 1(6 6 6*, , ,%C %C %CN0 0 060 0 02 [ FLx000FL!	222FLA+666	
 0 0 0   [|v|D8KLLLM 4 4 47 7 7$	 	 	D D D@0 0 06 6 6:0 0 0 [5n7UVV	0 	0 WV	0 [\D%=99[X'@'@'@AA0 0 BA :904, , ,    r   r	   )numpyr:   r5   pandas.errorsr   pandas.util._test_decoratorsutil_test_decoratorsr   pandasr   r   r   r   pandas._testing_testingr   r	   r   r   r   <module>r     s         0 0 0 0 0 0 ) ) ) ) ) ) ) ) )                 i i i i i i i i i ir   