
    Owg               	          d dl Z d dlmZ d dlZd dl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 d dlmZmZ ej,                  j.                  Zd Zd Zd Zd	 Zd
 Zd Zej,                  j?                  d edddd       e e d            g      d        Z!d Z"d Z#d Z$ej,                  j?                  dddg ddg      d        Z%y)    N)BytesIO)CategoricalIndex	DataFrameHDFStoreIndex
MultiIndex_testing
date_rangeread_hdf)ensure_clean_store)Term_maybe_adjust_namec                 r   t        dt        j                  d      j                  d      z  t	        t        d      t              t	        t        d      D cg c]  }d| 	 c}t                    }t        |       5 }|j                  d	|       d
}t        j                  t        |      5  |j                  d	dg       d d d        d}t        j                  t        |      5  |j                  d	dg       d d d        d d d        y c c}w # 1 sw Y   QxY w# 1 sw Y   #xY w# 1 sw Y   y xY w)N皙?x         ABCDdtyper   i-columnsindexdfzqcannot pass a column specification when reading a Fixed format store. this store must be selected in its entiretymatchA)r   zucannot pass a where specification when reading from a Fixed format store. this store must be selected in its entiretyz	columns=Awhere)r   nparangereshaper   listobjectranger   putpytestraises	TypeErrorselect)
setup_pathir   storemsgs        [/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/io/pytables/test_errors.pytest_pass_spec_to_storerr2      s   	biin$$W--d6l&1uRy1!r!X1@
B 
J	' 65		$A 	 ]]9C0 	.LLuL-	.H 	 ]]9C0 	6LL{_L5	66 6 2	. 	.	6 	66 6sB   D 0D-0D%D-*D!?D-D	D-!D*	&D--D6c                 v   t        dg di      }t        dg dit        dd            }t        |       5 }|j                  d|d	
       t	        j
                  d      }t        j                  t        |      5  |j                  d|d	d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Na)         )r         z1/1/2000r7   periods)r   frametableformatz3incompatible kind in col [integer - datetime64[ns]]r   T)r?   append)	r   r
   r   r(   reescaper)   r*   r+   )r-   df1df2r/   r0   s        r1   $test_table_index_incompatible_dtypesrE   3   s    
S)$
%C
S)$Jz1,M
NC	J	' A5		'3w	/iiMN]]9C0 	AIIgs74I@	AA A	A 	AA As$   AB/<B#B/#B,	(B//B8c                    t        |       5 }dt        j                  ddd      fg}|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| d      }t        j                  t        |      5  |j!                  d| |       d d d         	 d d d        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<   t        j                  ddd      |d<   |j#                         }t        |       5 }t        j                  d      }t        j                  t        |      5  |j!                  d|       d d d        d d d        y c c}w # 1 sw Y   xY w# 1 sw Y   $xY wc c}w # 1 sw Y   6xY w# 1 sw Y   y xY w)Ndatei  r5   r6   r   r   r   r   r   r   r   r   [z&] is not implemented as a table columnr   df1_fooobj1barobj2	datetime1zjCannot serialize the column [datetime1]
because its data contents are not [string] but [date] object dtypedf_unimplemented)r   datetimerG   r   r"   r#   r$   r   r%   r&   r'   rA   rB   r)   r*   r+   r@   _consolidate)r-   r/   dtypesnfr.   r   r0   s           r1   'test_unimplemented_dtypes_table_columnsrU   >   s    	J	' -58==q!456  		-DAqbiin,,W55d6l&9uRy9!r!X9HB
 BqE))as"HIJCy4 -tA3Z,- -		-	-  
biin$$W--d6l&1uRy1!r!X1@
B
 BvJBvJmmD!Q/B{O		B	J	' 15iiF
 ]]9C0 	1LL+R0	11 1% :- -- -& 2	1 	11 1sa   A9HHAHH2
HH,81H=)H1<H=HHHH)1H:	6H==Ic           
         t        |      5 }t        t        j                  j	                  d      j                  d      t        t        d      t              t        ddd      	      }d
|d<   d|j                  |j                  dd df<   |j                  d|d       t        j                  d      }t        j                   t"        |      5  t%                d d d        t        j                  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        | |z  }t        t        j                  j	                  d      j                  d      t        d      t        dd      	      }|j-                  |ddd       t/        |dd       t/        |dd       | |z  }t        t        j                  j	                  d      j                  d      t        d      t        dd      	      }|j-                  |dd        d!}t        j                   t&        |      5  t/        |dd       d d d        y # 1 sw Y   xY w# 1 sw Y   wxY w# 1 sw Y   LxY w# 1 sw Y   QxY w# 1 sw Y   y xY w)"Nr6   )
   r   r   r   z
2000-01-01rW   B)r;   freqr   rJ   stringrL   r   r   r   r=   r>   z:__init__() missing 1 required positional argument: 'where'r   zWcannot process expression [df.index[3]], [2000-01-06 00:00:00] is not a valid conditionzdf.index[3]zinvalid syntaxzindex>20130101r:   dfqT)keyr?   data_columnsz0index>Timestamp('20130104') & columns=['A', 'B']r    z
A>0 or C>0)r]   r?   a  The passed where expression: A>0 or C>0\n\s*contains an invalid variable reference\n\s*all of the variable references must be a reference to\n\s*an axis \(e.g. 'index' or 'columns'\), or a data_column\n\s*The currently defined references are: index,columns\n)r   r   r"   randomdefault_rngstandard_normalr   r%   r&   r
   locr   r(   rA   rB   r)   r*   r+   r   
ValueErrorr,   SyntaxErrorto_hdfr   )tmp_pathr-   r/   r   r0   pathr\   s          r1   test_invalid_termsrh   c   se   	J	' )5II!!!$44W=$v,f5\2C@

 8*/rxx!}h&'		$7	+ iiTU]]9C0 	F	 ii=
 ]]:S1 	.LL}-	. ]];c2 	)LLx(	)3): j D

		a 009VR0C
 JJtwTJB T5 RST5- j D

		a 009VR0C
 JJtwJ/	A  
z	- 2uL12 2Y	 		. 	.	) 	)3) )r2 2s`   CJ7J8J7J(%J7J* J78KJ	J7J'	"J7*J4	/J77KKc                 v   t        t        j                  j                  d      j	                  d            }t        dt        j                  j                  d      j	                  d      i      }t        dt        j                  j                  d      j	                  d      i      }t        dt        j                  j                  d      j	                  d      i      }t        ddt
        ft        j                  j                  d      j	                  d      i      }t        |       5 }d}|j                  ||       ||||fD ]M  }t        j                  d	      }	t        j                  t        |	
      5  |j                  ||       d d d        O 	 d d d        y # 1 sw Y   cxY w# 1 sw Y   y xY w)Nr6   )rW   r5   r4   rW   r5   r6   )1r6   rk   df_diff_valerrorz?cannot match existing table structure for [0] on appending datar   )r   r"   r_   r`   ra   r&   r   r@   rA   rB   r)   r*   rc   )
r-   r   rD   df3df4df5r/   namedr0   s
             r1   7test_append_with_diff_col_name_types_raises_value_errorrr      sj   	299((+;;GD	EB
S"))//2BB2FG
HC
VRYY2215EEbIJ
KC
Xryy44Q7GGKL
MC
c1f%ryy'<'<Q'?'O'OPR'ST
UC	J	' 	&5!T2sC% 	&A))QC z5 &T1%& &		&		& 	&& &	& 	&s%   .AF/<F#
F/#F,(F//F8c                 |   t        t        j                  j                  d      j                  d      t	        d      t	        d            }t        j                  |       5 }d}t        j                  t        |      5  |j                  |dd	
       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr6   r   r8   abcdABCDEr   r   z)complib only supports \[.*\] compression.r   r   foolib)r]   complib)r   r"   r_   r`   r%   tmensure_cleanr)   r*   rc   re   )r-   r   rg   r0   s       r1   test_invalid_complibr|      s    	
		a ''/6lW
B
 
	$ 8:]]:S1 	8IIdhI7	88 8	8 	88 8s$   "B2 B&B2&B/	+B22B;idx2019Dr7   UTC)rY   r;   tzabcc                     t        j                  | | g      }t        d|dg      }||z  }t        j                  t
        d      5  |j                  |d       d d d        y # 1 sw Y   y xY w)Nr   r4   rw   zSaving a MultiIndexr   r   r]   )r   from_arraysr   r)   r*   NotImplementedErrorre   )r}   rf   r-   mir   rg   s         r1   &test_to_hdf_multiindex_extension_dtyper      sg     
		c
	+B	1B	.Bj D	*2G	H "
		$D	!" " "s   A$$A-c                      | ddd      }d}t        j                  t        |      5  t        |       d d d        y # 1 sw Y   y xY w)Niodataz"legacy_hdf/incompatible_dataset.h5z_Dataset\(s\) incompatible with Pandas data types, not table, or no datasets found in HDF5 file.r   )r)   r*   rc   r   )datapath	data_pathmessages      r1   test_unsuppored_hdf_file_errorr      sH    v'KLI	8 
 
z	1   s	   =Ac                    t        t        j                  j                  d      j                  d      t	        d      t	        d            }|| z  }d}t        j                  t        |      5  t        |d       d d d        |j                  |d	
       t        |d      }|j                          d}t        j                  t        |      5  t        |d	       d d d        y # 1 sw Y   lxY w# 1 sw Y   y xY w)Nr6   rt   ru   rv   rw   zFile [\S]* does not existr   r]   r   r   r)modez&The HDFStore must be open for reading.)r   r"   r_   r`   r%   r)   r*   OSErrorr   re   r   close)r-   rf   r   rg   r0   r/   s         r1   test_read_hdf_errorsr      s    	
		a ''/6lW
B j D
&C	wc	* u IIdIT$E	KKM
2C	wc	*    s   /C'C3'C03C<c                      d} t        j                  t        |       5  t        t	        d      d       d d d        y # 1 sw Y   y xY w)Nz5Support for generic buffers has not been implemented.r       r   )r)   r*   r   r   r   )r0   s    r1   #test_read_hdf_generic_buffer_errorsr      s9    
AC	*#	6 %t$% % %s	   =Abad_versionrj   )r5   12123c                     d}t        j                  t        |      5  t        d|        d d d        y # 1 sw Y   y xY w)Nz5Version is incorrect, expected sequence of 3 integersr   values_block_0)version)r)   r*   rc   r   )r   r0   s     r1   )test_maybe_adjust_name_bad_version_raisesr      s9    
AC	z	- B+[AB B Bs   5>)&rP   r   r   rA   numpyr"   r)   pandasr   r   r   r   r   r	   rz   r
   r   pandas.tests.io.pytables.commonr   pandas.io.pytablesr   r   mark
single_cpu
pytestmarkr2   rE   rU   rh   rr   r|   parametrizer%   r   r   r   r   r    r   r1   <module>r      s      	  	 	 	 ?
 [[##
6.A"1J;2|&&	8 	6Q59e%""	*% r4(GHB IBr   