
    o[we-                     \   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d dl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j        j        Zd Zd Zd Zd	 Zd
 Zd Zej         d             Z!d Z"ej        #                    ddej$        gdej%        gdej&        gdej'        gdej$        gdej%        gdej&        gdej'        gdej(        gdej(        gg
          ej        )                    d          d                         Z*d Z+d Z,ej        #                    dddg          d             Z-dS )    N)	Timestamp)	DataFrameHDFStoreIndex
MultiIndexSeries_testingconcat)_maybe_removeensure_clean_store)_test_decoratorsc                 d   t          dddgi          }t          | |z            5 }|                    d|d           |                    d|d           |                    d          j        dk    sJ |                    d          j        dk    sJ 	 d d d            d S # 1 swxY w Y   d S )	NA      afixedformatbtable)r   r   put
get_storerformat_type)tmp_path
setup_pathdfstores       Alib/python3.11/site-packages/pandas/tests/io/pytables/test_put.pytest_format_typer       s   	C!Q=	!	!B	(Z'	(	( <E		#r'	***		#r'	***$$0G;;;;$$0G;;;;;< < < < < < < < < < < < < < < < < <s   A1B%%B),B)c                     d}t          j        t          |          5  t          | |z  d           d d d            d S # 1 swxY w Y   d S )Nz-format is not a defined argument for HDFStorematchr   r   )pytestraises
ValueErrorr   )r   r   msgs      r    test_format_kwarg_in_constructorr(   &   s     :C	z	-	-	- 8 8J&w77778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   A  AAc                    t          |          5 }t          j                    }t          j        dd          5  t          |d           |                    d|           |                    d          j        rJ d}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        dd          5  t          |d           |                    d|           |                    d          j        sJ t          |d           |                    d|           |                    d          j        sJ 	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   | |z  }t          j                    }t          j        dd          5  |                    |d           t          |          5 }|                    d          j        rJ 	 d d d            n# 1 swxY w Y   t          j
        t          |          5  |                    |d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        dd          5  |                    |d
           t          |          5 }|                    d
          j        sJ 	 d d d            n# 1 swxY w Y   |                    |dd	           t          |          5 }|                    d          j        sJ 	 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 )Nzio.hdf.default_formatr   r   Can only append to Tablesr"   df2r   Tappenddf3df4)r   tmmakeDataFramepdoption_contextr   r   r   is_tabler$   r%   r&   r-   to_hdfr   )r   r   r   r   r'   paths         r   test_api_default_formatr7   /   s   	J	'	' 356@@ 	( 	(%&&&IIdB''--6666-Cz555 ( (UB'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 6@@ 	3 	3%&&&IIdB##D))2222%'''LL#####D))22222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	33 3 3 3 3 3 3 3 3 3 3 3 3 3 3* j D				B		2G	<	< 0 0
		$d^^ 	7u''--66666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7]:S111 	0 	0IIdE$I///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
	2G	<	< 4 4
		$d^^ 	4u##E**33333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4
		$d	+++d^^ 	4u##E**33333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4s2  )FA CB<0C<C  CC CFC	FC	F3BF9FF			FF		FF #F &J:H$J$H(	(J+H(	,J
I/#J/I3	3J6I3	7JJ
J
&&M*K6*M*6K:	:M*=K:	>*M*(MM*M	M*M	M**M.1M.c                    t          |           5 }t          j                    }t          j                    }||d<   |d d         |d<   |d d         |d<   |d d         |d<   |d d         |d<   |                    d|d d         d	           d
}t          j        t          |          5  |                    d|dd          d           d d d            n# 1 swxY w Y   t          |d           t          j        t          |          5  |                    d|dd          d           d d d            n# 1 swxY w Y   t          j        t          |          5  |                    d|dd          d           d d d            n# 1 swxY w Y   |                    d|d d         dd           t          j	        |d d         |d                    d d d            d S # 1 swxY w Y   d S )Nr   
   r   zfoo/bar/bahfooz/foocr   r   r*   r"   Tr,   fF)r   r-   )
r   r0   makeTimeSeriesmakeTimeDataFramer   r$   r%   r&   r   assert_frame_equal)r   r   tsr   r'   s        r   test_putrA   Y   s   	J	'	' 35  !##c
Wc
!#2#wm#2#we3B3f		#r#2#ww	/// *]:S111 	1 	1IIc2bcc74I000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1
 	eS!!!]:S111 	1 	1IIc2bcc74I000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 ]:S111 	1 	1IIc2bcc74I000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 			#r#2#wwu	===
b"guSz22273 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3s   BG,-!CG,C	G,!C	".G,!D=1G,=E	G,E	G,#!FG,F	G,F	AG,,G03G0c                    t          |           5 }t          d t          d          D                       }t          t	          j        d          |          }t          ||d          }||d<   t          j        |d         |           ||d<   t          j	        |d         |           t          dgd t          d          D             z             }t          t	          j        d	          |          }t          ||d          }||d<   t          j        |d         |           ||d<   t          j	        |d         |           d d d            d S # 1 swxY w Y   d S )
Nc                     g | ]}d | S zI am a very long string index:  .0is     r   
<listcomp>z)test_put_string_index.<locals>.<listcomp>z   s!    PPP<<<PPP       index)r   Br   r   $abcdefghijklmnopqrstuvwxyz1234567890c                     g | ]}d | S rD   rE   rF   s     r   rI   z)test_put_string_index.<locals>.<listcomp>   s!    HHH444HHHrJ      )
r   r   ranger   nparanger   r0   assert_series_equalr?   )r   r   rM   sr   s        r   test_put_string_indexrW   x   s   	J	'	' .5PPeBiiPPPQQ29R==...QQ''((c

uSz1---c

eCj"--- 34HHeBiiHHHI
 
 29R==...QQ''((c

uSz1---c

eCj"----. . . . . . . . . . . . . . . . . .s   D;EEEc                    t          |           5 }t          j                    }|                    d|dd           t          j        |d         |           d}t          j        t          |          5  |                    d|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 )	Nr;   r   zlibr   complib0Compression not supported on Fixed format storesr"   r   r   )r   r0   r>   r   r?   r$   r%   r&   )r   r   r   r'   s       r   test_put_compressionr]      s<   	J	'	' 	?5!##		#r'6	:::
eCj"--- A]:S111 	? 	?IIc2gvI>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s6   A%B35BB3B	B3"B	#B33B7:B7c                    t          j                    }t          |           5 }d}t          j        t
          |          5  |                    d|dd           d d d            n# 1 swxY w Y   |                    d|dd           t          j        |d         |           d d d            d S # 1 swxY w Y   d S )	Nr\   r"   r   r   bloscrZ   r;   r   )r0   r>   r   r$   r%   r&   r   r?   )r   r   r   r'   s       r   test_put_compression_bloscr`      sL   				B	J	'	' .5@]:S111 	@ 	@IIc2gwI???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 			#r'7	;;;
eCj"---. . . . . . . . . . . . . . . . . .s5   B3A'B3'A+	+B3.A+	/7B33B7:B7c                    t          j                    }d|d<   d|d<   |d         dk    |d<   |d         dk    |d	<   d
|d<   d|d<   d|d<   t          d                              d          |d<   t          d                              d          |d<   t          d                              d          |d<   t          d                              d          |d<   t          j        |j        |j        dd         dgf<   |                                }t          |           5 }t          |d           t          j        t          j        j                  5  |                    d|           d d d            n# 1 swxY w Y   |                    d          }t          j        ||           d d d            d S # 1 swxY w Y   d S )Nr:   obj1barobj2r   r   bool1rN   bool2Tbool3r   int1r   int220010102ns
timestamp120010103
timestamp2	datetime1	datetime2      r   )r0   r>   r   as_unitrS   nanlocrM   _consolidater   r   assert_produces_warningr2   errorsPerformanceWarningr   getr?   )r   r   r   expecteds       r   test_put_mixed_typer|      s-   				BBvJBvJS'A+BwKS'A+BwKBwKBvJBvJ ,,44T::B| ,,44T::B|
++33D99B{O
++33D99B{O&(fBF28AaC=6("#			B	J	'	' ,5eT"""'	(DEE 	  	 IIdB	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  99T??
h+++, , , , , , , , , , , , , , , , , ,s6   &4F?E=1F?=F	F?F	-F??GGzformat, indexr   r   z3ignore:PeriodDtype\[B\] is deprecated:FutureWarningc                    t          |           5 }t          t          j                            d                              d          t          d                    } |t          |                    |_        t          |d           |
                    d||           t          j        ||d                    d d d            d S # 1 swxY w Y   d S )Nr   )r9   r   ABcolumnsr   r   )r   r   rS   randomdefault_rngstandard_normallistlenrM   r   r   r0   r?   )r   r   rM   r   r   s        r   test_store_index_typesr      s   ( 
J	'	' /5I!!!$$44W==tDzz
 
 
 5R>>eT"""		$6	***
b%+.../ / / / / / / / / / / / / / / / / /s   B/CCCc                 X   t          j        g dddg          }t          t          j        d                              dd          |          }|                    |j                                                  }t          |           5 }|
                    d	|           t          j        |d	         |d
d
           |
                    d|d           t          j        |d         |d
d
           t          j        d          }t          j        t"          |          5  |
                    d|ddg           d d d            n# 1 swxY w Y   t          j        d          }t          j        t"          |          5  |
                    d|dd
           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          |           5 }|                    d|           |                    d|           t          j        |d         t'          ||f                     d d d            n# 1 swxY w Y   t          t          j        d                              dd          t)          t+          d          d                    }|                    |j                                                  }t          |           5 }|
                    d|d           t          j        |d         |d
d
           d d d            d S # 1 swxY w Y   d S )N))r   r   )r   r   )rN   r   )rN   r   firstsecondnames   rq      r   r   T)check_index_typecheck_column_typedf1r   r   z<cannot use a multi-index on axis [1] with data_columns ['A']r"   r+   r   )r   data_columnsz;cannot use a multi-index on axis [1] with data_columns Truer.   ABCDr:   )name)r   from_tuplesr   rS   rT   reshapeset_axisrM   to_numpyr   r   r0   r?   reescaper$   r%   r&   r-   r
   r   r   )r   rM   r   r{   r   r'   s         r   test_column_multiindexr      sj    "888(@S  E 
29R==((A..	>	>	>B{{28,,..//H	J	'	' D5		$
$KDD	
 	
 	
 	
 			%G	,,,
%L(TT	
 	
 	
 	
 iVWW]:S111 	E 	EIIeRseIDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	EiUVV]:S111 	D 	DIIeRdICCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	DD D D D D D D D D D D D D D D& 
J	'	' >5UBUB
eElFB8,<,<===	> > > > > > > > > > > > > > > 
29R==((A..d6llQV8W8W8W	X	X	XB{{28,,..//H	J	'	' 
5		%G	,,,
%L(TT	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   BG'EGE	GE	2GF."G.F2	2G5F2	6GG	G	AII	I7LL#&L#c           	         t          |           5 }dd}t          |d           t          t          j        d          ddg |                      }|                    d|           t          j        |                    d          |           t          |d           t          t          j        d          ddg |g d                    }|                    d|           t          j        |                    d          |           t          |d           t          t          j        d	           |g d          
          }|                    d|           t          t          j        d	           |g d          
          }t          j
        |                    d          |           t          |d           t          t          j        d          ddg |g d                    }d}t          j        t          |          5  |                    d|           d d d            n# 1 swxY w Y   t          |d           t          t          j        d          ddg |g d                    }t          j        t          |          5  |                    d|           d d d            n# 1 swxY w Y   t          |d           t          t          j        d          ddg |g d                    }|                    d|           t          j        |                    d          |           d d d            d S # 1 swxY w Y   d S )Nc                 ^    t          j        d t          dd          D             |           S )Nc           	          g | ]?}t          d           D ]-}t          d          D ]}t          j        dd|          ||f.@S )r   rq   i  r   )rR   datetime)rG   drV   ts       r   rI   z=test_store_multiindex.<locals>.make_index.<locals>.<listcomp>  sx       "1XX  "1XX	   &tR33Q:    rJ   r   rq   r   )r   r   rR   r   s    r   
make_indexz)test_store_multiindex.<locals>.make_index  sE    ) "1a[[      rJ   r   )r   r   r   r   )r   rM   )dateNNrV   r   rL   )r   level_1level_2)r   r   r   zBduplicate names/columns in the multi-index when storing as a tabler"   )r   r   r   )r   rV   r   )N)r   r   r   rS   zerosr-   r0   r?   selectr   rU   r$   r%   r&   )r   r   r   r   rV   xpr'   s          r   test_store_multiindexr     sK    
J	'	' A65		 		 		 		 	eT"""rx((3*JJLLQQQT2
ell400"555 	eT"""HW#J*11122
 
 

 	T2
ell400"555 	eS!!!28B<<zz2F2F2F'G'GHHHS!BHRLL

3Q3Q3Q(R(RSSS
u||C00"555 	eT"""HW#J*///00
 
 

 S]:S111 	# 	#LLr"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	eT"""HW#J*55566
 
 

 ]:S111 	# 	#LLr"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	eT"""HW#J*///00
 
 

 	T2
ell400"555CA6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6s\   HMH;/M;H?	?MH?	AM"K9MK			MK		BMM #M r   c                 B   t          t          j                            d                              d          t          j        ddd                    }| |z  }|                    |dd	|
           t          j        |d          }t          j
        ||           d S )Nr   )   r   20220101Mr   )freqperiodsrL   r   w)moder   )r   rS   r   r   r   r2   period_ranger5   read_hdfr0   r?   )r   r   r   r   r6   r{   s         r   test_store_periodindexr   [  s     

	a  0088ojsA>>>
 
 
B
 j DIIdDs6I222{4&&H"h'''''rJ   ).r   r   numpyrS   r$   pandas._libs.tslibsr   pandasr2   r   r   r   r   r   r	   r0   r
   pandas.tests.io.pytables.commonr   r   pandas.utilr   tdmark
single_cpu
pytestmarkr    r(   r7   rA   rW   r]   skip_if_windowsr`   r|   parametrizemakeFloatIndexmakeStringIndexmakeIntIndexmakeDateIndexmakePeriodIndexfilterwarningsr   r   r   r   rE   rJ   r   <module>r      s    				      ) ) ) ) ) )                             / . . . . .[#
< < <8 8 8'4 '4 '4T3 3 3>. . .4
? 
? 
? 
. 
. 
., , ,4 	"#$	"$%	"/"	""#	"#$	"$%	"/"	""#	"$%	"$%  RSS/ / TS  /+
 +
 +
\D6 D6 D6N GW#566( ( 76( ( (rJ   