
    OwgAI                     6   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dl	Z
d dl	mZmZmZmZmZmZmZmZ d dlmZmZ d dlmZ ej4                  j6                  Zd Zd Zd	 Zd
 Z d Z!d Z"d Z#d Z$d Z%ej4                  jM                  d      d        Z'd Z(d Z)ej4                  jM                  d      d        Z*d Z+ej4                  jY                  dd ejZ                  dej\                        g      d        Z/d Z0ej4                  jY                  dejb                  ejd                  e3ddg      d        Z4d  Z5d! Z6ej4                  jY                  dd ejZ                  dej\                        g      d"        Z7d*d#Z8d*d$Z9d% Z:d& Z;d' Z<d( Z=d) Z>y)+    N)	Timestamp)is_platform_windows)	DataFrameDatetimeIndexIndexSeries_testingbdate_range
date_rangeread_hdf)_maybe_removeensure_clean_store)_test_decoratorsc                     t        j                         5 fd} t        t        j                  dt        j
                        t        dd            }t        j                  | | d|             t        t        d      dt        d      D cg c]  }d	| 	 c}
      }t        j                  | | d|             t        dt        j                  d      j                  d      z  t        t        d      t              t        t        d      D cg c]  }d| 	 c}t                    }t        j                  | | d|             t        t        d      t        d      d      }|j                  dd       t!        ddg      }t        j                  ||j"                  dkD     |       d d d        y c c}w c c}w # 1 sw Y   y xY w)Nc                 F     |j                   fd| i| t        |       S )Nkey)to_hdfr   )r   objkwargspaths      _/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/io/pytables/test_round_trip.py	roundtripz'test_conv_read_write.<locals>.roundtrip!   s(    CJJt///D#&&    
   dtype
2020-01-01periodsindexseriesfloat64i_r   r!   string_series皙?x         ABCDr*   i-columnsr!   frame   ABtableTr   appendzindex>2)where   )tmensure_cleanr   nparanger#   r   assert_series_equalranger   reshaper   listobjectassert_frame_equalr   r   r!   )r   oidfresultr   s        @r   test_conv_read_writerH      s{   		 8d	' IIb

+:lTV3W
 	q)Ha"8959Ib	5R11#h5RS
q)OQ"?@"))C.((11$v,f5595a2aS5VD

 	a7A!67 U1XE!H56
		$GD	1$	{;
bA.738 8 6S 6#8 8s,   A;GGA;GG
$BG
GGc                     dgdz  }t        d|i|      }t        |       5 }|j                  d|dg       |j                  d      }t	        j
                  ||       d d d        y # 1 sw Y   y xY w)N2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar   ar    rF   )data_columns)r   r   r7   selectr:   rC   )
setup_pathdatarF   storerG   s        r   test_long_stringsrQ   ;   sn    :?D	C;d	+B	J	' *5T2SE2d#
b&)	* * *s   =A''A0c                    | |z  }t        t        d            }|j                  d d j                  |ddd       |j                  dd  j                  |ddd       t	        j
                  t        |d      |       |j                  d d j                  |ddd       |j                  dd  j                  |ddd       t	        j
                  t        |d      |       y )N   r   rF   Tr5   r   r7   formatFr   r?   ilocr   r:   rC   r   tmp_pathrN   r   rF   s       r   test_apirZ   G   s     j D	59	BGGCRL$tGDGGBCL$tGD(4.3 GGCRL$uWEGGBCL$tGD(4.3r   c                    | |z  }t        t        d            }|j                  d d j                  |dd       |j                  dd  j                  |ddd       t	        j
                  t        |d      |       |j                  d d j                  |ddd       |j                  dd  j                  |dd       t	        j
                  t        |d      |       y )	NrS   r   rF   Tr6   r5   rT   FrV   rX   s       r   test_api_appendr\   W   s    j D	59	BGGCRL$t4GGBCL$tGD(4.3 GGCRL$uWEGGBCL$t4(4.3r   c                    | |z  }t        t        d            }|j                  |ddd       t        j                  t        |d      |       |j                  |ddd       t        j                  t        |d      |       |j                  |dd       t        j                  t        |d      |       |j                  |d       t        j                  t        |d      |       t        |      5 }t        t        d            }t        |d       |j                  d|j                  d d	 d
d       |j                  d|j                  d	d  d
d       t        j                  |j                  d      |       t        |d       |j                  d|j                  d d	 dd       |j                  d|j                  d	d  d
d       t        j                  |j                  d      |       t        |d       |j                  d|j                  d d	 dd       |j                  d|j                  d	d  d
d       t        j                  |j                  d      |       t        |d       |j                  d|j                  d d	 dd       |j                  d|j                  d	d  d
d        t        j                  |j                  d      |       d d d        y # 1 sw Y   y xY w)NrS   rF   FfixedrT   fr6   )r   r   Tr5   )r7   rU   )r   r?   r   r:   rC   r   r   r   r7   rW   rM   )rY   rN   r   rF   rP   s        r   
test_api_2r`   e   sm   j D	59	BIIdU7I;(4.3IIdU3I7(4.3IIdUI+(4.3IIdI(4.3	J	' 65uRy!eT"T2773B<WET27723<WE
ell40"5 	eT"T2773B<gFT27723<WE
ell40"5 	eT"T2773B<gFT27723<WE
ell40"5eT"T2773B<gFT27723<TB
ell40"5/6 6 6s   6G)K((K1c                    | |z  }t        dt        j                  d      j                  d      z  t	        t        d      t              t	        t        d      D cg c]  }d| 	 c}t                    }d	}t        j                  t        |
      5  |j                  |ddd       d d d        t        j                  t        |
      5  |j                  |ddd       d d d        d}t        j                  t        |
      5  |j                  |ddd       d d d        t        j                  t        |
      5  |j                  |ddd       d d d        d}d| d}t        j                  t        |
      5  t        |d       d d d        y c c}w # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   kxY w# 1 sw Y   y xY w)Nr'   r(   r)   r,   r   r*   r-   r.   zCan only append to TablesmatchrF   Tr_   rT   r^   z)invalid HDFStore format specified \[foo\]fooF zFile z does not exist)r   r<   r=   r@   r   rA   rB   r?   pytestraises
ValueErrorr   	TypeErrorFileNotFoundErrorr   )rY   rN   r   rE   rF   msgs         r   test_api_invalidrl      s   j D	biin$$W--d6l&1uRy1!r!X1@
B &C	z	- ;
		$Dc	:; 
z	- ?
		$Dg	>? 7C	y	, =
		$De	<= 
y	, >
		$Du	=> D$
'C	(	4 t / 2
; ;? ?
= => > sB   FF F,F8GG F),F58GGGc                    t        |       5 }t        t        j                  dt        j                        t        dd            |d<   |j                  d      }|d   }t        j                  ||       |j                  d      }|d   }t        j                  ||       t        j                  t        d	      5  |j                  d
       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r   r   r   r    rK   z/az'No object named b in the file'rb   b)r   r   r<   r=   r#   r   getr:   r>   rf   rg   KeyError)rN   rP   leftrights       r   test_getrs      s    	J	' 5IIb

+:lTV3W
c
 yy~c

tU+yyd
tU+]]8+LM 	IIcN	 	 	 s$   B2C->C!C-!C*	&C--C6c                     t        t        j                  j                  d      j	                  d            }t        |t        j                  |        y )Nr9   )2   d   )r   r<   randomdefault_rngstandard_normal_check_roundtripr:   rC   )rN   rF   s     r   test_put_integerr{      s8    	299((+;;IF	GBR..
;r   c                    t        |       5 }t        dg did      }|j                  d|       t        j                  |j
                  |d   j
                         t        dg did      }|j                  d|       t        j                  |j
                  |d   j
                         t        j                  d      }t        j                  t        |	      5  |j                  d|       d d d        t        t        j                  d
gdgdggd      dg      }|j                  d|       t        j                  |j
                  |d   j
                         |j
                  j                  d   dk(  sJ t        dD ci c]<  }|t        t        j                  j!                  d      j#                  d      |      > c}      }d|d<   d|d<   |d   j%                  d      |d<   |d   dkD  |d<   t'        d      |d<   t'        d      |d<   |j                  d|       |j)                  d      j
                  j+                         }|j,                  D cg c]  }t/        |       c}|_        t        dd
d
d
d
d
d
d
dd	d !      }|j1                         }|j1                         }t        j                  ||       d d d        y # 1 sw Y   xY wc c}w c c}w # 1 sw Y   y xY w)"NrK      r9      f8r   df_f8i8df_i8zinvalid combination of [values_axes] on appending data [name->values_block_0,cname->values_block_0,dtype->float64,kind->float,shape->(1, 3)] vs current table [name->values_block_0,cname->values_block_0,dtype->int64,kind->integer,shape->None]rb   r~   r9   r   f4r3   r/   df_f4r   float32)r   r#   int32int64int16int8r1   rd   string      ?float322bool20130101time120130102time2df_mixed_dtypes1)	r   r#   r   r   r   r   r   rB   zdatetime64[ns]count)name)r   r   r7   r:   r>   dtypesreescaperf   rg   rh   r<   arrayrW   r   rw   rx   integersastyper   rM   value_countsr!   str
sort_index)	rN   rP   df1df2rk   crG   rE   expecteds	            r   "test_table_values_dtypes_roundtripr      s   	J	' =15i(5Wc"
szz5>+@+@Ai(5Wc"
szz5>+@+@A ii
 ]]:S1 	'LL#&	'
 1#sQC=uMWc"
szz5>+@+@Azzq!Y...  S 6"))//2;;A>aHH
 HJj/00;J)nq(F ,G ,G'-0188EEG(.51A5"#
 
 ""$&&(
vx0{=1 =1$	' 	' 6Y=1 =1s@   CK'K0BK'AK
BK' K"2AK'K	K''K0z(ignore::pandas.errors.PerformanceWarningc           	         t        t        d      dt        d      D cg c]  }d| 	 c}      }t        |t        j                  |        t        t        j                  dt
        j                        t        dd      	      }t        |t        j                  |        t        |j                  t        |j                  t                    }t        |t        j                  |        t        |j                  t        t        j                  |j                  t              t                    }t        |t        j                  | d
       y c c}w )Nr   r#   r$   r%   r   r   r   r   r    F)r   check_index_type)r   r?   rz   r:   r>   r<   r=   r#   r   r!   r   rB   valuesasarray)rN   rE   ststs2ts3s         r   test_seriesr     s    uRy	E"I1NqBqc(1NOAQ..Z@	
		"BJJ'z,PR/S
B R//jA
58
9CS"00zB
E"**RXXV"DFS
TCR##*u 2Os   Ec                 
   t         j                  j                  d      j                  d      }t	        t         j                  j                  d      j                  d      |      }t        |t        j                  |        y )Nr9   r   r    r   )r<   rw   rx   ry   r   rz   r:   r>   )rN   r!   r   s      r   test_float_indexr     sY    II!!!$44R8Eryy$$Q'77;5IAQ..Z@r   c                    t        j                  d      }g d}t         j                  j                  d      j	                  d      j                  d      }t        |||      }t        j                  t        j                  j                        5  t        |t        j                  |        d d d        y # 1 sw Y   y xY w)Nr   ))g        r   )       @      @)g      @g      @r9   r*   )r   r   )r!   r/   r   )r<   r=   rw   rx   ry   r@   r   r:   assert_produces_warningpderrorsPerformanceWarningrz   rC   )rN   colidxrO   DFs        r   test_tuple_indexr   "  s    
))B-C
.C99  #33B7??HD	4sC	0B		#	#BII$@$@	A ER22DE E Es   B88Cc                 ^   t         j                  j                  d      j                  d      }d }t	        |ddg      }t        |||        t	        |t        j                  j                         dg      }t        |||        t	        |ddg      }t        |||        t	        |t        j                  j                         dg      }t        |||        t	        |ddg      }t        |||        t	        |t        j                  j                         dg      }t        |||        t	        |ddg      }t        |||        t	        |t        j                  j                         dg      }t        |||        t	        |ddg      }t        |||        t	        |d	d
g      }t        |||        t	        |d	dg      }t        |||        t        ddgd      }t	        ||      }t        |||        |j                  j                  d      |_
        t        |||        y )Nr9   c                 2    t        j                  | |d      S )NT)r   )r:   r>   )lhsrhss     r   <lambda>z"test_index_types.<locals>.<lambda>1  s    B223dS r   r   yr   rK   gGz?rn   r~   g{Gz?r1   z
2012-01-01z
2012-01-02M8[ns]r   r    r   )r<   rw   rx   ry   r   rz   datetimetodaydater   r!   as_unit)rN   r   funcserdtis        r   test_index_typesr   -  s   YY""1%55a8FSD
!S
"CS$Z0
(++113Q7
8CS$Z0
#q
"CS$Z0
(----/5
6CS$Z0
!S
"CS$Z0
(++113Q7
8CS$Z0
#q
"CS$Z0
(----/5
6CS$Z0
$
%CS$Z0
!T
#CS$Z0
!Q
 CS$Z0
|4H
EC
s
#CS$Z0		!!#&CIS$Z0r   c                 f   t        dd      }t        t        j                  j	                  d      j                  t        |            |      }	 t        |t        j                  |        y # t        $ r: t               r.|j                  t        j                  j                  d              w xY w)Nz1/1/1940z1/1/1960r9   r    r   z'known failure on some windows platforms)r
   r   r<   rw   rx   ry   lenrz   r:   r>   OverflowErrorr   applymarkerrf   markxfail)rN   requestdrr   s       r   test_timeseries_preepochr   \  s    	Z	,B			%%a(88RA	LBR33*E  !!"KL 	s   A- -AB0compressionFT)marksc                    t        dt        j                  d      j                  d      z  t	        t        d      t              t	        t        d      D cg c]  }d| 	 c}t                    }t        j                  |j                  d	<   t        j                  |j                  d
<   t        |t        j                  ||        t        |t        j                  ||        t        t        j                  j                  d      j!                  d      t	        t        d      t              t#        ddd            }t        |t        j                  ||        t%        |      5 }t        j                  j                  d      j!                  t'        |            |d<   ||d<   |d   }|j(                  j+                         sJ 	 d d d        t        |d d t        j                  |       y c c}w # 1 sw Y   .xY w)Nr'   r(   r)   r,   r   r*   r-   r.   )r   r   )r1   r   r   r   r9   )r   r+   z
2000-01-01r   r4   )r   freqrd   rF   r   r   )r   r<   r=   r@   r   rA   rB   r?   nanrW   _check_roundtrip_tabler:   rC   rz   rw   rx   ry   r   r   r   _mgris_consolidated)r   rN   rE   rF   tdfrP   reconss          r   
test_framer   i  s    
biin$$W--d6l&1uRy1!r!X1@
B FFBGGDMFFBGGDM
B!!
 
B!!
 
		a 009d6l&1r<C
 R"" 
J	' -5II))!,<<SWE5	dt{{**,,,- RVR22D? 2.- -s   G9/A!G>>Hc                    t        t              }t        dt              }t               }t        g d      }t        g d      }t        |t        j
                  |        t        |t        j
                  |        t        |t        j                  |        t        |t        j                  |        t        |t        j                  |        y )	Nr   myseries)r   r   rK   rn   r   r    )der_   r   r   )r   rB   r   rz   r:   r>   rC   )rN   s0s1df0r   r   s         r   test_empty_series_framer     s    	f	B	Zv	.B
+C
/
*C
O
,CR//jAR//jAS"//jAS"//jAS"//jAr   r   zm8[ns]r   c                 T    t        |       }t        |t        j                  |       y )Nr   r   )r   rz   r:   r>   )r   rN   r   s      r   test_empty_seriesr     s    UAQ..Z@r   c                    t        dd      D cg c]  }|j                          }}t        t        j                  j                  d      j                  t        |      df      |      }t        |t        j                  |        y c c}w )Nz1/1/2000z	1/30/2000r9   r+   r    r   )r
   r   r   r<   rw   rx   ry   r   rz   r:   rC   )rN   xrngr0   s       r   test_can_serialize_datesr     sm    ([A
B1668
BC
B
		a 00#c(A?sE UB11
C Cs   B	c                 J   |}t        |t        j                  |        t        |j                  t        j                  |        t        |d   t        j                  |        t        |       5 }||d<   |d   }t        j                  ||       d d d        y # 1 sw Y   y xY w)Nr   r3   r0   )rz   r:   rC   Tr>   r   )rN    multiindex_dataframe_random_datar0   rP   r   s        r   test_store_hierarchicalr     s    ,EUB11
CUWWb33*EU3Z!7!7jI 
J	' -5gw
fe,- - -s   /!BB"c                    d } |       } |       }t        |t        j                  |       t        |t        j                  |       t        |      5 }||d<   t        j                  |d   |       ||d<   t        j                  |d   |       d d d        t        |d   t        j                  ||        t        |d   t        j                  ||        t        |d   t        j                  ||        y # 1 sw Y   jxY w)Nc                  h   t        dt        j                  d      j                  d      z  t	        t        d      t              t	        t        d      D  cg c]  } d|  	 c} t                    }d	|d
<   d|d<   |d   dkD  |d<   |d   dkD  |d<   d|d<   d|d<   |j                         S c c} w )Nr'   r(   r)   r,   r   r*   r-   r.   rd   obj1barobj2r3   r   bool1r4   bool2r~   int1r9   int2)	r   r<   r=   r@   r   rA   rB   r?   _consolidate)rE   rF   s     r   	_make_onez#test_store_mixed.<locals>._make_one  s    "))C.((11$v,f5595a2aS5VD

 6
6
gk7gk76
6
   6s   B/r   r   r   r   r   r   )rz   r:   rC   r   r>   )r   rN   r   r   r   rP   s         r   test_store_mixedr     s    ! +C
+CS"//jAS"//jA	J	' 15e
eElC0e
eElC0	1 F
	 G
	 F
	'1 1s   =C;;Dc                     i }|rd|d<   t        |dfi |5 }| |d<   |d   } ||| fi | d d d        y # 1 sw Y   y xY w)Nblosccomplibwr   )r   )r   
comparatorr   r   r   optionsrP   	retrieveds           r   rz   rz     s[    G$		D#	1	1 -Ue%L	9c,V,- - -s   5>c                     i }|rd|d<   t        |dfi |5 }|j                  d| d       |d   } |||        d d d        y # 1 sw Y   y xY w)Nr   r  r  r   r5   )rU   )r   put)r   r  r   r   r  rP   r  s          r   r   r     s_    G$		D#	1	1 #U		%W	-%L	9c"	# # #s   #AAc                     ddg}t        t        j                  j                  d      j	                  t        |            |      }t        |t        j                  |        y )Nu   σu   σσr9   r   )	r   r<   rw   rx   ry   r   rz   r:   r>   )rN   unicode_valuesr   s      r   test_unicode_indexr
    sO    /N
		a 00^1DE	A Q..Z@r   c                    d}t        d|gi      }t        |       5 }|j                  d|dd       |j                  d      }t	        j
                  ||       d d d        t        d|gddgd	      }t        |       5 }|j                  d|dd       |j                  d      }t	        j
                  ||       d d d        y # 1 sw Y   lxY w# 1 sw Y   y xY w)
Nu   Δr3   rF   r5   zutf-8)rU   encodingrK   rn   r2   )r   r   r  ro   r:   rC   )rN   charrF   rP   rG   s        r   test_unicode_longer_encodedr    s    D	C$=	!B	J	' *5		$7W	=4
fb)*
 
#tC:6	7B	J	' *5		$7W	=4
fb)* ** ** *s   =C>=CCCc                     t        g dg dg dd      }t        t        j                  dt        j                        t        dd            }|j                  d d	 |d
<   t        |t        j                  |        y )Nr}   )r   r   r   r   r   r   r   r   r    r   r   r   )
r   r   r<   r=   r#   r   r!   rz   r:   rC   )rN   rF   r   s      r   test_store_datetime_mixedr  !  s`    	O	PB	
		"BJJ'z,PR/S
B hhrlBsGR..Z@r   c                     t        ddgddgd      }| |z  }|j                  |dd       t        |d      }t        j                  ||       |j                  |      sJ |j                  |      sJ y )	Nr~   r9   r   r   )r4   r3   rF   r5   r   rU   )r   r   r   r:   rC   equals)rY   rN   rF   r   others        r   test_round_trip_equalsr  *  su    	!QsCj1	2Bj DIIdWI-T4 E"e$99U<<r   c           
         t        j                  d       | |z  }t        j                  dd      5  t	        dt        d      t        t        d                  j                  dd	g      }|j                         }|j                  |d
d       t        |d
      }t        j                  ||       d d d        y # 1 sw Y   y xY w)Npyarrowzfuture.infer_stringTr~   r,   r   r.   r3   r4   rF   r5   r  )rf   importorskipr   option_contextr   rA   r?   	set_indexcopyr   r   r:   rC   )rY   rN   r   rF   r   rG   s         r   test_infer_string_columnsr  6  s    
	"j D			0$	7 0q$v,d59oFPP#J
 779
		$D	1$%
fh/0 0 0s   BB;;C)F)?r   r   numpyr<   rf   pandas._libs.tslibsr   pandas.compatr   pandasr   r   r   r   r   r	   r:   r
   r   r   pandas.tests.io.pytables.commonr   r   pandas.utilr   tdr   
single_cpu
pytestmarkrH   rQ   rZ   r\   r`   rl   rs   r{   r   filterwarningsr   r   r   r   r   parametrizeparamskip_if_windowsr   r   r   r#   rB   r   r   r   r   rz   r   r
  r  r  r  r   r   r   <module>r+     s    	   ) - 	 	 	 /[[##
8:	*4 4'6TB"<>1B FG H$AE FG+1 H+1\
 E<6<<B4F4FGH#E#ELB 288RZZ8"TUA VA
D- E<6<<B4F4FGH--`-	#A* A	0r   